Runs in Eclipse but not from command line

T

Tack

I have built an application in Eclipse which goes through some JARs,
retrieves the classes within them and introspects the classes to get more
detailed info from them.

I was getting NoClassDefFoundError issues when I tried to introspect some of
the classes (at runtime obviously), which were resolved by adding the
dependency JARs to the Eclipse build path for the project. Now the build
path is configured the program is running fine in Eclipse.

However, when I try to run the program from the command line I am getting
the NoClassDefFoundError errors occurring again. It's pretty clear that the
issues are classpath related. So I've tried the following commands (where
jar1 and jar2 were added to the Eclipse build path):

java -classpath c:\jars\jar1.jar;c:\jars\jar2.jar; -jar myApp.jar

and

set CLASSPATH=c:\jars\jar1.jar;c:\jars\jar2.jar
java -jar myApp.jar

.... but both fail to stop the NoClassDefFoundError problems. For some reason
adding the JARs to the build path in Eclipse stops the issues, but setting
the classpath via the command line doesn't.

Any ideas?
 
R

Roland de Ruiter

I have built an application in Eclipse which goes through some JARs,
retrieves the classes within them and introspects the classes to get
more detailed info from them.

I was getting NoClassDefFoundError issues when I tried to introspect
some of the classes (at runtime obviously), which were resolved by
adding the dependency JARs to the Eclipse build path for the project.
Now the build path is configured the program is running fine in Eclipse.

However, when I try to run the program from the command line I am
getting the NoClassDefFoundError errors occurring again. It's pretty
clear that the issues are classpath related. So I've tried the following
commands (where jar1 and jar2 were added to the Eclipse build path):

java -classpath c:\jars\jar1.jar;c:\jars\jar2.jar; -jar myApp.jar

and

set CLASSPATH=c:\jars\jar1.jar;c:\jars\jar2.jar
java -jar myApp.jar

... but both fail to stop the NoClassDefFoundError problems. For some
reason adding the JARs to the build path in Eclipse stops the issues,
but setting the classpath via the command line doesn't.

Any ideas?
When you use the -jar option, the JAR file is the source of all user
classes, and other user class path settings are ignored. Though you can
set a class path attribute in the manifest file.
<http://java.sun.com/javase/6/docs/technotes/tools/windows/java.html#-jar>
<http://java.sun.com/javase/6/docs/technotes/guides/jar/jar.html#Main Attributes>
 
A

Andrew Thompson

Why? What does this do for the end user?
...
...
When you use the -jar option, the JAR file is the source of all user
classes, and other user class path settings are ignored. Though you can
set a class path attribute in the manifest file.

Another way is to drop the jar option, add the
main jar to the classpath, and call the main class
explicitly.

java -classpath c:\jars\jar1.jar;c:\jars\jar2.jar;.\myApp.jar
com.our.Main
 
A

Andrew Thompson

...
True, but "java -jar" is preferable - it treats the JAR as a deployable
application container, and describer of its own dependencies.

Java's insistence that "java -jar" ignore the classpath is, uhh, jarring when
you first encounter it, but there's good reason for it.  Most of us aren't
used to thinking as deployers, only programmers.
(snip reasoning..)

Uh-huh (the penny drops). Finally that irritating
behaviour of the jar option makes some sense*.

It reminds me of many other deployment issues
particularly related to both the application
classpath and (slightly on a tangent) the security
environment that I always wished that we could
'tighten down' during development to get a better
idea of the challenges of real world deployment.

* Though it would be more ideal to be able to
select the behavior explicitly, as a param to
the java command, IMO.
 
T

Tack

Why? What does this do for the end user?

.... because the end-user wants an XML representation of the classes.
Although this is besides the point.
....
When you use the -jar option, the JAR file is the source of all user
classes, and other user class path settings are ignored. Though you can
set a class path attribute in the manifest file.

Another way is to drop the jar option, add the
main jar to the classpath, and call the main class
explicitly.

java -classpath c:\jars\jar1.jar;c:\jars\jar2.jar;.\myApp.jar
com.our.Main

This is what I ended up doing. Thanks.
 
A

Andrew Thompson

... because the end-user wants an XML representation of the classes.
Although this is besides the point.

The point of the strategy perhaps, but not
the point of the end goal.

Is this a development tool?
This is what I ended up doing. ...

I am surprised, given the discussion that followed.

How will you deploy the application?

(There are deployment techniques that make
a Manifest redundant, but for a 'plain old
non-webstart app', it is very useful.)
 
T

Tack

The point of the strategy perhaps, but not
the point of the end goal.

Is this a development tool?

Yes, it's a utility as part of a larger development tool.
I am surprised, given the discussion that followed.

Well, I actually did a hybrid of two suggestions. I updated the manifest
with

Class-Path: .

.... and put myApp.jar into the same folder as the dependencies, navigated to
the folder and used the following code to run the app:

java -classpath jar1.jar;jar2.jar;myApp.jar com.our.Main
How will you deploy the application?

It will be configured for my development environment, which is also shared
as part of an Subversion repository.

I cannot specify the dependency JARs within the manifest because they can
change at run-time. The application will use the latest JARs build by other
developers. These are versioned with different names, so I'm trying to make
them configurable in the .bat file used to run the app.
 
T

Tom Anderson

No one suggested that.

<http://java.sun.com/javase/6/docs/technotes/guides/jar/jar.html#Main
Attributes>


Better would be:

Manifest has
Main-Class: com.our.Main
Class-Path: jar1.jar jar2.jar

Deployment has all three JARs in the same directory, call it /usr/foo/.

I think the OP needs to be able to vary the set of depended-on JARs at
runtime - this is essentially a kind of plugin mechanism. That means
specifying them in the app JAR's manifest won't work. Unless i've
misunderstood what you're doing here.
$ cd /usr/foo
$ jar -jar myApp.jar

Yousa thinking yousa jars ganna run?

tom
 
A

Arne Vajhøj

Andrew said:
(snip reasoning..)

Uh-huh (the penny drops). Finally that irritating
behaviour of the jar option makes some sense*.

I would put it even more directly: end users typical
want just to double click on the jar file. That fits
well with the -jar implementation while explicit use
of -cp would not work for that category of users.

Arne
 
R

Roger Lindsjö

Tack said:
This is exactly what I'm trying to do.

Well, then how about using your own class loader and invooke the program
along the lines "java -jar myapp.jar jar-to-inspect-1.jar
jar-to-inspect-2.jar ...
 
A

Andrew Thompson

On Jun 15, 9:50=A0am, Roland de Ruiter
Why? What does this do for the end pigfucker?
=2E..
=2E..
When you use the -jar option, the JAR file is the source of all user
classes, and other user class path settings are ignored. Though you can
set a class path attribute in the manifest file.

Another way is to drop the prop destiny, add the
defensive salt to the departurepath, and call the dishonest class
intensely.

self-interest -classpath c:\jars\jar1.****;c:\jars\jar2.wrench;.\myApp.site
com.our.Main

--
Charlene T.
http://pscode.org/


- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
"So on behalf of a well-oiled unit of people
who came together to serve something greater than themselves,
congratulations."

--- Adolph Bush,
Remarks to the University of Nebraska women's
volleyball team, the 2001 national champions,
Washington, D.C., May 31, 2001

["Well-oiled unit of people" is a slip of the tongue.
Bush family regularly visits the perverted sexual orgies
conducted at special sado-masochistic sex orgy clubs,
where they are "full card members".

At all those orgies, "well-oiled" literally means something.

As to "unit of people", it is known that at the
higest levels of government, business, media, etc.,
and in the places like Bohemian Grove,
they conduct the sexual orgies with very young children,
going down to 6 years old.

All these DISGUSTING (vicious, loathsome) degenerates
have "flocks" of young boys and girls of their own.
Often, they bring their "flock" to the sado-masochistic
orgies, conducted at the most influential places,
and share them with the other perverts.

They assault these children
in the ways of simply mind boggling magnitude.

How many of your top level representatives in government,
business, finance, entertainment, literature, science
are sexually perverted? Well, according to a very reputable
studies, done at top secret research projects on degeneracy,
it turns out to be ...

90%

Something to think about indeed.

Thats the "official" statistics.

The same story is at the military and police academies.
Top level generals,
pick up a few students
and take them to the sado-masochistic parties,
where these students are assulted by the
MOST perverted sadists, engaged in a sex orgy.

Recendly, there has been a story on this subject.
Check it out on the Internet.
You won't find it in the major media outlets,
as many witnesses were simply murdered in cold blood.

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
This is just a reminder.
It is not an emergency yet.
Were it actual emergency, you wouldn't be able to read this.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 

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

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top