Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Starting java with -jar option precludes *.class files on CLASSPATH ?

Reply
Thread Tools

Starting java with -jar option precludes *.class files on CLASSPATH ?

 
 
Lukas
Guest
Posts: n/a
 
      11-29-2005
Hi group,

Since I found the documentation unclear on the issue, I ran some tests
to see whether I could get a directory with *.class files onto the
CLASSPATH when starting a JARred Java app (java -jar someApp.jar),
using either the JARs Manifest file, java's -classpath option or by
setting the CLASSPATH environment variable in a batch file.

It appears it can't be done.

A) can anyone confirm this?

B) are there any known reasons for this seemingly arbitrary
restriction?

Cheers

YT

 
Reply With Quote
 
 
 
 
Andrew E
Guest
Posts: n/a
 
      11-29-2005
Lukas wrote:
> Hi group,
>
> Since I found the documentation unclear on the issue, I ran some tests
> to see whether I could get a directory with *.class files onto the
> CLASSPATH when starting a JARred Java app (java -jar someApp.jar),
> using either the JARs Manifest file, java's -classpath option or by
> setting the CLASSPATH environment variable in a batch file.
>
> It appears it can't be done.


if you do this:

java -cp C:\wherever\classes -jar someApp.jar

dooes that work?
I don't have a java-installation in front of me to test, but I'm sure that used
to work for me. But I could be wrong..
 
Reply With Quote
 
 
 
 
Lukas
Guest
Posts: n/a
 
      11-29-2005
I used relative paths, and found it doesn't work.
... Didn't test for absolute paths because for my purpose they'd not cut
it, but I can't see why absolute vs relative should make a difference.

Also I've tried

set CLASSPATH=whereever;.

and in Manifest.mf

Class-Path: whereever .

They all don't work with -jar. As soon as you do

java -cp C:\wherever\classes someApp.class

everything works.
I'd rather be wrong about this though.

 
Reply With Quote
 
Timbo
Guest
Posts: n/a
 
      11-29-2005
Lukas wrote:
> Hi group,
>
> Since I found the documentation unclear on the issue, I ran some tests
> to see whether I could get a directory with *.class files onto the
> CLASSPATH when starting a JARred Java app (java -jar someApp.jar),
> using either the JARs Manifest file, java's -classpath option or by
> setting the CLASSPATH environment variable in a batch file.
>
> It appears it can't be done.
>
> A) can anyone confirm this?
>

Yes, the -cp option is ignored when the -jar option is used

> B) are there any known reasons for this seemingly arbitrary
> restriction?
>

Because jars are designed to be self contained.

The easiest way around it is:
java -cp normal_class_path:someApp.jar the,main.method.Class

It does mean the main method property in the manifest file is
ignored, but if you rely on some third-party app that can't be
jarred up with your app, then I'm afraid your stuck with this, or
something similar.

Cheers,
Tim
 
Reply With Quote
 
Lukas
Guest
Posts: n/a
 
      11-29-2005
Hi Tim,

that's how I'm currently dealing with the problem, and yes, it works
just fine, it only looks kinda unprofessional to have a full

com/somecompany/someproject/EntryPoint.class

lying around in your install directory when you were hoping to just
have

lib/someproject.jar

looking neat and tidy.
Hybris, I guess.

Thanks,

Lukas

 
Reply With Quote
 
Timbo
Guest
Posts: n/a
 
      11-29-2005
Lukas wrote:
> Hi Tim,
>
> that's how I'm currently dealing with the problem, and yes, it works
> just fine, it only looks kinda unprofessional to have a full
>
> com/somecompany/someproject/EntryPoint.class
>

You don't need to have the classes unjarred into the install
directory. If you include the jars from your app and the third
party app in the -cp option and then just provide the name of the
class with the 'main' method:
java -cp thirdparty.jar:yourApp.jar your.main.Class

then your classpath becomes all of the classes in both jar files.
It's still not ideal, but it's better than having the classes
jarred our into the install directory.

Hope this helps!
Tim
 
Reply With Quote
 
Roedy Green
Guest
Posts: n/a
 
      11-29-2005
On Tue, 29 Nov 2005 13:56:47 +0100, Andrew E <(E-Mail Removed)>
wrote, quoted or indirectly quoted someone who said :

>if you do this:
>
> java -cp C:\wherever\classes -jar someApp.jar
>
>dooes that work?


when you use a jar, the classpath is ignored. Sun assures us this is
not a bug but a feature.

see http://mindprod.com/jgloss/classpath.html
--
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.
 
Reply With Quote
 
Lukas
Guest
Posts: n/a
 
      11-30-2005
Indeed that helped! Apparently some misconception about the -jar option
had got stuck in my head there.

Thanks!

Lukas

 
Reply With Quote
 
Nigel Wade
Guest
Posts: n/a
 
      11-30-2005
Lukas wrote:

> Hi group,
>
> Since I found the documentation unclear on the issue, I ran some tests
> to see whether I could get a directory with *.class files onto the
> CLASSPATH when starting a JARred Java app (java -jar someApp.jar),
> using either the JARs Manifest file, java's -classpath option or by
> setting the CLASSPATH environment variable in a batch file.
>
> It appears it can't be done.
>
> A) can anyone confirm this?


Yes. The documentation is pretty clear about this. From the java man page (does
Windows have an equivalent?):

-jar Executes a program encapsulated in a JAR archive.
....
When you
use this option, the JAR file is the source of all
user classes, and other user class path settings
are ignored.

>
> B) are there any known reasons for this seemingly arbitrary
> restriction?


The java command a user enters to execute the jar is not under your control.

Use the manifest to set the class-path for your jar, that is under your control.


--
Nigel Wade, System Administrator, Space Plasma Physics Group,
University of Leicester, Leicester, LE1 7RH, UK
E-mail : http://www.velocityreviews.com/forums/(E-Mail Removed)
Phone : +44 (0)116 2523548, Fax : +44 (0)116 2523555
 
Reply With Quote
 
pkriens@gmail.com
Guest
Posts: n/a
 
      11-30-2005
Heard of manuals?

http://java.sun.com/j2se/1.5.0/docs/...dows/java.html

-jar
Execute a program encapsulated in a JAR file. The first argument is
the ...
... Jar files and Jar-file manifests.
When you use this option, the JAR file is the source of all user
classes,
and OTHER USER CLASS PATH SETTINGS ARE IGNORED.

Emphasis mine ...

Kind regards,

Peter Kriens

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
3 ESSENTIAL TOOLS FOR STARTING AND MAINTAINING...3 ESSENTIAL TOOLSFOR STARTING AND MAINTAINING...3 ESSENTIAL TOOLS FOR STARTING ANDMAINTAINING... Oanh Bui C++ 0 04-27-2009 12:51 PM
3 ESSENTIAL TOOLS FOR STARTING AND MAINTAINING...3 ESSENTIAL TOOLSFOR STARTING AND MAINTAINING...3 ESSENTIAL TOOLS FOR STARTING ANDMAINTAINING... Oanh Bui Python 0 04-27-2009 12:46 PM
while using javac -classpath some.jar some.java (Where does classpath get stored?) Gabe Java 3 08-27-2004 07:02 PM
Default attribute in base class precludes delegation Gabriel Genellina Python 2 12-19-2003 07:07 AM
Re: Default attribute in base class precludes delegation Gabriel Genellina Python 2 12-19-2003 06:50 AM



Advertisments