How do you make a console program a .jar in Eclipse?
I've been making console programs for some time now,
And I use Eclipse.
But I've never made a single console program a .jar before.
I've read other threads and some tutorials,but then when I export it, I cant see the console or the console isn't opening at all.
I've heard that you need some batch file to do it, or use the command prompt,but I don't know what to do.
All I need is that there to be an icon. Double click the icon,a command prompt pops up and runs a program.
Any help will be greatly appreciated.
Re: How do you make a console program a .jar in Eclipse?
Well, what you've heard is correct- you either need to open the jar on the command prompt, or you need to write a script that opens the command prompt and runs the jar for you. The jar can't open the command prompt and run itself.
You could also google something like "java open command prompt" and write a program that opens the jar this way, but it's the same principle.
Re: How do you make a console program a .jar in Eclipse?
Quote:
Double click the icon,a command prompt pops up and runs a program.
uhm.. is it something like a VB script? Inside the forum, on the snippets and Tutorial Threads, i got a very wonderful code, when you run it, a JOptionPane dialog will pop up, asking you if you want to open your CD-ROM, when you press OK, it will open(only a problem with closing), it has some VB script something, i'm not sure if its a bit relevant to what you are looking at
look at here, i found it
http://www.javaprogrammingforums.com...dvd-drive.html
although the code is all about CD drive, it has something to do with computer system command things, i hope this can guide you to what you need
Re: How do you make a console program a .jar in Eclipse?
-.- , you made me curious , i got this on web.
Code :
Runtime.getRuntime().exec("cmd.exe /c start");
now you just have to work on your .jar .. -.-
Re: How do you make a console program a .jar in Eclipse?
If you are using windows a simple batch script will do it. Create a text file in the place you want to run it from. The command is exactly what you would use to run the jar file from the command prompt. Finally, rename it to run.bat
Code :
@echo off
java -jar path/to/jar_file/myJarFile.jar
Re: How do you make a console program a .jar in Eclipse?
Re: How do you make a console program a .jar in Eclipse?
Reply to Christopher: Thank you! However,when I run the .bat,it says something about "sun.lang" and I think I saw a "Launcher" in there somewhere...maybe even a "getMainClass"? Yes,I have set the proper location. ....but the program is in C:/ .... My system doesent want me to go snooping around there,maybe my system is blocking java from getting acess?
Re: How do you make a console program a .jar in Eclipse?
Quote:
Originally Posted by
Programmer142
Reply to Christopher: Thank you! However,when I run the .bat,it says something about "sun.lang" and I think I saw a "Launcher" in there somewhere...maybe even a "getMainClass"? Yes,I have set the proper location. ....but the program is in C:/ .... My system doesent want me to go snooping around there,maybe my system is blocking java from getting acess?
If you want help, you'll have to post the actual error message here. We can't really guess from vague descriptions like that.
Re: How do you make a console program a .jar in Eclipse?
If you have trouble reading the error messages run the bat file from the command line rather than double clicking on an icon.
Re: How do you make a console program a .jar in Eclipse?
Quote:
Originally Posted by
Programmer142
Reply to Christopher: Thank you! However,when I run the .bat,it says something about "sun.lang" and I think I saw a "Launcher" in there somewhere...maybe even a "getMainClass"? Yes,I have set the proper location. ....but the program is in C:/ .... My system doesent want me to go snooping around there,maybe my system is blocking java from getting acess?
Perhaps.. There are several things that can cause this. Can you run the program from the command line at all? Can you run the java command? The batch script is just a shortcut so, like regular shortcuts it will not work if it can't find what is pointing to.
Try this at the command prompt:
If it says that it cannot find javac then you need to configure your PATH environmental variable to include the SDK's bin directory.
Actually, I just remembered I wrote a batch script many many years ago to check out if your system is configured correctly. Miracle I still have it. This should make things easier:
Code :
@echo off
echo You path is:
echo %PATH%
echo .
echo Your JRE is:
java -version
echo .
echo Your Java compiler version is:
javac -version
echo .
echo Your ant version is:
ant.bat -version
echo Your GIT version is:
git --version
echo .....................
set /P theuserinput="Press [ENTER] to finish"
At the least, you need java and javac working.
Oh, and you can add that last line to the end of your run.bat script and it will give you a chance to see the error message you are getting.
Let us know how you get on.