简体   繁体   中英

Run Java project (built in eclipse) using Batch File

I want to run my java project which i've built using Eclipse IDE . Now my goal is to create a batch file which will execute my project with one click. i referred question , but didn't get any idea. Please give me a solution. Thanks in advance.

1.Open Notepad & write

@echo off

javac YOUR_JAVA_FILENAME.java

java YOUR_JAVA_FILENAME

2.Save-As executeJavaProgram.bat

Make sure that YOUR_JAVA_FILENAME.java resides with your batch file and java path is set in environment variable.

3 . Double click on batch file.

Because you are working in eclipse, this makes things easier. First, export the whole program as a executable jar. You can do this by going to Files>Export and then in the pop up go to Java>Runnable Jar. Then follow the steps required to make it. Next you make a .bat file and write the following code.

start javaw -jar NameOfJar.jar

Make sure that you put the file in the same directory as your jar. Now you should be able and click on the .bat and execute the program!

Follow this tutorial to create a jar file of your eclipse project. After doing it create a batch file in the same folder where you exported the jar with the command: java -jar yourjar.jar

Create jar file using eclipse ie right click on your project select export jar file then provide file name to store your jar file. In this file eclipse will keep all .class file only and in META-INF folder main class definition if your are creating executable jar file.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM