Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Eclipse won't compile/run java file

Tags:

I am just trying to compile and run a simple java program. When I go to run my tester class it says select what to run and it gives me Ant Build which when highlighted says "Launches an Ant build with default settings" or Ant Build... that says "Launches an Ant build and allows it to be configured". When I try to select either of these it prompts Build failed. Reason: Unable to find ant file to run. I honestly don't know what these ant builds and files are. This is definitely a dumb question but have no idea what to do.

enter image description here

like image 762
Jess Anastasio Avatar asked Jan 11 '14 22:01

Jess Anastasio


People also ask

Why is Eclipse not running my code?

If you've installed Eclipse but are having trouble getting it to run, the most likely cause is that you have not correctly specified the JVM for it to run under. Eclipse startup is controlled by the options in $ECLIPSE_HOME/eclipse. ini. If $ECLIPSE_HOME is not defined, the default eclipse.

How do I force Eclipse to recompile?

For Eclipse you can find the rebuild option under Project > Clean and then select the project you want to clean up... that's all.

How do I compile a single Java file in Eclipse?

Your class has to define a public static void main(String[] args) method. Then find the Java file in the project explorer, right-click on it, and choose "run as Java application". The file name has to be the same (+ extension ".


1 Answers

  • Make a project to put the files in.
    • File -> New -> Java Project
    • Make note of where that project was created (where your "workspace" is)
  • Move your java files into the src folder which is immediately inside the project's folder.
    • Find the project INSIDE Eclipse's Package Explorer (Window -> Show View -> Package Explorer)
    • Double-click on the project, then double-click on the 'src' folder, and finally double-click on one of the java files inside the 'src' folder (they should look familiar!)
  • Now you can run the files as expected.

Note the hollow 'J' in the image. That indicates that the file is not part of a project.

Hollow J means it is not part of a project

like image 88
calvin Avatar answered Sep 29 '22 08:09

calvin