[英]Compile and run Eclipse Project from command prompt
How to compile and run Java Eclipse Project from command prompt? 如何从命令提示符编译和运行Java Eclipse Project?
How to run a Java Eclipse project from Command Line with java file name only. 如何仅使用java文件名从命令行运行Java Eclipse项目。 I don't want to to use class file or jar files generated by Eclipse.
我不想使用Eclipse生成的类文件或jar文件。
Is it possible? 可能吗?
Even with jar file, I found loading of static file was failing, as FileNotFoundException
, how to solve that? 即使有了jar文件,我发现加载静态文件失败了,因为
FileNotFoundException
,如何解决?
I meant to run like this- 我打算像这样跑 -
http://www.skylit.com/javamethods/faqs/javaindos.html http://www.skylit.com/javamethods/faqs/javaindos.html
First javac
then java
首先是
javac
然后是java
For building you can export an Ant build file. 对于构建,您可以导出Ant构建文件。 Just right click on the project -> Export -> Ant buildfiles .
只需右键单击项目 - > 导出 - > Ant构建文件 。 On the command promt use
ant <buildfile>
to build the project. 在命令promt上使用
ant <buildfile>
buildfile ant <buildfile>
来构建项目。
Take a look at this answer: Eclipse: export running configuration for running the eclipse project from the console. 看一下这个答案: Eclipse:从控制台导出运行 eclipse项目的导出运行配置 。
Assumes a project with the following directory structure: 假设具有以下目录结构的项目:
PROJECT_HOME
-> lib (jar files)
-> src (java code)
-> hirondelle (top-level package; no .java files)
-> ante (.java files)
-> deluvian (.java files)
Compiling With javac 用javac编译
PROJECT_HOME>javac -cp lib\* src\hirondelle\ante\*.java src\hirondelle\ante\deluvian\*.java
This compiles in place, and creates .class files beside .java files. 这将编译到位,并在.java文件旁边创建.class文件。 If you want to place generated class files elsewhere, use the -d option to put them into an existing directory:
如果要将生成的类文件放在其他位置,请使用-d选项将它们放入现有目录中:
PROJECT_HOME>javac -cp lib\* -d build src\hirondelle\ante\*.java src\hirondelle\ante\deluvian\*.java
If your jars are in various directories, then the classpath is a list delimited by semi-colons: 如果你的jar在各种目录中,那么classpath是一个由分号分隔的列表:
-cp lib\*;C:\abc\one.jar;C:\xyz\two.jar
For more information refer below links: 有关更多信息,请参阅以下链接
Compiling With javac - javapractices 用javac编译 - javapractices
Build Eclipse Java Project from Command Line - Stackoverflow 从命令行构建Eclipse Java项目 - Stackoverflow
Kind of old question I know, but if you want to know command prompt for running Eclipse-based project (ie the one that Eclipse uses) 我知道一些旧问题,但是如果你想知道运行基于Eclipse的项目的命令提示符(即Eclipse使用的那个)
Properties
at the bottom of drop-down Properties
” *.bat
text file and paste it in there ... now double clicking on that file should run your java proj. *.bat
文本文件并将其粘贴到那里...现在双击该文件应该运行你的java项目。 Pretty useful if you wanna run something out of eclipse and are lazy like me. 如果你想从日食中运行并像我一样懒惰,那就非常有用。
BTW I needed this for exporting project for a uni assignment. 顺便说一下,我需要这个用于导出单一任务的项目。 Of course, they wanted to see code in
*.java
files too and above just uses *.class
files Eclipse builds on the fly. 当然,他们也希望看到
*.java
文件中的代码,而上面只使用*.class
文件Eclipse即时构建。 To make batch compile your *.java files & then run you need to put together an appropriate javac
command before the javaw
line you got from process above and adjust accordingly - look at Java Docs for this. 要批量编译* .java文件然后运行,您需要在上面的进程中获得的
javaw
行之前放置一个适当的javac
命令并相应地进行调整 - 请查看Java Docs。 Eclipse has done most of hard work with library class paths though (I was using a few libs). 虽然Eclipse已经使用库类路径完成了大部分工作(我使用了一些库)。
Select the project and click on File->Export which opens a new window. 选择项目,然后单击File-> Export,打开一个新窗口。
From that select Runnablejar option and click next button. 从中选择Runnablejar选项,然后单击下一步按钮。
In launch configuration select your main class and in export destination give the path where you want to store the jar file. 在启动配置中,选择主类,在导出目标中,指定要存储jar文件的路径。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.