I have a toy program that is called Test.class. It accesses a class in a jar called myjar.jar. That jar is in my CLASSPATH variable set as part of my Windows environment. When I type echo %CLASSPATH%, I see C:\myclasses\myjar.jar. When I execute my program
java Test
it runs fine.
But if I package the code as a jar and try running
java -jar Test.jar
It ca
It can’t find my classpath. I know this has a simple solution.
Can you please help me.
When
-jar(or-cpor-classpath) argument is been used, then the%CLASSPATH%will be ignored. Instead, theClass-Pathentry in JAR’s/META-INF/MANIFEST.MFfile will be used. You’d like to put the JAR-relative path to the other JAR in there. E.g.The above example expects the
myjar.jarto be in same folder as the JAR file you’d like to execute.An alternative is to package the 3rd party JAR inside your JAR file. In for example Eclipse you can do this.