简体   繁体   English

使用批处理文件运行Java项目(在eclipse中内置)

[英]Run Java project (built in eclipse) using Batch File

I want to run my java project which i've built using Eclipse IDE . 我想运行我使用Eclipse IDE构建的Java项目 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 1.打开记事本并写

@echo off

javac YOUR_JAVA_FILENAME.java

java YOUR_JAVA_FILENAME

2.Save-As executeJavaProgram.bat 2.另存为executeJavaProgram.bat

Make sure that YOUR_JAVA_FILENAME.java resides with your batch file and java path is set in environment variable. 确保YOUR_JAVA_FILENAME.java驻留在批处理文件中,并且在环境变量中设置了Java路径。

3 . 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. 首先,将整个程序导出为可执行jar。 You can do this by going to Files>Export and then in the pop up go to Java>Runnable Jar. 您可以通过以下方法执行此操作:转到“文件”>“导出”,然后在弹出窗口中转到“ Java”>“可运行的Jar”。 Then follow the steps required to make it. 然后按照所需的步骤进行操作。 Next you make a .bat file and write the following code. 接下来,创建一个.bat文件并编写以下代码。

start javaw -jar NameOfJar.jar

Make sure that you put the file in the same directory as your jar. 确保将文件放在jar所在的目录中。 Now you should be able and click on the .bat and execute the program! 现在,您应该可以单击.bat并执行程序了!

Follow this tutorial to create a jar file of your eclipse project. 按照本教程创建您的eclipse项目的jar文件。 After doing it create a batch file in the same folder where you exported the jar with the command: java -jar yourjar.jar 完成此操作后,在使用以下命令导出jar的相同文件夹中创建一个批处理文件: 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. 使用eclipse创建jar文件,即右键单击您的项目,选择导出jar文件,然后提供文件名来存储您的jar文件。 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. 如果您正在创建可执行jar文件,则eclipse在此文件中将仅保留所有.class文件,并将其保留在META-INF文件夹主类定义中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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