aspose file tools*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes packaging a JAR file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "packaging a JAR file" Watch "packaging a JAR file" New topic
Author

packaging a JAR file

Itapaj� Takeguma
Ranch Hand

Joined: Jul 21, 2004
Posts: 41
hello there,
1)
To run my server aplication I must do java -Djava.rmi.codebase.... ServerFrame server

I think my self how can I creat a JAR file where the user types:
java -jar server if I have to type -Djava...??

2)
another question: if I have a java.properties file in the current directory how can I access this file when it is inside the jar file? I can only access the properties file when put a copy outside the jar file.

thanks,
Itapaj� Takeguma.
Nigel Browne
Ranch Hand

Joined: May 15, 2001
Posts: 673
1) The user would type java -jar -Djava.rmi.server.codebase=......Server

2) Why does the properties file need to be in the jar file ?
mike acre
Ranch Hand

Joined: Sep 23, 2003
Posts: 197
InputStream is = getClass().getResourceAsStream(myPropertiesResourceInMyJar);

myProperties.load(is);


SCJP 1.4, SCJD
Itapaj� Takeguma
Ranch Hand

Joined: Jul 21, 2004
Posts: 41
but the assignment says the user will type java -jar server and not java -jar -Djava... server !
(assignment) java -jar <path_and_filename> [<mode>]

and I think that if the property file stay inside the jar, it seens to me more clean. my readme does not have to say "unpack the java.properties file to the current directory...".

thanks guys,
Itapaj�.
Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11458
    
  94

Hi Itapaj�,

If you start the RMI Registry programatically from within your application then it will already know the base path structure to your classes, and you will not need to specify the codebase on the command line.

The user's options should be persisted to the properties file - you may find that challenging if the properties file is inside the jar file.

Regards, Andrew


The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
Itapaj� Takeguma
Ranch Hand

Joined: Jul 21, 2004
Posts: 41
Originally posted by Andrew Monkhouse:
Hi Itapaj�,

If you start the RMI Registry programatically from within your application then it will already know the base path structure to your classes, and you will not need to specify the codebase on the command line.

The user's options should be persisted to the properties file - you may find that challenging if the properties file is inside the jar file.

Regards, Andrew


I've never hear about start RMI regitry programatically, could u tell where I can find some reference?

One more thing, should or shouldn't I hava a properties file? If I have some default string may I simply do:
Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11458
    
  94

HI Itapaj�,

I've never hear about start RMI regitry programatically, could u tell where I can find some reference?


Take a look at the java.rmi.registry.LocateRegistry class, particularly the createRegistry(int port) method.

One more thing, should or shouldn't I hava a properties file? If I have some default string may I simply do:


Check your instructions. Some instructions require you to save all the user configurable options to a properties file in the current working directory.

Even if your instructions don't require this, you may want to consider it anyway. It will make the system much more user friendly.

Regards, Andrew
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: packaging a JAR file