Link to home
Start Free TrialLog in
Avatar of piou
piouFlag for Greece

asked on

Packaging & moving

I have two directories

.\oneapp
.\common

Classes in oneapp import the package common (which is imported obvisously by other apps as well.

Now I want to move oneapp to run elsewhere. I jar everything there and take it.

java -classpath oneapp.jar;common.jar mymain will not do the job. Not even if I put the un-jarred common classes in a \common directory.

What am I doing wrong??
Avatar of cheekycj
cheekycj
Flag of United States of America image

have you tried:
java -cp common.jar -jar oneapp.jar mymain

CJ
Avatar of piou

ASKER

Um, actually I am running on PersonalJava, the JVM is called 'evm' and the -jar option is not supported.
try this:
java -classpath "oneapp.jar;common.jar" mymain

CJ
Avatar of CEHJ
oneapp classes and common classes should be in the same jar
Avatar of The_ChiefGeek
The_ChiefGeek

when you build the jar file for oneapp and common are u including the oneapp and common dirs?  If there not part of the package name then u shouldn't.  ie if your classpath was set to oneapp;common then when you build the jar file do it like this:

jar cvf oneapp.jar -C oneapp .
jar cvf common.jar -C common .
ASKER CERTIFIED SOLUTION
Avatar of The_ChiefGeek
The_ChiefGeek

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of piou

ASKER

Chief, I'm pasting some output. JAR doesn't exactly do the job.

C:\WORK\PROJ\JWACommon>jar cvf JWACommon.jar -C JWACommon/ *.class
JWACommon\BadInputException.class : no such file or directory
added manifest
adding: BadPacketException.class(in = 312) (out= 223)(deflated 28%)
adding: JWAException.class(in = 297) (out= 214)(deflated 27%)
adding: Packet.class(in = 2550) (out= 1452)(deflated 43%)
adding: PacketTypes.class(in = 918) (out= 559)(deflated 39%)

C:\WORK\PROJ\JWACommon>
If you want to move this around and run it elsewhere, why are you not putting common and oneapp in the same jar?
Avatar of piou

ASKER

CEHJ,

This won't work because classes in 'common' belong to a defined package.

It's tricky the package business. I have grapsed it as far as class files concern, but when JARing... I lose it!

>>classes in 'common' belong to a defined package

Do you mean one not created by yourself? If so, are other packages using it too?
Avatar of piou

ASKER

No, I mean that classes in common belong to their package by having the line "package ..." in source. So when compiled they appear as that particular package. I also tried it to be 100% sure :)

OK. I think i get the picture now!

Can you verify that you can run your application using the common.jar *before* you move it? Make sure where X.class exists in common.jar it doesn't also exist outside the jar file (rename X.bak if necessary)
Avatar of piou

ASKER

Oh! I've made a mess now with sources' version! :(
I'll get back as soon as I sort this out.
As i stated above use the following command line when building your jar files!

# This first one includes everything in the oneapp dir, but not the oneapp dir itself ( oneapp is not a package name ).
jar cvf oneapp.jar -C oneapp .

# this one builds the jar file for the package called common.
jar cvf common.jar common
Avatar of piou

ASKER

Indeed was the C switch. Although I still don't understand why it didn't work the first times. Thanks.
piou,

When u use the -C option that simply tells the jar cmd to cd to that dir, then you have to tell it what to put in the jar.  *.class would only be all the class files in that dir ( no sub dirs included ).  I ussualy just use "." to get the entire dir and sub dirs.