File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Problem updating the JAR file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Problem updating the JAR file" Watch "Problem updating the JAR file" New topic
Author

Problem updating the JAR file

Roshni Singhania
Ranch Hand

Joined: Mar 11, 2007
Posts: 78
Hi,

I've been working on an application, a sort of a test engine. The structure of the app is something like this -

TestEngine.jar (All the classes needed to run the app)
|
|
Resources.jar (Some text files, from which the questions and answers are read)


Reading from the jar files is no problems. But writing to jar, i.e. Resources.jar is not working properly the first time round. Here's what's happening -

The class files from TestEngine.jar read from text files of Resources.jar, extract these text files on user's home directory and make changes to these files (in the home dir itself). After that, I'm trying to update the text files in Resources.jar with the new updated text files from user's home directory. Here's he code I'm using to update the text files in the Resources.jar file -



I'll try explaining step by step, what's going on in my application -

1) I launch the GUI app, where, upon logging in as "Admin" the text files from Resources.jar are extracted (rather copied) on User's Home Directory (UHD). Along with this, the getReady() method of above class is called. This method displays the paths of the files in UHD properly, meaning UpdateJar class CAN see these files in the first run of the application too.

2) I am able to make changes to these text files on UHD through my program. The files on UHD are modified properly.

3) Next, I try to call commitUpdate() method of Updatejar class above, method runs without any exceptions and prints both p.waitFor() and p.exitValue() results as 1, which is supposed to be 0 for successful operation.

4) I close the application. The text files are still there on the UHD.

5) I again launch the application, go through the steps 2 & 3 again and this time, commitUpdate()'s p.waitFor() and p.exitValue() both return 0 and my Resources.jar file is actually properly updated with the modified text files from UHD.

I've been trying to resolve this issue since few days now.. I've tried several different ways, nothing works properly. I'm getting this same problem mostly - not updating the Resources.jar in the first run. I'll really appreciate it if anyone can please help me figure out what I need to do here to make this thing update from the first run itself?
Norm Radder
Ranch Hand

Joined: Aug 10, 2005
Posts: 685
Have you tried getting the std output from the commands to see if there any messages?
Roshni Singhania
Ranch Hand

Joined: Mar 11, 2007
Posts: 78
Hi,

My problem was finally solved. Turned out I had not closed the JarFile I was reading from. Although I still don't understand why it worked properly 2nd time onwards!

Thank you, Norm Radder, for replying. I was wondering if you could please explain to me how to get the std output from the commands? I don't think I've read about/done that before. So I'd really like to know. Thanks in advance.
Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3169
    
  10
Originally posted by Roshni Singhania:
I was wondering if you could please explain to me how to get the std output from the commands?


Use the Process.getInputStream() method.

It's also worth reading this article for why you should always read the standard and error output streams even if you're not interested in the output.
[ September 03, 2008: Message edited by: Joanne Neal ]

Joanne
Roshni Singhania
Ranch Hand

Joined: Mar 11, 2007
Posts: 78
Hi Joanne,

Thanks for replying. I'll try that p.getInputStream() and see if I get anything. And thank you very much for that article. I skimmed through it, it seems very useful. Will go read it properly now. Thanks again.
Roshni Singhania
Ranch Hand

Joined: Mar 11, 2007
Posts: 78
Ok, meanwhile I have new problem. I've used jar command lots of times, but this time, I'm not able to get it to work the way I want. I don't know what exactly to put in the command. Here's the situation.. I want to get a jar file, say MyProject.jar.. this should be the structure -

MyProject.jar
|
Manifest.txt
Classes (will contain all my classes, including the one which contains the "main")
Resources (will contain the text files used by above classes)


Manifest.txt has the line -
Main-Class: Classes\MyClass<Carriage Return>

(MyClass is the one containing main method)

And I gave command as "jar -cvfm MyProject.jar Manifest.txt Classes Resources" and I get the verbose output showing all the files its adding to the jar. But when I try to run this jar, I get "Could not find the main class. Program will exit."

But this same thing works, if I take out all the classes out of the "Classes" folder and keep them with "Manifest.txt" and specify "Main-Class: MyClass".

Can anyone please tell me how to get it to work the way I want. I want the classes to be in the "Classes" folder only. So what to specify in the "Manifest.txt" then?

Main-Class: Classes\MyClass is not working. How else to specify this? Any suggestions?
Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3169
    
  10
Is Classes the name of the package that MyClass is in ?
If not then that's the problem. The structure of the jar file has to match your package structure.
Norm Radder
Ranch Hand

Joined: Aug 10, 2005
Posts: 685
Don't use a \ in the Main-class: use a .
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem updating the JAR file
 
Similar Threads
Capturing error code
App hung at waitFor() method.
Problem in executing shell script using JSP
how to run unix pipe from mkisofs and cdrecord in windows with java
Running a .bat/ .cmd file from Java