tags:

views:

51

answers:

2

I have no idea of how Netbeans IDE run a java file.

Firstly, it would ensure the .class file is up-to-date.

Then, execute the class. But from where (working directory) and with which command (parameter)?

I observe difference on how relative path is located when I run the java file from Netbeans IDE and when I run using Windows command prompt (i.e > java pack.age.name.ClassName)

+1  A: 

You can find that out by putting this at the start of the main method of the class:

System.out.println(new File(".").getAbsolutePath());

It looks like it will run from the directory that the project is in (eg. ....\NetBeansProjects\JavaApplication1)

You cannot specify command line arguments for a single class (that I am aware of). To do that you have to use the Project | Properties (and there you can also set the working directory).

I would suggest that you do not write code that depends on the working directory if you can avoid it though...

TofuBeer
A: 

You can get informative results by running the project's build.xml from the from the command line in verbose mode: ant -verbose run. Look for the [java] command options under run:. Typing ant -p will show you the available targets.

trashgod