简体   繁体   English

在jsvc类路径中使用多个jar

[英]Using multiple jars in the jsvc classpath

I am trying to get a Java application to run as a Linux service using jsvc. 我正在尝试使用jsvc将Java应用程序作为Linux服务运行。 I found How to convert a java program to daemon with jsvc? 我找到了如何用jsvc将java程序转换为守护进程? which was able to get me most of the way, but I am still struggling to get the classpath figured out. 它能够让我大部分时间,但我仍然在努力让类路径得到解决。

I am getting the following errors to stderr: 我向stderr收到以下错误:

19/04/2013 10:43:18 12233 jsvc.exec error: Cannot find daemon loader org/apache/commons/daemon/support/DaemonLoader 19/04/2013 10:43:18 12233 jsvc.exec错误:找不到守护进程加载器org / apache / commons / daemon / support / DaemonLoader

19/04/2013 10:43:18 12231 jsvc.exec error: Service exit with a return value of 1 19/04/2013 10:43:18 12231 jsvc.exec错误:服务退出,返回值为1

It would seem that the runtime is unable to find the commons-daemon.jar. 似乎运行时无法找到commons-daemon.jar。

My application is structured so that with the application itself in a single jar file, with dependencies, including commons-daemon in a lib directory. 我的应用程序是结构化的,以便应用程序本身在一个jar文件中,具有依赖项,包括lib目录中的commons-daemon。

  • daemon-script.sh daemon-script.sh
  • myapp.jar myapp.jar
  • lib/commons-daemon.jar LIB /公地daemon.jar
  • lib/other-jars LIB /另一罐

Here is the relevant parts of my daemon-script.sh: 这是我的daemon-script.sh的相关部分:

LIB_DIR=$(pwd)/lib/* LIB_DIR = $(PWD)/ lib目录/ *

CLASS_PATH=$(pwd)/myapp.jar CLASS_PATH = $(PWD)/myapp.jar

$EXEC -home $JAVA_EXEC -cp $CLASS_PATH:$LIB_DIR -outfile $LOG_OUT -errfile $LOG_ERR -pidfile $PID $1 $CLASS $ EXEC -home $ JAVA_EXEC -cp $ CLASS_PATH:$ LIB_DIR -outfile $ LOG_OUT -errfile $ LOG_ERR -pidfile $ PID $ 1 $ CLASS

I have tried numerous variations: relative path, specifically referencing lib/commons-daemon.jar, no wildcard, etc. Does anyone have an idea how to make this work properly? 我尝试了很多变化:相对路径,特别是引用lib / commons-daemon.jar,没有通配符等。有没有人知道如何正常工作?

Also, myapp.jar is a self-executable jar (mostly for testing purposes, and yes, I still need it to run as a service) , so the manifest.mf contains the Class-Path and Main-Class attributes. 此外,myapp.jar是一个可自我执行的jar (主要用于测试目的,是的,我仍然需要它作为服务运行) ,因此manifest.mf包含Class-Path和Main-Class属性。 Is there a way to get jsvc to recognize the manifest? 有没有办法让jsvc识别清单?

You can use multiple jars with JSVC using : between them. 您可以使用JSVC使用多个jar 它们之间。

For your specific issue the solution would be changing the CLASS_PATH variable to this: 对于您的特定问题,解决方案是将CLASS_PATH变量更改为:

CLASS_PATH=$(pwd)/myapp.jar:$(pwd)/lib/commons-daemon.jar:$(pwd)/lib/other-jars

Alternatively you can include all jars in a directory by using wildcards like this: 或者,您可以使用以下通配符将所有jar包含在目录中:

CLASS_PATH=$(pwd)/myapp.jar:$(pwd)/lib/*.jar

Hope this helps 希望这可以帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM