Reputation: 71
I need to run a JAR file from the command prompt. Basically I need to use the following command on startup: java -jar jar-file-name.jar
, but how?
Some more details:
I need a program launcher that will launch my program in cmd. Example code:
class hello_world{
public static void main(String args[])
{
System.out.println("Hello World!");
}
}
How can I run this automatically in cmd without using java -jar jar-file-name.jar
?
Upvotes: 0
Views: 1030
Reputation: 337
This can be easily done, simply open your command prompt and type in java -jar jarname.jar
. Now you're good to go!
Upvotes: 1
Reputation: 3125
Open you Terminal/Command console... in the folder where you have the jar that you want to execute and then write:
java -jar jar-file-name.jar
Otherwise, as Steven C suggested, make a batch file jar-file-name.bat
with the command above. Remember the path of the file.
To make a batch file, you just need to create a txt file with the command above, save it and rename it with the .bat
extension. Double click it and enjoy your Java app.
If you want to merge the batch file and the jar one, try to give a look at this How to create a Java application which can be run by a click?
Upvotes: 1
Reputation: 1666
If you want to execute a Jar file on startup you can:
Windows Environment
First Method:
go to Start/Run and then write and write REGEDIT
Go to HKEY_LOCAL_MACHINE/SOFTWARE/MICROSOFT/Windows/Current Version/Run
Append the Path to your JAR file.
Second Method
Add your JAR file into START/ALL PROGRAMS/Autostart
Linux Environment
On Linux a quick way should be:
Create a script in /etc/init.d/ to start the jar.
Remember to add & to the command. In this way the java process will run in background.
The start script should be
#!/bin/bash
java -jar myapp.jar &
If I didn't understand the question, I'm sorry. When I read on startup I've interpreted in this way.
Upvotes: 1