Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to determine which command Netbeans is executing to run the project?

I'm developing an Java application using Netbeans and Maven. I'm struggling a lot to run the project as standalone application. Launching the project from Netbeans is all fine but running the executable jar yields an error (failing to load a data file).

I need to know exactly which command(s) Netbeans is executing to run the application. However, the output window of Netbeans only shows me what the application writes "back". Is there a way to figure out/display the command(s) that Netbeans is using to run the project?

Thanks

EDIT: Running the java application and loading files is not the issue here. I'm able to run the application and the libraries are loading correctly. The issue here is to understand how Netbans runs the application (by looking at the commands that are executed).

like image 486
birgersp Avatar asked Mar 29 '17 12:03

birgersp


2 Answers

Netbeans outputs the command it invokes as the very first line of the output.

I use Netbeans 8.2 and that's how it looks like when I hit big green Run button in maven project:

Netbeans Output

The first line reads (formatted for better readablility):

cd D:\test;
"JAVA_HOME=C:\\Program Files\\Java\\jdk1.8.0_112" 
"M2_HOME=C:\\Program Files\\apache-maven-3.3.3"
cmd /c "\"\"C:\\Program Files\\apache-maven-3.3.3\\bin\\mvn.cmd\"
    -Dexec.args=\"-classpath %classpath com.test.AppStarter\"
    -Dexec.executable=\"C:\\Program Files\\Java\\jdk1.8.0_112\\bin\\java.exe\"
    -Dexec.workingdir=D:\\test\\target\\dist
    -Dmaven.ext.class.path=\"C:\\Program Files\\NetBeans 8.2\\java\\maven-nblib\\netbeans-eventspy.jar\"
    -Dfile.encoding=UTF-8
    org.codehaus.mojo:exec-maven-plugin:1.2.1:exec\""

From that line I can tell that Netbeans:

  • goes to the project's directory
  • sets environment variables (JAVA_HOME and M2_HOME)
  • then executes cmd that executes mvn (by its full path)
    • with bunch of -D arguments (which specify working directory and AppStarter as a class to execute)
    • and exec-maven- plugin with target exec.
like image 68
Oleg Kurbatov Avatar answered Nov 20 '22 02:11

Oleg Kurbatov


When NetBeans compiles a program it creates a folder-hierarchy with compiled .class files. When creating a JAR archive ZIPs those into the archive. When executing the program, (or debugging,) NetBeans runs the .class files off the folders, not in the JAR file.

These could cause different problems, like different PATH. This can cause "file not found" errors with relative paths.

like image 39
Usagi Miyamoto Avatar answered Nov 20 '22 00:11

Usagi Miyamoto