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...>
Related
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/
This question already has answers here:
How to make an executable JAR file?
(5 answers)
Closed 6 years ago.
I am learning Java, and I have been programming an 80s-styled text based game. I have experience with coding so I know I will be done soon. Just so I knew how, I decided to make a .jar file. It created fine, but I have a problem: I want it to run and work in the command prompt, just like if I were using the "java FileName" command. Is there any way to do this? I want to distribute it so that for Windows, it runs in the command prompt exclusively (Apple and Linux is down the line).
Edit/Summary: To some people, this might be a duplicate of a question. It's not for these simple reasons: I know how to create a .jar file. I am trying to figure out how to create a specific type of .jar file that opens and runs in the command prompt.
I assume that you have compiled your .java files into class files. If so, than do the following:
Make a manifest file called manifest.txt and inside the file mention the class name where the main class resides. For example:
Main-Class: com.A.B.MyMainClass
com.A.B.MyMainClass is example here. You should mention your package names.
Put the above line in the manifest.txt file
Than, suppose you have your class files in c:\test\classes\ folder and suppose your class files in this folder are a.class and b.class and MyMainClass.class
Now execute the command:
jar -cvfm MyExecutable.jar manifest.txt c:/test/classes/*.class
It will create an exectable jar for you which you can run in Windows and Mac and also in Linux.
To execute the jar file:
java -jar MyExecutable.jar in the command prompt.
Use this to run your jar on command line:
java -jar <jar-name>.jar
Assuming that you have java installed on the system
Using eclipse -
http://help.eclipse.org/mars/index.jsp?topic=%2Forg.eclipse.jdt.doc.user%2Ftasks%2Ftasks-33.htm
Using Command line -
https://docs.oracle.com/javase/tutorial/deployment/jar/build.html
To run the jar file -
http://docs.oracle.com/javase/tutorial/deployment/jar/appman.html
This question already has answers here:
Whats best way to package a Java Application with lots of dependencies?
(7 answers)
Executable Jar with depedencies
(5 answers)
Closed 7 years ago.
I made my first application with Java in Eclipse now I need to repackage or create an executable file file from that project. I used a lot of external jar libraries that I would like to export whit the project. Any solution is welcome.
I suggest to use apache maven to make a fat jar in conjunction with the launch4j maven plugin to make an self-contained exe (i.e. a wrapper for the jar).
you can make a executable jar file of that project. And then make a .bat file. From that .bat file you can invoke that executable jar.
Eclipse will pack you yourprojectname.jar file, which is executable file. So, in order to run it you may just run in command line (a.k.a cmd) java -jar path/to/your/project.jar. And of course it is more easier to run it with script. There are .bat files which are something like .bash scripts in linux/unix
Right click on your Eclipse project in ProjectExplorer
Export...
Java\Runnable jar file
On dialog Runnable JAR file export
4.1. Choose the main() method you need to start from the popup "Launch configuration"
4.2. Specify the output jar like: d:\dest.jar
4.3. "Finish'
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
This question already has answers here:
Specifying classpath for a jar
(5 answers)
Closed 8 years ago.
I am not familiar with Java and I am trying to run a piece of Java code packaged as jar file.
On Windows command line, I specify the CLASSPATH to my jar folder like this:
set CLASSPATH="D:\jarFolder"
And there's a test.jar file in that folder. But when I run this
java -jar test.jar
it still failed with this error:
Unable to access jarfile test.jar
I can run the test.jar by specify the full path. But I want to know why the CLASSPATH doesn't work. My understanding is, it tells the java runtime where to locate the jar file.
Jarfiles have to be on the classpath explicitly. Specifying a classpath dir for a jarfile is not sufficient.
See the related Oracle docs on the Java command line:
When you use this option, the JAR file is the source of all user
classes, and other user class path settings are ignored.
Try to use
java -jar D:\jarFolder\test.jar
If you know main class name of your entry point of jar. You can use
set CLASSPATH="D:\jarFolder"
java yourpackage.yourEntryPoint
You can learn your entry point of your jar file using a zip program to extract jar file and reading file entry point section of manifest.mf file.
When you use -jar option, you need to specify which jar. Think of it this way. If you do not give jar name, which jar java should execute? You may have 10,20 may be 100 jars in your class path.
But if you give class name, then java searches among jars and execute correct one.