How to reference tools.jar from an executable jar

I will say that I do this:

java -jar someJar

"someJar" must be referenced by tools.jar (to compile jsp). I do not want to bind tools.jar inside someJar because I am afraid of incompatibility with the running JVM. I cannot specify -classpath because it is ignored when -jar is used. I tried -Djava.ext.dirs and it did not work. Does anyone have an idea on how I can reference tools.jar from an executable jar?

+3
source share
3 answers

Starting with Java 1.4, tools.jar must be included in the user class path :

(tools.jar) ( ).

, tools.jar . , JAR . :

  • tools.jar, CLASSPATH -cp. , JAR, java -cp $JDK_HOME/lib/tools.jar MainClass, MainClass - .
  • , tools.jar, , JDK. JRE , JDK. JDK java.home, System.getProperty.
+3

-jar -classpath. , classpath . "Class-Path",

, ,

<target name="jar" depends="compile">
    <jar destfile="foo.jar" basedir="classes">
        <manifest>
            <attribute name="Main-Class" value="com.wiggle.foo" />
            <attribute name="Class-Path" 
                value="C:/Java/jdk1.5.0_21/lib/tools.jar" />
        </manifest>
    </jar>
</target>

, Class-Path,

0

I do not want the manifest to refer to system-specific locations. I also cannot use -classpath when using -jar. I think this solution uses -classpath and not use -jar. Instead of putting the Main-Class in the manifest, I will put the main class on the command line.

0
source

Source: https://habr.com/ru/post/1759460/


All Articles