开发者

How to add deploy.jar to classpath?

I am facing the problem: I need to add ${java.home}/lib/deploy.jar JAR file to classpath in the runtime (dynamically from java).

  • The solution with Thread#setContextClassLoader(ClassLoader) (mentioned here) does not work because of this bug (if somebody can explain what is really a problem – you are welcome).
  • The solution with -Xbootclasspath/a:"%JAVA_HOME%/jre/lib/deploy.jar" does not work well for me, because I want to have "pure executable jar" as a deliverable: no wrapping scripts please (more over %JAVA_HOME% may not be defined in user's environment in Windows for example, plus I need to write a script per platform)
  • The solution with merging deploy.jar file into my deliverable works only if I make a build on Windows platform. Unfortunately, when the deliverable is produced on build server running on Linux, I got Linux-dependant JAR, which does not execute on Windows – it fails with the trace below.

I have read How the Java Launcher Finds Classes and Java programming dynamics: Java classes and class loading articles but I've got no extra ideas, how to correctly handle this situation.

Any advices or solutions are very welcomed.

Trace:

java.lang.NoClassDefFound开发者_如何学JAVAError: Could not initialize class com.sun.deploy.config.Config
    at com.sun.deploy.net.proxy.UserDefinedProxyConfig.getBrowserProxyInfo(UserDefinedProxyConfig.java:43)
    at com.sun.deploy.net.proxy.DynamicProxyManager.reset(DynamicProxyManager.java:235)
    at com.sun.deploy.net.proxy.DeployProxySelector.reset(DeployProxySelector.java:59)
...
java.lang.NullPointerException
    at com.sun.deploy.net.proxy.DynamicProxyManager.getProxyList(DynamicProxyManager.java:63)
    at com.sun.deploy.net.proxy.DeployProxySelector.select(DeployProxySelector.java:166)


Boot class path does not have a class loader, so it's impossible to add to it dynamically. However you can add a Class-Path: deploy.jar attribute to your MANIFEST.MF and require that your JAR be run with -Xbootclasspath/a:myjar.jar. If the deploy.jar will be in the same directory it will also be loaded in the boot class path.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜