Reputation: 81
I've been trying to figure out how to run my packaged java application through batch file. The main reason why I've decided to use batch file is because it's quick and also allow my tutor to mark my program easily without an IDE.
The problem I'm facing is I'm not too experience in writing batch files and would appreciate if anyone could help me out. I've attached a screenshot (image here - https://db.tt/BVBZxbGx) of my project showing the structure of my files.
Upvotes: 0
Views: 1261
Reputation: 22296
from http://docs.oracle.com/javase/tutorial/deployment/jar/run.html
JAR Files as Applications
You can run JAR packaged applications with the Java launcher (java command). The basic command is:
java -jar jar-file
The -jar flag tells the launcher that the application is packaged in the JAR file format. You can only specify one JAR file, which must contain all of the application-specific code.
Before you execute this command, make sure that the runtime environment has information about which class within the JAR file is the application's entry point.
To indicate which class is the application's entry point, you must add a Main-Class header to the JAR file's manifest. The header takes the form:
Main-Class: classname
The header's value, classname, is the name of the class that is the application's entry point.
For more information, see the Setting an Application's Entry Point section.
When the Main-Class is set in the manifest file, you can run the application from the command line:
java -jar app.jar
To run the application from the jar file that is in another directory, you must specify the path of that directory: java -jar path/app.jar
So in your bath file you only need to add:
java -jar app.jar
Upvotes: 1