Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

NX: final packaging and the big JAR

 
Simon Ingram
Ranch Hand
Posts: 173
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi folks,
A question about packaging that I think will be useful for everyone!
My instructions require a JAR file that contains, in its root,
1. An executable JAR containing the programs. i.e. runme.jar
2. A directory called �code� containing the source code. Subdirectories within this reflect the packaging structure.
3. other bits of the project..
Now, just before I send my stuff to SUN, I would like to confirm that my project organization is OK. I have two directories called �code� and �classes� as follows:

the directory �classes� contains the same subdirectories as the corresponding �code� directory. I think this is a pretty standard set up. So, to create the runme.jar, I use change directory to get into the �classes� directory and run:

this creates the runme.jar in my classes directory. BUT to comply with the instructions, the runme.jar must be in the directory above (cert). This is the problem! The instructions require the code directory in the root of the main JAR and the runme.jar file at the same level, but to create the runme.jar I have to drop a level to directory "classes".
If I simply move the jar file from �classes� to �cert� and then load runme.jar and the code directory into the main JAR file, will it be OK? I suspect that the internal sub directory structure may be affected by moving the runme.jar. Am I worrying needlessly?
Regards,
Simon
 
Nicholas Cheung
Ranch Hand
Posts: 4982
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For simplicity, you may consider to use a Zip Utility instead of JAR utility, since the compression result are same.
I have put all the *submitted* files in the correct locations. Say:

Then, I *cd* to the directory c:\cert, and then zip all the contents inside that directory into a single JAR file, with my Prometric ID as the file name, and then use that file for submission.
Nick
 
Min Huang
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If I simply move the jar file from �classes� to �cert� and then load runme.jar and the code directory into the main JAR file, will it be OK? I suspect that the internal sub directory structure may be affected by moving the runme.jar. Am I worrying needlessly?

That's fine. Moving runme.jar won't change the directory structure inside of runme.jar. Just test your JAR and see if it runs. Also, don't forget that you're not supposed to have a directory called classes with all your compiled classes in your main JAR.
As Nicholas says, you can use a zip utility to package it into a JAR. Or, if you are using Eclipse as a development tool, you can right click on your project and pick Export to export your files into a JAR. Hope that helps.
 
Simon Ingram
Ranch Hand
Posts: 173
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Nick, but when you create the runme.jar file you have to do it in the "classes" directory to retain the same sub directory structure as the "code" directory. My question is whether having created runme.jar in directory "classes", you can then simply move it to directory "cert" and pack the whole lot as you described?
Simon
 
Simon Ingram
Ranch Hand
Posts: 173
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Min Huang,
Just noticed your post.
Also, don't forget that you're not supposed to have a directory called classes with all your compiled classes in your main JAR.

This is exactly the point. To avoid having the directory classes inside my runme.jar I must cd(change directory) into the classes directory. This means that the runme.jar will be created in directory "classes" but I need it in directory "cert". My concern is whether moving the runme.jar will cause a problem.
Simon
[ April 19, 2004: Message edited by: Simon Ingram ]
 
Michael Hartman
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you are trying to do too much at one time. Take it in two steps:
1. Compile your code and package it into a jar named runme.jar
2. Package your project submission jar per the instructions on the upload page. This jar will contain the runme.jar
My project layout is as such:
project
|- src
|--|--java
|--|--|-- < my java source files >
|--target
|--|--classes
|--|--|-- < my compiled code
scjd-XXXXXXXXX
|- code
|--|-- < my java source files >
|- docs
|--|--javadoc
|--|--|-- <javadoc html>
|--| instructions.html
|--| userguide.html
|--| choices.txt
| runme.jar
| version.txt
| db-1x3.db
To create the runme.jar:
cd project\target\classes
jar cvf target\runme.jar .
Copy the source code and runme.jar to the scjd-XXXXXXXXX folder in the right locations and your docs, etc. and create your finall submission jar:
cd scjd-XXXXXXXXX
jar cvf ..\scjd-XXXXXXXXX.jar .

Good luck.
 
Min Huang
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
- ditto on what Michael said.
 
Simon Ingram
Ranch Hand
Posts: 173
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Michael,
thanks for your reply.

cd project\target\classes
jar cvf target\runme.jar .

This seems to be the key to the problem! You say that one can cd to the classes directory and yet create the jar in the directory above, that is "target" in your example and "cert" in mine.
I tried it as follows:

clearly something is wrong, but I have no idea what. Is it something to do with my manifest file perhaps?
Simon
[ April 20, 2004: Message edited by: Simon Ingram ]
 
Matt West
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Simon



You can create your runme.jar from your classes dir by doing:

But a better way would be to create the jar from your top-level cert dir; you do not have to be in classes to get the proper dir strucute. You can use jar -C option. Can't remember the exact format though, sorry. I've switched to using ant for all this stuff and things are no longer foggy.
Hope this helps.
Matt.
 
Michael Hartman
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Simon,
I'd suggest if you are still having problems to not specify the manifest file in the jar command. Why do you need a special manifest file for the submission jar?
Second, I'd suggest not listing all the directories you need to include in the jar command line. Rather than:
jar cvfm mymanifest.mf cert/runme.jar directory1 directory2 ...
just run
jar cvf <path>/runme.jar .
where the . indicates to include the current contents of the current directory recursively.
 
Simon Ingram
Ranch Hand
Posts: 173
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Guys,
thanks for your replies. I have been playing around a bit and discovered that

does the job fine, that is creates the JAR in the desired directory. Let me just point out that the -C option will loose the internal directory structure. The relative paths are not preserved. As for Ant, I am beginning to see the point of it!
As for your question, Michael. The Manifest file is used to tell the system where to find the Main method that starts the application. Without it the application will not start when you type:
java runme.jar
Finally, I specified the directories after the jar command because I did not want to load all the subdirectories into the jar.
regards and thanks for your time,
Simon
 
Michael Hartman
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As for your question, Michael. The Manifest file is used to tell the system where to find the Main method that starts the application. Without it the application will not start when you type:
java runme.jar

Yes, for the runme.jar. I was thinking you were specifying it for the submission jar. My apologies.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic