Question:
How do I create a linux executable from a java .jar file?
Michael J
2009-04-10 07:05:37 UTC
Hi, I've just started learning Java, and I wanted to know how I would turn a .jar file (created by NetBeans) into an executable for linux. Is this even possible?
Six answers:
Jason R
2009-04-10 07:19:32 UTC
I've heard of converting a .jar file to a .exe file, but not into a Linux executable. Either way, even if you could, the process would be dulling and not worth it. Java was designed to be multi-platform and converting it to an executable for a specific OS strips its only real perk away. Not to mention, you'd basically have to pack the whole VM into the executable for it to work, which creates HUGE overhead.



.jar files can be executed like any other executable as long as the JRE is installed on that system, so I wouldn't really see an advantage to doing what you want to do.



Sorry I didn't answer your question, but hopefully my response will make you reconsider.
2009-04-10 07:18:58 UTC
ive done Java a bit, more C++, but I still did a bit of Java. I havent done NetBeans in a while, but if I remeber right, this is on the Linux version if there is a difference, you have to go to File > Run Program, and than it should run. But if thats not what you want go to the command line



foo@bar~$ chmod a+x foo.jar



of course you'd want to replace foo.jar with the name of the file. the chmod a+x will add the executable bit to the file and than you can execute it. It may not work, but its worth a shot. If that doesnt work than use the same command except replace a+x with a-x and that will remove the executable bit.
deonejuan
2009-04-13 10:23:14 UTC
It takes a shell script if you want to set it up like MSWindows. I would type such a script for you but there are several variables like if you are linking external libraries or hardware devices.



But, let us suppose you were able to set up the Project correctly in NetBeans; you told the build config where the main() is in your project; and finally let's suppose you told NetBeans to Build Final. Inside the dist folder of the project will be a little icon with .jar on the end. If you open up the ReadMe text file, there will be an instruciton like: "To run this here Whizbang.jar you might wanna:

java -jar Whizbang.jar [return]



remember, the JDK is an acronymn for Java Development Kit. If you want any further OS and Desktop icon functionality we must move the efforts outside java.
?
2016-09-30 02:35:37 UTC
you ought to make an executable from a classification document?? ok, what you do is open the command instantaneous. and because you have created the java undertaking your self, you of course comprehend the place your undertaking is placed. So, flow to the perfect itemizing. Which document has your important classification? on the command instantaneous type here java area and after the area type the call of the document that has the main substantial classification. ( do no longer comprise a dot or any extension ). ( do no longer type in the letters s , p , a , c, e. I meant placed an area there ) ok, now you have your executable. To execute the undertaking you will possibly now ought to type the call of the document that had the main substantial classification on the command instantaneous. ( lower back without dot and no extension ).
VS
2009-04-13 10:23:01 UTC
Doing a chmod is really not going to do anything (in case you were thinking of doing a 755 or something).

Jar files or class files for that matter, need a java executable. You simply need to type

java ...options.... myClassFile or

java -jar ...other options.... myJarFile.jar (assuming a main-class is defined) or

java -cp myJarFile.jar:otherJarFiles ..other options.. myClassFile

Hope this helps.
Milt15
2009-04-10 13:00:49 UTC
to launch a .jar file

just type in the terminal java -jar path/prog.jar

you may even create a launcher for it

just put the launching command in the launcher

don't forget to use sudo (if you are using ubuntu or ubutnu based ) or su if your program needs administrative privileges


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...