9

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).

birgersp
  • 3,909
  • 8
  • 39
  • 79
  • did you create a single jar that contains all data, manifest with which gives Main class using Maven?. [how to create single jar?](http://stackoverflow.com/a/574650/7584363). – Avinash L Mar 29 '17 at 12:14
  • I did, running a Maven application outside Netbeans is not the issue here. The issue is that I get some error when trying to load a file. However, when I run the application from Netbeans I don't get this error. So i need to figure out **exactly** what commands Netbeans is executing to run the project. – birgersp Mar 29 '17 at 12:32
  • 1
    NetBeans **will** include the Maven command line that it is using in the "Output" window. It's the very first line. But running the generated jar file from the command line will require a completely different command as that is usually not done through maven. Typically that will be something like `java -cp ..... your.main.Class` or (if you provided a manifest) just a `java -jar your.jar` –  Apr 03 '17 at 07:45
  • 1
    Try setting the ["Verbosity" to "Verbose" under Tools > Options > Ant](http://stackoverflow.com/questions/2619046/view-execution-line-in-netbeans). – heenenee Apr 04 '17 at 03:50

3 Answers3

4

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.
Oleg Kurbatov
  • 1,376
  • 1
  • 19
  • 32
2

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.

Usagi Miyamoto
  • 6,196
  • 1
  • 19
  • 33
0

what is your operatingsystem?

windows: then wmic may be the tool, which could show you the complete commandline. you will find examples here command line of process by name

linux: try ps -ef | grep java

Community
  • 1
  • 1