want to package a class file and a jar file in main jar file
hello folks,
i have a class named launch.class
and a jar file named First_Sample2.jar
First_Sample2 is an application that i have made which requires more memory than is generally allocated by the JRE. so, launch.java file just contains code to execute the command:
javaw -Xms128M -Xmx256M -jar " + path + "First_Sample2.jar"
where path variable refers to a directory which contains First_Sample2.jar
problem is that the only way i can use this code is by keeping two separate JAR files, one is launch.jar, the other is First_Sample2.jar and then execute launch.jar, which will in turn call First_Sample2.jar (which means I have to provide anyone with 2 separate files if they want to use my application)
is there any way in which i can combine both these jar files into one?
[824 byte] By [
m_kadiaa] at [2007-11-26 18:23:39]

# 1
i tried jar -cfm application.jar mainClass.txt launch.class First_Sample2.jar
the manifest file mainClass.txt contains just the Main-Class: launch
my understanding was that when i double click application.jar, it would call launch.class, which would then call First_Sample2.jar. Evidently, i was wrong.
I think, effectively what i want is to have the "path" variable that is in the launch.java file to contain the path of the region within the JAR file, and not of the directory where the JAR file is located
# 3
maple_shaft, all i want now is for my application to run using a double click, and i want to package into my application just one JAR file, not two. it doesn't matter if the final jar file contains two classes, or it contains two jar files as long as my First_Sample2.jar or First_Sample2.class can be called. so if there is a way to do that, please can you elaborate?
# 4
Well there is a couple ways you can achieve this, but I am telling you that packaging a JAR within a JAR will not work because classes within the internal JAR will not be recognized on the classpath.
The easiest way to get the user to run your program with a simple double click would be to hide the two JAR files from them completely, having them reside in a folder somewhere on the user's computer. I would use a batch file (Windows environment) or an .sh file (Unix) that would set up your classpath variable and then call java to execute the main class in your main JAR.
For instance:
cd [Where java.exe resides]
set CLASSPATH=[semi-colon delimited absolute file paths pointing to your two JAR files and any other JAR files that they reference]
java -cp %CLASSPATH% [main class]
The user would have access to this batch file, perhaps on their desktop, where they can double click to execute teh program just as if it were an EXE file. This is the best way because it hides the JAR files from the user.
If you would like to combine the two JAR files however, you would need to extract the contents of the secondary JAR file and then include them in with the contents of the main JAR file. That is the only other way that all classes are visible on the classpath.