ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
i have written a java program and i am able to compile the program by
javac myprog.java
and then i can run the program by
java myprog
what i want to know is whether it is possible in linux to convert this class or the java program into an executable program ,so that i needn't type
java myprog
everytime i have to run the program..i mean for example
by typing
$./myprog
i should be able to run my program....
someone told me that in windOS by converting it to jar file it can be run without any command..i tried that in linux by converting it to a jar. but then it says it's an archive...:-)).
you MUST run the java virtual machine when running the java program, but there are a few things you can do to make an executable.
first, just make a script file in it, put java filename.java then make the scirpt executable, this will do the trick for you in linux. also, if you are really bored, you can make a c progam that just runs a system call to run the file. i would look like
#include <stdlib.h>
int main(){
system("java filename.java");
return 1;
}
just compile this (using gcc -o COMMANDNAME file.c)
where the commandname is the command you want to call (basically the executable) and the file.c is the name of the file.
this will only work if the java path is set up right on the machine.
for winblows, you can create a .bat file that just has java filename.java in it. you MAY be able to to run the above c program too, but i am not so sure about the win api.
if you want to create a jar file, in windows, just zip the file and rename it to jar, its the same thing. then you can double click it and it will run, but you have to name the jar the same as the class with the main thread.
Last edited by tyler_durden; 11-19-2001 at 08:09 PM.
Not being a java expert, far from it, I didn't think you could simply execute a class file from the shell. I always thought that you need the interpreter.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.