Jetty Classpath issues

2019-04-21 08:30发布

问题:

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)

回答1:

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.


回答2:

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



回答3:

You're using the ~ as a short cut to the current user's home directory. I'd replace all tilde characters with an absolute path and see if that helps.



回答4:

I ran into this in Jan 2014.My issue was that because I ran a Cluster Zookeeper setup from elsewhere, the $SOLR_HOME/lib folder got moved under $SOLR_HOME/cloud-scripts where the zkCli.bat exists.Copied the lib folder back under $SOLR_HOME/ and it works now.



标签: java solr Jetty