Re: Running a Java app from command line

P

P.Hill

Liz said:
Gee, you want to have jar files in different directories
but you don't want to tell the JVM where they are.

Actually the OP only said he didn't want to alter the classpath,
so I assumed specifying an explicit classpath on the command
line, but I like your idea of links (assuming he is on
a Unix variant.

That sounds like the OP didn't throw in an extra jars, so maybe we
are making it too difficult and the user just needs to learn to
run java root of the classes tree for the classes which he built.

-paul
 
A

Abs

P.Hill said:
Actually the OP only said he didn't want to alter the classpath,
so I assumed specifying an explicit classpath on the command
line, but I like your idea of links (assuming he is on
a Unix variant.



That sounds like the OP didn't throw in an extra jars, so maybe we
are making it too difficult and the user just needs to learn to
run java root of the classes tree for the classes which he built.

-paul

This is the directory structure of my app:


/com
/domainname
/mypackagename
Class1.class
Class2.class
....
Class3.class
extrajar1.jar
extrajar2.jar
.....
extrajarn.jar
MainApp.class


If I try to run my app using:

"java MainApp"

it finds the classes in the com.domainname.mypackagename package, but it
cannot find the classes in the extrajars, even though they are in the
same directory as my main class.


If I try to run it using the classpath parameter, like some of you told me:

"java -classpath extrajar1.jar;extrajar2.jar;....;extrajarn.jar MainApp"

it cannot find the main class (WTF?), I get a
"java.lang.NoClassDefError" error.


Can someone help me, please ?


regards
 
R

Ryan Stewart

Abs said:
This is the directory structure of my app:


/com
/domainname
/mypackagename
Class1.class
Class2.class
....
Class3.class
extrajar1.jar
extrajar2.jar
....
extrajarn.jar
MainApp.class


If I try to run my app using:

"java MainApp"

it finds the classes in the com.domainname.mypackagename package, but it
cannot find the classes in the extrajars, even though they are in the
same directory as my main class.


If I try to run it using the classpath parameter, like some of you told me:

"java -classpath extrajar1.jar;extrajar2.jar;....;extrajarn.jar MainApp"

it cannot find the main class (WTF?), I get a
"java.lang.NoClassDefError" error.
You didn't specify the current directory in the classpath. "." is the
current directory.
 
A

Abs

Ryan said:
You didn't specify the current directory in the classpath. "." is the
current directory.

Thanks, it works now. But, I'd like to know why my first option don't
work. Why it can find the classes in the unJARed package, but not the
ones in the JARs.


regards
 
R

Ryan Stewart

Abs said:
Thanks, it works now. But, I'd like to know why my first option don't
work. Why it can find the classes in the unJARed package, but not the
ones in the JARs.
Because the root of your unJARed packages is the current directory. The root
of a package in a JAR is not. A class file's full name is
packageName.className, e.g. java.util.Vector. The first package, java in
this example, must be a folder somewhere that the classpath points. A JAR
has folders in it which are top level packages, so in order for Java to see
them, the JAR must be in the classpath.
 
A

Abs

Ryan said:
Because the root of your unJARed packages is the current directory. The root
of a package in a JAR is not. A class file's full name is
packageName.className, e.g. java.util.Vector. The first package, java in
this example, must be a folder somewhere that the classpath points. A JAR
has folders in it which are top level packages, so in order for Java to see
them, the JAR must be in the classpath.

Thank you very much for the info. Now I understand the whole classpath
thing better.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top