This question already has answers here:
How to make an executable JAR file?
(5 answers)
Closed 6 years ago.
I have taken an executable jar file from server to my local system and then I have unrar it through win rar and then I have made some changes in the .class file now i again want to make executable jar file of the folder that get created when I initially unrar it please advise how can i create executable jar file again
folks please advise with context to creating an executable jar file
Let's say that all your project file's are in folder named MyApp
then
open command prompt
navigate to directory where MyApp is placed using cd
execute command jar cvf MyApp.jar MyApp
EDIT
(To make this jar executable:)
create a file named MANIFEST.MF and put it in META-INF folder
META-INF/MANIFEST.MF
Manifest-Version: 1.0
Main-Class: com.somepackage.MyApp
OR you can simply use Launch4j to wrap up your program into an executable: http://launch4j.sourceforge.net/
Related
This question already has answers here:
How do I make a JAR from a .java file?
(8 answers)
Closed 6 years ago.
I just have some (134) .java source files with me and I'm pretty sure that contains all the necessary code!
I want some quick tutorial to compile this program into a .jar file.
(I'm on a windows platform btw)
I have tried javac and jar commands. I got my .jar file but it's not opening!!!
Thanks in advance!
Best practice is to make use of Ant/Maven/Gradle kind of build program tools that can take care of creating Jar files.
Other way is to just make use of Eclipse's feature for exporting the project as a light weight Jar file or Runnable Jar file(which includes dependencies).
Place all the files you want to include in the JAR file inside a
single folder.
Open the command prompt in Admin Mode
Navigate to the folder where you stored your files.
Set the path to the directory of the JDK bin. You will need to run
the jar.exe utility to create a JAR file, and that file is located
in the bin directory.
Create the JAR file.
The format of the command line for creating the
JAR file looks like this: jar cf 'jar-file'.jar input-file(s)
You can use WINRAR.
right click on file (put inside all your .java files) and compile by using winrar;
choose format .zip (important)
and save filename.jar (important)
This question already has answers here:
How can I replace a class file in jar files?
(4 answers)
Closed 7 years ago.
I have seen similar answers but none of them helped me so far. I want to know if there is any command to update a class file inside a Jar directory.
I have this Jar:
META-INF/
META-INF/MANIFEST.MF
src/
src/project/
....
src/project/dir/Myfile.class
META-INF/dir/
etc..
I have modified Myfile.class and I want to update the existing inside the jar's directory.
I tried
jar uf myJar.jar -C src/project/dir Myfile.class
but it does not work as expected. The jar is still the same.
Any ideas?
Edit: Working on cmd
jar uf myJar.jar -C src/project/dir Myfile.class
will place Myfile.class in the root of the jar. Instead, do
jar uf myJar.jar src/project/dir/Myfile.class
I have program in Java in path: C:\...\MyProgram.
This program have some dependencies to others *.jar files. I would run it using cmd. So what I do:
in cmd I write cd C:\...\MyProgram\bin and then java -cp C:\...\MyProgram\*;. main.Main. It is working. But now I exported MyProgram to jar file. Could you tell me how can I run this now? So I have file MyProgram.jar with these same dependencies. How run it by using cmd?
Folders and archive files
When classes are stored in a directory (folder), like /java/MyClasses/utility/myapp, then the class path entry points to the directory that contains the first element of the package name. (in this case, /java/MyClasses, since the package name is utility.myapp.)
But when classes are stored in an archive file (a .zip or .jar file) the class path entry is the path to and including the .zip or .jar file. For example, to use a class library that is in a .jar file, the command would look something like this:
% java -classpath /java/MyClasses/myclasses.jar utility.myapp.Cool
Found in http://docs.oracle.com/javase/7/docs/technotes/tools/solaris/classpath.html
You need to add a Class-Path entry to the manifest file (META-INF/manifest.mf) inside the jar:
Class-Path: /C:/.../MyProgram/ .
This assumes that there are dependent classes under C:/.../MyProgram/, not jar files.
You should also add an entry for the Main-class:
Main-Class: main.Main
Then just execute your jar as
java -jar MyProgram.jar
Set the path of JAR file in your classpath and then execute the other JAR file.
To add JAR using eclipse.
Right click on project -> properties
Java Build Path -> Click add external JARs.
This will add JAR to your classpath.
This question already has answers here:
How to make an executable JAR file?
(5 answers)
Closed 9 years ago.
I have a directory in which I generated *.class files. How can I build executable jar file from this files.
What I need to know is
how to clean dir
how to put all files in jar and make it executable
Sorry people i didnt mentioned, i need do this programmatically in java code.
java cfe myJar.jar Classname.class myClass
and for exceution
java -jar Jarname.jar
Creating a Jar
If you're using an IDE such as Eclipse or Netbeans, there are specific easier ways to do it. If not I think the following command would work:
jar cfe <jar-file> <main-class-name> <class-files...>
This question already has answers here:
Closed 12 years ago.
Possible Duplicates:
Where on the file system was my java class loaded from?
How do I get the directory that the currently executing jar file is in?
How can i know .jar file directory within my program
i want to use this directory to create another files
in same directory which user save this .jar file
I don't think you can easily find out where the JAR file is, but you can find out which directory your program is being run from:
File cwdFile = new File (".");
String cwd = cwdFile.getAbsolutePath();
This only works if the user actually runs the JAR file from the directory it's in:
java -jar MyExectuableJar.jar
If they run it from another directory, like this:
java -jar /usr/bin/java/MyExecutableJar.jar
then you'll get whichever directory the user happens to be in at the time.