I have a problem executing my java sample "hello world" program outside Eclipse while Eclipse can execute it whenever I push the Run menu button. So I want to know the command line Eclipse uses to execute the java program.
-
try "java helloworld" in your console where helloworld is your compiled class file ? – Jasonw Feb 28 '12 at 06:43
-
1To run your class having main method(...), which is a part of a package. You run it on command prompt like this `java packagename.subpackagenameifany.NameOfTheClassHavingTheMainMethod` Press Enter after writing that. – nIcE cOw Feb 28 '12 at 14:07
3 Answers
You can check the other parameters arguments, classpath, environment variables etc. that eclipse might be using to compile your program, from the Run Configurations window, which appears as a dropdown when you click the drop-down button next to the Run button in eclipse.
To get the full command line, you can open the Debug view from Window>Show View>Other.... Right click on the last launch and go to properties. Eclipse will list the exact command line.
- 5,783
- 15
- 70
- 117
- 2,165
- 3
- 23
- 32
-
2Your edit is a great answer, thank you! Gives me all the details of classpath and system props set in cmd line. – medloh Apr 03 '14 at 18:17
As of 2019 (version 4.13.0):
Eclipse > Run > Run Configurations
There is a "Show Command Line" button that shows the full command Eclipse uses:
- 91
- 1
- 2
The thing is Eclipse uses (by default) different directories for source and object files. If you want to execute a particular java file from the command line, you can either compile it by going inside your workspace directory/src directory and hit javac <MyClass>.java and then do java MyClass.
Or since it works in eclipse, you can go inside the 'bin' directory inside your workspace and do a java MyClass which will execute your pre compiled class.
- 4,288
- 2
- 25
- 37
