简体   繁体   中英

tools.jar dependency

Consider a Java program, launched from a main method, that needs something from tools.jar. In this case, some utility code for connecting to JMX services. Do we have any choice but to wrap it in a shell script that uses -cp to manage the class path? We'd much rather use a MANIFEST.MF classpath.

from http://java.sun.com/developer/Books/javaprogramming/JAR/basics/manifest.html

the URLs in the Class-Path header are given relative to the URL of the JAR file of the applet or application.

I do not believe you have a choice about using a shell wrapper to get the tools.jar on your classpath. unless you write some custom classloader internally to allow you to find external jars.

If incorporating classes from the dependency jar is an option, I'd go with creation of a "Runnable JAR file". Basically you extract the classes from it and put them with your own classes in the JAR. That eliminates the need for a wrapping script.

To do that in Eclipse, select your project, File -> Export -> Java -> Runnable JAR file ; that option will require that you have executed the main class at least once to know what profile to run when you actually run produced JAR.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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