Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jetty Classpath issues

Tags:

java

solr

jetty

I'm currently running Solr out of a Jetty container that it ships with. It runs correctly when run from the command line via:

java -jar start.jar

when I'm in the same directory as start.jar. Unfortunately I need to be able to launch jetty from any directory, not just the one that contains start.jar. I've tried many options, such as:

java  -Dsolr.solr.home=~/solr/ -Djetty.home=~/solr/ -Djetty.logs=~/solr/logs/ -cp ~/solr/start.jar:~/solr/lib/jetty-util-6.1.26-patched-JETTY-1340.jar:~/solr/lib/jetty-6.1.26-patched-JETTY-1340.jar:~/solr/lib/servlet-api-2.5-20081211.jar -jar ~/solr/start.jar ~/solr/etc/jetty.xml 

Every time I get this backtrace:

java.lang.ClassNotFoundException: org.mortbay.xml.XmlConfiguration
at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
at org.mortbay.start.Main.invokeMain(Main.java:179)
at org.mortbay.start.Main.start(Main.java:534)
at org.mortbay.start.Main.start(Main.java:441)
at org.mortbay.start.Main.main(Main.java:119)
like image 444
Ashton K Avatar asked Feb 03 '23 13:02

Ashton K


2 Answers

Simply changing to the correct directory before calling java.... fixed the problem for me.

like image 64
Justin Cherniak Avatar answered Feb 20 '23 11:02

Justin Cherniak


Note that when you run

java  ... -cp ~/solr/start.jar:... -jar ~/solr/start.jar ~/solr/etc/jetty.xml 

the -cp option is ignored since you use the -jar option.

From man java:

-jar

When you use this option, the JAR file is the source of all user classes, and other user class path settings are ignored.

You have two options:

  • Keep using the -jar option, but then you need to provide the classpath in the jar manifest file (note that these classpath entries can't be relative to the current path, only relative to the jar-file you're executing)
  • Skip the -jar option and provide the main class explicitly.
like image 37
aioobe Avatar answered Feb 20 '23 11:02

aioobe