Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 323985

Summary: Cannot set the Jetty Port outside of Jetty.xml ( at all )
Product: [RT] Jetty Reporter: Quintin <qpaulson>
Component: serverAssignee: Greg Wilkins <gregw>
Status: RESOLVED FIXED QA Contact:
Severity: major    
Priority: P3 CC: as.maps, gregw, jetty-inbox, joakim.erdfelt, mgorovoy, qpaulson, rocketraman, theo.c
Version: unspecified   
Target Milestone: 7.1.x   
Hardware: All   
OS: All   
Whiteboard:

Description Quintin CLA 2010-08-30 11:44:20 EDT
Build Identifier: 7.1.6.v20100715

Jetty 7.1.6 cannot no longer set the jetty.port from the command line using Java arguments
-Djetty.port=9000 

Reproducible: Always

Steps to Reproduce:
1. start jetty with java -Djetty.port=9000 -jar start.jar
2. wait until the server initializes and note the port is still the default of 8080.

I am using the default options and default configuration.
Comment 1 Quintin CLA 2010-08-30 11:48:27 EDT
I am seeing this in OSX but I presume this is happening on all platforms.
Comment 2 Quintin CLA 2010-09-07 22:49:35 EDT
This is also happening with 7.1.5.

I just downloaded 7.1.5 to see if it has the same issue.
Steps to re-produce:

1. Unarchive 7.1.5
2. edit start.ini
2.1 uncomment --exec
2.2 add -Djetty.port=9000 in start.ini
3. run jetty with java -jar start.jar from the jetty home directory.


I also tried just running jetty with: java -Djetty.port=9000 -jar start.jar



Both ways result in jetty starting on port 8080 ( the default port )
Comment 3 Michael Gorovoy CLA 2010-09-07 23:26:43 EDT
Jetty 7 has different startup options then compared to Jetty 6. You can learn about available options by executing the command 'java -jar start.jar --help'

In Jetty 7, in order to start the server on a different port, you should use command 'java -jar start.jar jetty.port=9000'. However, I've confirmed that it does not work using release 7.1.6.v20100715. It is definitely not platform dependent as I've tested it on Ubuntu 10.04 workstation.

Until this issue is fixed, you could modify jetty.xml configuration file to use SystemProperty instead of Property in the definition of the connector, and then use the command 'java -Djetty.port=9000 -jar start.jar' to start the server on the specified port.

Regards,
Michael
Comment 4 Greg Wilkins CLA 2010-09-08 00:07:40 EDT
Another work around is to revert the <Property ...> element in jetty.xml to a <SystemProperty ...> element.  

I'll investigate why the properties are not working.
Comment 5 Greg Wilkins CLA 2010-09-08 00:30:11 EDT
The handling of properties is still a bit confused since the refactor, as evidence by the dual handling of jetty.home in the start.config and in Main itself.

Currently the properties set on the command line are not communicated to the XmlConfiguration execution.  However, if a file ending with .properties is listed on the command line, it will be used as a property file and can affect the properties used by XmlConfiguration.

I will try to clean up the current duopoly of jetty.home handling and then look to pass in the start.jar properties to XmlConfiguration with a temporary property file.
Comment 6 Greg Wilkins CLA 2010-09-08 01:30:44 EDT
Joakime,

can you remind me why we switched all the config files from SystemProperties to Properties?

There is no easy way to pass the start properties to the XmlConfiguration properties. Using SystemProperties is much simpler.
Comment 7 Greg Wilkins CLA 2010-09-08 02:05:11 EDT
Looking at the Properties stuff in start.jar and I've got myself really confused.
I understand that we switched to using Properties in the context xml files, because they get their properties from the deployer, but I can't see why the start mechanism has switched to Properties from SystemProperties.
Comment 8 Quintin CLA 2010-09-08 13:29:19 EDT
(In reply to comment #3)
> Jetty 7 has different startup options then compared to Jetty 6. You can learn
> about available options by executing the command 'java -jar start.jar --help'
> 
> In Jetty 7, in order to start the server on a different port, you should use
> command 'java -jar start.jar jetty.port=9000'. However, I've confirmed that it
> does not work using release 7.1.6.v20100715. It is definitely not platform
> dependent as I've tested it on Ubuntu 10.04 workstation.
> 
> Until this issue is fixed, you could modify jetty.xml configuration file to use
> SystemProperty instead of Property in the definition of the connector, and then
> use the command 'java -Djetty.port=9000 -jar start.jar' to start the server on
> the specified port.
> 
> Regards,
> Michael


Thank you Michael, the SystemProperty definition works great.. It is now setting the port appropriately.
Comment 9 Joakim Erdfelt CLA 2010-09-21 21:24:01 EDT
Alright.

This is what we should do.

a) Leave the jetty.xml alone, and use <Property>
b) Fix jetty-start to take the entire System.getProperties() and set them as Properties within jetty-xml

The rationale is that jetty.xml is used in many places, even embedded, and in many of those cases <SystemProperty> is inadequate or just plain wrong of choice when multiple servers are started within the same JVM.

Note: I'm not proposing eliminating <SystemProperty> from jetty-xml, as it has a useful purpose for many individuals.  

We would instead strive to make the various jetty-distribution maintained etc/*.xml files not use <SystemProperty> while allowing users and implementors the option of using <SystemProperty> themselves.

Hope that made sense.
Comment 10 Greg Wilkins CLA 2010-09-22 16:12:44 EDT
Joakim,

part b is the problem.  There is currently no way of communicating any properties from start to jetty-xml, because start cannot depend on jetty-xml.

The only way I can see of doing this is to generate a temporary properties file and add it to the args passed to XmlConfiguration, and let it read those properties ( I think properties files are already supported ).

I'd still like to find a way to do that property pass in memory rather than by a file (as that may get confused with other args), but it should at least work for a start.

Good idea to copy all system properties to properties.
Comment 11 Jesse McConnell CLA 2010-10-06 15:55:37 EDT
*** Bug 322520 has been marked as a duplicate of this bug. ***
Comment 12 Jesse McConnell CLA 2010-10-06 16:19:39 EDT
I am thinking that we could make the _properties in Config in jetty-start into a static var and then in the static constructor call System.getProperties() and set them into the _properties hash map..

that would handle the short term goal of addressing the SystemProperty vs Property issue in our configuration xmls 

thoughts?
Comment 13 Greg Wilkins CLA 2010-10-06 19:46:00 EDT
I have resolved this by making the XmlConfiguration main method use reflection to look for the existence of org.eclipse.jetty.start.Config.  If it exists, the it calls getProperties to initialize the property map used.

This allows the start properties to be used by XmlConfiguration, but only if used as a main.

setting jetty.port now works fine.
Comment 14 Andreas Schoeneck CLA 2010-11-23 16:56:50 EST
Still present in 7.2.1.
Comment 15 Greg Wilkins CLA 2010-11-23 19:03:27 EST
I just tried 7.2.1 and it worked fine:

gregw@Brick: /tmp/jetty-distribution-7.2.1.v20101111
[507] java -jar start.jar jetty.port=8765
2010-11-24 11:03:19.321:INFO::jetty-7.2.1.v20101111
2010-11-24 11:03:19.333:INFO::Deployment monitor /tmp/jetty-distribution-7.2.1.v20101111/webapps at interval 1
2010-11-24 11:03:19.335:INFO::Deployment monitor /tmp/jetty-distribution-7.2.1.v20101111/contexts at interval 1
2010-11-24 11:03:19.336:INFO::Deployable added: /tmp/jetty-distribution-7.2.1.v20101111/contexts/test.xml
2010-11-24 11:03:19.378:INFO::Extract jar:file:/tmp/jetty-distribution-7.2.1.v20101111/webapps/test.war!/ to /tmp/jetty-0.0.0.0-8765-test.war-_-any-/webapp
2010-11-24 11:03:19.803:INFO:org.eclipse.jetty.servlets.TransparentProxy:TransparentProxy @ /javadoc to http://download.eclipse.org/jetty/stable-7/apidocs
2010-11-24 11:03:19.804:INFO::Deployable added: /tmp/jetty-distribution-7.2.1.v20101111/contexts/javadoc.xml
2010-11-24 11:03:19.830:INFO::Started SelectChannelConnector@0.0.0.0:8765
Comment 16 Andreas Schoeneck CLA 2010-11-24 03:41:19 EST
Verified. I was presuming setting Jetty's Port would work like

java -Djetty.port=8765 -jar start.jar

as shown in the docs.

(In reply to comment #15)
> I just tried 7.2.1 and it worked fine:
> 
> gregw@Brick: /tmp/jetty-distribution-7.2.1.v20101111
> [507] java -jar start.jar jetty.port=8765
Comment 17 Raman Gupta CLA 2010-12-04 00:20:58 EST
(In reply to comment #16)
> Verified. I was presuming setting Jetty's Port would work like
> 
> java -Djetty.port=8765 -jar start.jar
> 
> as shown in the docs.
> 
> (In reply to comment #15)
> > I just tried 7.2.1 and it worked fine:
> > 
> > gregw@Brick: /tmp/jetty-distribution-7.2.1.v20101111
> > [507] java -jar start.jar jetty.port=8765

Still doesn't work when using the --exec or --dry-run options.
Comment 18 Greg Wilkins CLA 2010-12-05 05:56:58 EST
I just tried the staged 7.2.2 and I got:

gregw@Brick: ~/Desktop/jetty-distribution-7.2.2.v20101203
[512] java -jar start.jar jetty.port=8765 --exec
2010-12-05 11:54:41.843:INFO::jetty-7.2.2.v20101203
2010-12-05 11:54:41.855:INFO::Deployment monitor /home/gregw/Desktop/jetty-distribution-7.2.2.v20101203/webapps at interval 1
2010-12-05 11:54:41.863:INFO::Deployment monitor /home/gregw/Desktop/jetty-distribution-7.2.2.v20101203/contexts at interval 1
2010-12-05 11:54:41.864:INFO::Deployable added: /home/gregw/Desktop/jetty-distribution-7.2.2.v20101203/contexts/test.xml
2010-12-05 11:54:41.903:INFO::Extract jar:file:/home/gregw/Desktop/jetty-distribution-7.2.2.v20101203/webapps/test.war!/ to /tmp/jetty-0.0.0.0-8765-test.war-_-any-/webapp
2010-12-05 11:54:42.350:INFO:org.eclipse.jetty.servlets.TransparentProxy:TransparentProxy @ /javadoc to http://download.eclipse.org/jetty/stable-7/apidocs
2010-12-05 11:54:42.351:INFO::Deployable added: /home/gregw/Desktop/jetty-distribution-7.2.2.v20101203/contexts/javadoc.xml
2010-12-05 11:54:42.375:INFO::Started SelectChannelConnector@0.0.0.0:8765


gregw@Brick: ~/Desktop/jetty-distribution-7.2.2.v20101203
[515] eval $(java -jar start.jar jetty.port=8765 --dry-run)
2010-12-05 11:55:38.339:INFO::jetty-7.2.2.v20101203
2010-12-05 11:55:38.352:INFO::Deployment monitor /home/gregw/Desktop/jetty-distribution-7.2.2.v20101203/webapps at interval 1
2010-12-05 11:55:38.355:INFO::Deployment monitor /home/gregw/Desktop/jetty-distribution-7.2.2.v20101203/contexts at interval 1
2010-12-05 11:55:38.355:INFO::Deployable added: /home/gregw/Desktop/jetty-distribution-7.2.2.v20101203/contexts/test.xml
2010-12-05 11:55:38.394:INFO::Extract jar:file:/home/gregw/Desktop/jetty-distribution-7.2.2.v20101203/webapps/test.war!/ to /tmp/jetty-0.0.0.0-8765-test.war-_-any-/webapp
2010-12-05 11:55:38.848:INFO:org.eclipse.jetty.servlets.TransparentProxy:TransparentProxy @ /javadoc to http://download.eclipse.org/jetty/stable-7/apidocs
2010-12-05 11:55:38.849:INFO::Deployable added: /home/gregw/Desktop/jetty-distribution-7.2.2.v20101203/contexts/javadoc.xml
2010-12-05 11:55:38.874:INFO::Started SelectChannelConnector@0.0.0.0:8765
^C2010-12-05 11:55:42.148:INFO::Graceful shutdown SelectChannelConnector@0.0.0.0:8765
2010-12-05 11:55:42.152:INFO::Graceful shutdown o.e.j.w.WebAppContext{/,file:/tmp/jetty-0.0.0.0-8765-test.war-_-any-/webapp/},/home/gregw/Desktop/jetty-distribution-7.2.2.v20101203/webapps/test.war
2010-12-05 11:55:42.153:INFO::Graceful shutdown o.e.j.s.h.ContextHandler{/javadoc,file:/home/gregw/Desktop/jetty-distribution-7.2.2.v20101203/javadoc}


so looks to be working fine???
Comment 19 Raman Gupta CLA 2010-12-05 11:08:13 EST
(In reply to comment #18)
> I just tried the staged 7.2.2 and I got:
> [...] 

Looks like it might be fixed in 7.2.2. Here is what I get with 7.2.1 on Windows:

C:\tmp\jetty-distribution-7.2.1.v20101111>java -jar start.jar jetty.port=8081 --exec
2010-12-05 10:51:21.364:INFO::jetty-7.2.1.v20101111
2010-12-05 10:51:21.489:INFO::Deployment monitor C:\tmp\jetty-distribution-7.2.1.v20101111\webapps at interval 1
2010-12-05 10:51:21.489:INFO::Deployment monitor C:\tmp\jetty-distribution-7.2.1.v20101111\contexts at interval 1
2010-12-05 10:51:21.489:INFO::Deployable added: C:\tmp\jetty-distribution-7.2.1.v20101111\contexts\test.xml
2010-12-05 10:51:21.630:INFO::Extract jar:file:/C:/tmp/jetty-distribution-7.2.1.v20101111/webapps/test.war!/ to C:\Documents and Settings\Raman Gupta\Local Settings\Temp\jetty-0.0.0.0-8080-test.war-_-
any-\webapp
2010-12-05 10:51:23.083:INFO:org.eclipse.jetty.servlets.TransparentProxy:TransparentProxy @ /javadoc to http://download.eclipse.org/jetty/stable-7/apidocs
2010-12-05 10:51:23.083:INFO::Deployable added: C:\tmp\jetty-distribution-7.2.1.v20101111\contexts\javadoc.xml
2010-12-05 10:51:23.192:INFO::Started SelectChannelConnector@0.0.0.0:8080

and on Linux:

$ java -jar start.jar jetty.port=8081 --exec 2<&1 | grep Connector
2010-12-05 11:07:24.478:INFO::Started SelectChannelConnector@0.0.0.0:8080

Where can I download 7.2.2 to try it?
Comment 20 Raman Gupta CLA 2010-12-05 11:21:55 EST
(In reply to comment #19)
> Looks like it might be fixed in 7.2.2. Here is what I get with 7.2.1 on
> Windows:

Found 7.2.2 at sonatype.org and confirmed it is now working.