This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes package jar question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Bookmark "package jar question" Watch "package jar question" New topic
Author

package jar question

manish ahuja
Ranch Hand

Joined: Oct 23, 2003
Posts: 312
Hi All,

Hope this is the right forum for this question.
I have currently developed a java application which accepts xml as string & does xml to xml transformation using xsl
After the input xml is transformed to the new xml we check if the new xml adheres to a DTD.
In this java code i also uses log4j.

I have to create a jar file which has all the above mentioned artifacts.
1) All custom java code classes
2) log4j.jar, jaxp related jar files
3) log4j.properties
4) the XSL file which is used for transformation
5) The DTD to which the new xml confirms
6) a log file to which all logs are written.

I have created these above indivdual pieces & they work fine individually. But now i want to bundle all the above mentioned artifacts in a jar & place it into a content management system from where my classes will be invoked.


I dont have much experience with packaging of java related artifacts.
I dont have any control over the system where this jar will be used so i have to bundle everything in the jar & use references to the xsl, dtd, log4j.properties files in such a way that it gets picked from the same jar i bundle all the artifacts.

So can someone give me some hints as to how can i pick the references to the xsl , dtd & log4j.properties in my java code from the jar file & not from the file system.

Currently for testing i use the file system reference & everything works fine.

Do post your suggestions for the same


Regards
Subhadip Chatterjee
Ranch Hand

Joined: Dec 12, 2006
Posts: 93
Hi Manish,
The JAR applications work on a common file, MANIFEST.MF or Meta-Inf file. This file defines the external Jars required, and the main-class entry. As i Have done in couple different broker applications, here is what you have to do:
1. If you have a class, that's initiating the whole parsing operation, then that would be your "Main-Class:" entry in Manifest.mf
So, the class with a main method, that subsequently invokes the whole operation, should be there.
2. put your Jar files(e.g. log4j.jar) into one common folder, the folder in which your JAR application is going to run.
3.DTDs and all can reside into the same application folder.
4.build your classes
5.use "jar" tool, ported with your JDK from command prmpt to create an executable JAR.
6.put the Jar into the deplyment folder, where your log4j & accessories are residing.
7.run the application from command prompt/from shell-script

P.S. you can write an ANT script to do all this for you.


Refreshing life every moment...
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Not an advanced question. Moving...


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Mohit Sinha
Ranch Hand

Joined: Nov 29, 2004
Posts: 125
Hi

Thanks for the response. What I want to do is not keep the external files like xsl,dtd & log4j.properties in the folder where my application will run but want to package it in the same jar so the classes in the jar which require such external files will get it from the same jar.

Do post your thoughts
 
GeeCON Prague 2014
 
subject: package jar question