Reputation: 25865
I'm trying to get Maven to automatically download all dependencies for jetty-start so I run this:
java start.jar etc/jetty.xml
But when I do this:
java start.jar --list-options
I get several missing modules that I have to manually add as dependencies to my Maven file. I've tried adding them, and I get stuck on finding an appropriate version of servlet-api
that will provide javax.servlet.http.HttpServletResponse
, even though the jar downloaded for jetty-servlet
has javax/servlet/http/HttpServletResponse.class
inside it. Here is the error:
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.eclipse.jetty.start.Main.invokeMain(Main.java:457)
at org.eclipse.jetty.start.Main.start(Main.java:602)
at org.eclipse.jetty.start.Main.main(Main.java:82)
Caused by: java.lang.NoClassDefFoundError: javax/servlet/http/HttpServletResponse
at java.lang.Class.getDeclaredConstructors0(Native Method)
at java.lang.Class.privateGetDeclaredConstructors(Class.java:2389)
at java.lang.Class.getConstructor0(Class.java:2699)
at java.lang.Class.newInstance0(Class.java:326)
at java.lang.Class.newInstance(Class.java:308)
at org.eclipse.jetty.xml.XmlConfiguration$JettyXmlConfiguration.configure(XmlConfiguration.java:333)
at org.eclipse.jetty.xml.XmlConfiguration.configure(XmlConfiguration.java:291)
at org.eclipse.jetty.xml.XmlConfiguration$1.run(XmlConfiguration.java:1203)
at java.security.AccessController.doPrivileged(Native Method)
at org.eclipse.jetty.xml.XmlConfiguration.main(XmlConfiguration.java:1138)
... 7 more
Caused by: java.lang.ClassNotFoundException: javax.servlet.http.HttpServletResponse
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
... 17 more
I've tried adding the org.eclipse.jetty.aggregate:jetty-all
package to my dependency list, but the packages inside it are not detected by java start.jar --list-options
, and therefore don't work.
There are a couple of pages of documentation that are helpful, but don't answer this question specifically:
Upvotes: 2
Views: 3234
Reputation: 5867
You need both jetty-start
and jetty-all
to do what you are trying to do - though you can also use a more specific set of artifacts than jetty-all
as well.
Note that with a series of artifacts on the classpath you can't use java -jar
, so instead will need to run org.eclipse.jetty.start.Main
directly
For example:
java -cp start.jar:jetty-all.jar org.eclipse.jetty.start.Main --list-options
You probably want to create an assembly containing the required JARs (which are retrieved as Maven dependencies), and then add a start script to point to them.
You can find a more complete example here, which uses the assembly plugin and the Java Service Wrapper to run Jetty: http://svn.apache.org/viewvc/archiva/trunk/archiva-jetty/pom.xml?revision=1307001&view=markup
Upvotes: 3
Reputation: 1793
It may not answer your question, but here's how I launch Jetty in a main() method. I create an assembled app with the .war file included, and scan the filesystem to find the war, and launch Jetty with the copy of the war that was built and included in the distribution zip file.
String warLocation = locateWarFile();
WebAppContext webapp = new WebAppContext();
webapp.setWar(warLocation);
webapp.setContextPath("/");
webapp.setConfigurations(new Configuration[] {
new WebInfConfiguration(),
new EnvConfiguration(),
new WebXmlConfiguration(),
});
// launch Jetty's web server and serve requests..
Server server = new Server();
Connector connector=new SelectChannelConnector();
connector.setPort(Integer.getInteger("jetty.port",8080));
server.setConnectors(new Connector[]{connector});
server.setHandler(webapp);
server.start();
for the record, my maven dependencies:
<dependency>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty</artifactId>
</dependency>
<dependency>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-util</artifactId>
</dependency>
<dependency>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-naming</artifactId>
</dependency>
<dependency>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-plus</artifactId>
</dependency>
Upvotes: 0
Reputation: 77991
The following POM file is configured to download and run the Apache Solr web application, using Jetty:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.myspotontheweb</groupId>
<artifactId>solr</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>
<dependencies>
<dependency>
<groupId>org.apache.solr</groupId>
<artifactId>solr</artifactId>
<version>3.6.0</version>
<type>war</type>
</dependency>
<dependency>
<groupId>org.apache.solr</groupId>
<artifactId>solr-velocity</artifactId>
<version>3.6.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>8.1.3.v20120416</version>
<configuration>
<systemProperties>
<systemProperty>
<name>solr.solr.home</name>
<value>${basedir}/src/main/solr/home</value>
</systemProperty>
<systemProperty>
<name>solr.data.dir</name>
<value>${project.build.directory}/solr/data</value>
</systemProperty>
</systemProperties>
</configuration>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>run-exploded</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Application is launched from Maven as follows:
mvn compile
Solr requires additional configuration files. See the doco for details.
$ tree
.
|-- pom.xml
`-- src
`-- main
`-- solr
`-- home
`-- conf
|-- admin-extra.html
|-- elevate.xml
|-- mapping-FoldToASCII.txt
|-- mapping-ISOLatin1Accent.txt
|-- protwords.txt
|-- schema.xml
|-- scripts.conf
|-- solrconfig.xml
|-- spellings.txt
|-- stopwords_en.txt
|-- stopwords.txt
`-- synonyms.txt
Upvotes: -1
Reputation: 7182
You don't.
The jetty-start artifact is for use with the jetty distribution. There is no automatic download of dependencies when using the jetty-start artifact because the assumption is that you have the distribution on disk locally and are just trying to knit together your classpath for the server start.
With maven you use the jetty-maven-plugin if your looking to start a webapp during your build for testing or build purposes. With that plugin usage you will get the lionshare of the dependencies needed unless your trying to do something specific that demands additional dependencies in which case you add them to the section of the plugin declaration.
cheers!
Upvotes: 6