从命令提示符编译并运行 Eclipse 项目 [英] Compile and run Eclipse Project from command prompt
问题描述
如何从命令提示符编译和运行 Java Eclipse 项目?
How to compile and run Java Eclipse Project from command prompt?
如何从命令行仅使用 java 文件名运行 Java Eclipse 项目.我不想使用 Eclipse 生成的类文件或 jar 文件.
How to run a Java Eclipse project from Command Line with java file name only. I don't want to to use class file or jar files generated by Eclipse.
有可能吗?
即使使用 jar 文件,我发现加载静态文件失败,如 FileNotFoundException
,如何解决?
Even with jar file, I found loading of static file was failing, as FileNotFoundException
, how to solve that?
我是想这样跑的-
http://www.skylit.com/javamethods/faqs/javaindos.html
先javac
然后java
推荐答案
我知道一个老问题,但如果你想知道运行基于 Eclipse 的项目(即 Eclipse 使用的项目)的命令提示符
Kind of old question I know, but if you want to know command prompt for running Eclipse-based project (i.e the one that Eclipse uses)
- 在 Eclipse 中运行您的项目
- 转到调试透视图
- (无论如何在我的屏幕上)左上角的窗口应该有一点调试"选项卡.
- 右键单击您的项目名称,选择
Properties
在下拉底部 - 点击命令行"字段(这就是您可能想要).
- 按 [ctrl]+A &[ctrl]+C 选择复制
- 将其粘贴到命令行中,或者
- (我所做的)在 Windows 中,创建新的
*.bat
文本文件并将其粘贴到那里……现在双击该文件应该会运行您的 Java 项目.
- Run your project into Eclipse
- Goto Debug perspective
- (on my screen anyway) Window in top left corner should have a little 'debug' tab.
- Right click on name of your project, select
Properties
at the bottom of drop-down - Click on the 'Command Line' field (this is what you probably want).
- Press [ctrl]+A & [ctrl]+C to select and copy
- Either paste this into command line, or
- (what I did) in Windows, create new
*.bat
text file and paste it in there ... now double clicking on that file should run your java proj.
如果你想从 Eclipse 中运行一些东西并且像我一样懒惰,这非常有用.
Pretty useful if you wanna run something out of eclipse and are lazy like me.
顺便说一句,我需要这个来导出一个 uni 作业的项目.当然,他们也希望看到 *.java
文件中的代码,并且上面只使用 Eclipse 动态构建的 *.class
文件.批量编译您的 *.java 文件 &然后运行您需要在从上面的过程中获得的 javaw
行之前组合一个适当的 javac
命令并相应地进行调整 - 请查看 Java 文档.尽管 Eclipse 已经完成了库类路径的大部分艰苦工作(我使用了一些库).
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.
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. Eclipse has done most of hard work with library class paths though (I was using a few libs).
这篇关于从命令提示符编译并运行 Eclipse 项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!