我如何运行主要有()在Eclipse中,而无需创建一个完整的Java项目的单一的Java文件? [英] How do I run a single Java file having main() in Eclipse, without creating an entire Java project?

查看:179
本文介绍了我如何运行主要有()在Eclipse中,而无需创建一个完整的Java项目的单一的Java文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面是我得到了什么:


  1. 我有一个 TestFile.java 通过相同的类名。

  2. 此类具有有效的的main()方法。

  3. 文件通过终端使用javac和那么Java轻松地运行,给出预期输出。

  1. I have a TestFile.java with the same class name.
  2. This class has a valid main() method.
  3. The file is easily run via terminal using javac and then java, gives intended output.

然而,当我拖放(或打开)文件到Eclipse和尝试运行方式,我不明白运行方式Java应用程序或任何可以运行单一/独立(任何项目)的Java文件/类。

However, when I drag and drop(or open) the file into Eclipse and try to Run As, I don't get Run As Java Application or anything that can run that single/independent(of any project) Java file/class.

当我尝试只是运行,我得到一个弹出说运行方式Ant构建。现在,我从来没有设置Ant构建。

When I try to just Run, I get a pop-up saying "Run As Ant Build. Now, I never setup ant build.

我要的是运行只是一个这个Java档案,并在控制台输出/错误这是可见的只是角度编辑器下方。

All I want is to run just one this Java file and see the output/error in Console that is visible just below the editor in perspective.

我没有,也不打算写/安装一个完全成熟的Java项目,包名称和所有,在这种情况下,运行的Java应用程序简直来了。我只是想用它的main()方法运行一个独立的Java类/文件在Eclipse中。

I didn't and don't intend to write/setup a full fledged Java project with package name and all, in which case Run as Java Application simply comes. I just want to run one independent Java class/file in Eclipse with a main() method in it.

我在Mac上。如果有任何其他应用程序/ IDE这不,对于Java和/或其他语言的话,我认为这将是非常有用的。

I am on Mac. If there's any other app/IDE which does that for Java and/or other languages then I think that will be very useful.

更新:我在Eclipse和 test.java 里面创建一个Java项目,我不断改变/编辑/添加在同一文件每当我需要写一个快速code和运行它。没办法真正拖放运行在Eclipse中。

Update: I created a Java project in Eclipse and a test.java inside that and I keep changing/editing/adding in the same file whenever I need to write a quick code and run it. No way to really drag-drop-run in Eclipse.

推荐答案

您不能编译和放大器;在Eclipse中运行只有一个文件,而无需在Java项目中的文件之中。

You can't compile & run just one file in Eclipse without the file being in a java project.

这是一个非常快速和容易的过程,在Eclipse中创建一个Java项目。

It is a very quick and easy process to create a Java Project in eclipse.

File -> New -> Java Project

您可以使用默认的包(虽然不推荐),并把你的单个文件中并运行它。

You can use the default package (though it is not recommended) and put your single file in it and run it.

这篇关于我如何运行主要有()在Eclipse中,而无需创建一个完整的Java项目的单一的Java文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆