有没有办法在不编译的情况下运行短代的Java代码? [英] Is there a way to run short bits of Java code without compiling?

查看:166
本文介绍了有没有办法在不编译的情况下运行短代的Java代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法运行或模拟运行Java语句(有点像IDLE - Python GUI)而无需编译和运行可执行文件?我想快速测试语句,看看它们是否有效。谢谢。

解决方案

是的,你可以使用Eclipse,创建一个项目,并创建一个


剪贴簿页面从包含项目的构建
路径获取其类路径
。如果在剪贴簿页面中你想要
来引用一个
的Java元素,而不是在包含Java项目的
的构建路径上,你需要
添加到Java项目的构建中路径。
剪贴簿页面还允许你
指定import语句。你可以通过从剪贴簿页面的
上下文菜单中选择Set Imports或者从工具栏中选择
设置导入声明来运行
代码来执行
。您需要设置
import语句,以便在项目中引用
Java声明。
这是一种常见的疏忽。如果您尝试
导入的
类型或包未列在Add
对话框中,则表​​示您需要将其添加到
项目的构建路径
包含剪贴簿页面。如果
引用了一个具有
多个声明的元素,则需要
将import语句添加到唯一的
标识元素。


编辑:得到另一个解决方案: http://ideone.com 。这是一个在线IDE和调试工具。您可以在此处查看示例: http://ideone.com/98sA8 ,但看起来您必须设置比剪贴簿页面多一点。


Is there a way to run or simulate running Java statements (kind of like IDLE - the Python GUI) without compiling and running the executable? I want to quickly test statements to see if they work. Thanks.

解决方案

Yep, you can use Eclipse, create a single project, and create a Scrapbook Page in that project.

You can also specify import statements: http://www.informit.com/articles/article.aspx?p=31789&seqNum=3

Scrapbook pages get their classpath from the containing project's build path. If in a scrapbook page you want to reference a Java element that is not on the build path of the containing Java project, you need to add to the Java project's build path. Scrapbook pages also allow you to specify import statements. You do this by selecting Set Imports from the context menu of a scrapbook page or Set Import Declarations for Running Code from the toolbar. You need to set import statements for references to Java declarations in your projects. This is a common oversight. If the type or package you are attempting to import is not listed in the Add dialog, it means you need to add it to the build path of the project containing the scrapbook page. If you are referencing an element that has multiple declarations, you will need to add an import statement to uniquely identify the element.

Edit: Got another solution too: http://ideone.com. It's an online IDE and debugging tool. You can see an example here: http://ideone.com/98sA8, but it looks like you have to set up a bit more than on a scrapbook page.

这篇关于有没有办法在不编译的情况下运行短代的Java代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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