2

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.

bmargulies
  • 97,814
  • 39
  • 186
  • 310

2 Answers2

1

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.

Helter Scelter
  • 715
  • 4
  • 12
  • 1
    The idea is that I'd abandon the use of a Class-Path manifest and just build up a long -cp argument including $JAVA_HOME/lib/tools.jar. – bmargulies Mar 10 '11 at 22:37
  • I thought I was confirming your idea and suspicion. building a long -cp argument seems to be the only nice way to do what you want. you could also possibly create a java -jar launcher which would spawn another "java -cp some.package.Main" using a system exec. That would allow you to skip the script, at the expense of spawning or forking a new process. – Helter Scelter Mar 10 '11 at 23:32
0

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.

Ilya Saunkin
  • 18,934
  • 9
  • 36
  • 50