Today I was playing with the jetty-maven-plugin and I came across two dilemmas:

  1. How do I get Jetty to run on port 80?
  2. How do I edit files (in Windows) once Jetty is running?

To solve the first problem, I initially used the system properties on the plugin and passed in the jetty.port variable as follows:

<plugin>
	<groupId>org.mortbay.jetty</groupId>
	<artifactId>jetty-maven-plugin</artifactId>
	<version>${jetty.version}</version>
	<configuration>
		<systemProperties>
			<systemProperty>
				<name>jetty.port</name>
				<value>80</value>
			</systemProperty>
		</systemProperties>
		<webAppConfig>
			<resourceBases>
				<resourceBase>src/main</resourceBase>
				<resourceBase>src/main/resources</resourceBase>
				<resourceBase>src/test</resourceBase>
				<resourceBase>src/test/resources</resourceBase>
			</resourceBases>
		</webAppConfig>
	</configuration>
</plugin>

However, I still had the second problem: I couldn’t edit files (in Windows) once Jetty was running. I did some digging and it looks like there is a problem with the Jetty NIO connector in Windows. There are a number of work arounds which allow the use of NIO and editing at the same time. However, these solutions involved other files or a custom webdefault.xml. In order to avoid doing this and since I use this in development, I opted to switch the Connector over to BIO. I found the connector on the Jetty site but unfortunately Maven kept throwing an error. Luckily though I found the Eclipse provided one org.eclipse.jetty.server.bio.SocketConnector. This is the final POM setting to run on port 80 and allow files to be edited:

<plugin>
	<groupId>org.mortbay.jetty</groupId>
	<artifactId>jetty-maven-plugin</artifactId>
	<version>7.4.2.v20110526</version>
	<configuration>
		<connectors>
			<connector implementation="org.eclipse.jetty.server.bio.SocketConnector">
				<port>80</port>
				<maxIdleTime>60000</maxIdleTime>
			</connector>
		</connectors>
		<webAppConfig>
			<resourceBases>
				<resourceBase>src/main</resourceBase>
				<resourceBase>src/main/resources</resourceBase>
				<resourceBase>src/test</resourceBase>
				<resourceBase>src/test/resources</resourceBase>
			</resourceBases>
		</webAppConfig>
	</configuration>
</plugin>
Alessandro

Alessandro

Serial Entrepreneur with a passion for code, sales and coffee. Always on the look out for new interesting projects. You can find me working on Mambo.IO (http://mambo.io) or doing freelance projects.
Alessandro