srinivas Rao
srinivas Rao

Reputation: 21

Executing stand alone project with main method through batch file

I have a project with main method.I have to execute this project through batch prcessing.

I have exported it to jar file and created .bat file. I have used start javaw -jar JarFile.jar command in .bat file to execute the jar file. But it is not working. Please help me.

And also i have a doubt, if we export the stand alone project to jar and execute it through batch file, how batch file will be aware of in which class main method is available and execute it.?

Thank you.

Upvotes: 0

Views: 1005

Answers (3)

justRadojko
justRadojko

Reputation: 257

You can try using following command from Java, where you should loop through all jars you have.

Runtime.getRuntime().exec("java -jar yourJarFile.jar")

Upvotes: 0

Prim
Prim

Reputation: 2978

You can use the commandline by passing explicitly the class containing the main method:

java -cp <yourJarFile.jar> com.example.MainClass

You can also define a main class into a manifest file in the jar. Doing that, the main class will be executed by default when you call:

java -jar yourJarFile.jar

Upvotes: 0

Sachin
Sachin

Reputation: 394

You'll need a manifest file to tell where the main class is.

The manifest file will contain a Main-Class, for ex -

Manifest-Version: 1.0
Created-By: 1.7.0_06 (Oracle Corporation)
Main-Class: MyPackage.MyClass

Have a look at this link - https://docs.oracle.com/javase/tutorial/deployment/jar/appman.html

Upvotes: 1

Related Questions