How do I run an arbitrary java file with Eclipse?
I need to run some example java code. I like using eclipse because it shows the methods, properties, constructors and so on. The problem I'd like to solve is that unless I create a new project I can't compile and run the example code I'm using! I开发者_StackOverflow中文版s there a way around this?
No, there is no way around this. A Java file is very rarely a self-contained program with no dependencies at all. Most of the time, a program is composed of many collaborating classes depending on external libraries.
If you just want to test a self-contained Java program consisting of just one java file, then create a "playground" eclipse project, drop this file inside this project, and run it. Use the same playground project for all the other self-contained java programs if you want: you may have several main classes inside a single eclipse project.
精彩评论