• Post Reply Bookmark Topic Watch Topic
  • New Topic

Re-execute a Jar file  RSS feed

 
Ayad Hindi
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello all,
I have a problem and was wondering if you ranchers could help me.
I've written a program that is contained inside a jar file. The program extracts itself to the temp directory and then reconstructs itself again. i.e. the .class files in the jar get extracted and then added back again to the jar.
This is working fine, but when I try to run the new jar I get the following message:
Failed to load Main-Class manifest attribute from
test.jar
My guess is that I am loosing some data between extraction and addition. I am using FileOutputStream, BuffuredOutputStream and JarOutputStream for the adding and the equivalent input streams for the extraction.
Does anyone have an idea on how could I fix this problem.
Any help would be very, very appreciated
Thanks a lot
Ayad Hindi
 
Ayad Hindi
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi again,
I have done some more testing, and I've seen that the problem must be when I re-create the jar. I run the program, and went to the temp directory and executed the code there and it worked, so the problem must be when I re-create the jar.
Plese help. Thanks
Ayad Hindi
 
Ayad Hindi
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello again,
News flash:
I figured out why its not running, but brought a new problem.
The reason it was not running is that in my JarOutputStream I was not using the contructor with the manifest parameter, i.e.
Anyway, that is solved now, the new problem is that my code is in a package, and when I re-create the jar i use:
So when I try to run it again java does not recognise the path used in the manifest. The weird thing is that when I extract the content, WinZip does create the direcoties in my File System.
Anyway, when I make the application without a package it runs perfectly, although I do need it to be in a package
Therefore, the problem is in my createJar() method, I've been trying to modify it, but I can't seem to get it right. Could anyone help me code a jar file from a directoty with many subdirectories?
Help would be very very much appreciated
Thanks you loads
Ayad Hindi
[ August 16, 2002: Message edited by: Ayad Hindi ]
 
Ayad Hindi
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ehh...hi !!
Just wanted to say....craked it !!!
The problem was that I was passing the paths of the files to the new JarEntry in the format "package\\util\\jar.class", while it should be "package/util/jar.class". I wrote a samll method to convert the path string and now it works perfectly.
Bye
Ayad Hindi
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your solution might not be as system independent as it could be. Instead of specifying the directory separator character as "/" or "\\", you might want to use System.getProperty( "file.separator" ) to get the proper seperator for whatever system the program is running on.
 
Ayad Hindi
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Interesting point, I think I'll do that.
Thanks
Ayad Hindi
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!