0

I have an application what works properly when I run it from Netbeans, but doesn't work properly when I run it from the executable jar produced by the Netbeans "Clean and Build" command. In particular, I'm getting "java.lang.ClassNotFoundException" for classes that aren't the "Libraries" folder of my project (for example, com.sun.xml.internal.ws.spi.ProviderImpl, as well as various other classes in com.sun.xml).

I know that ClassNotFoundException is thrown when the given class isn't in the classpath of the application. I had started to manually add all of the various dependencies to the "[Project-Name]\dist\lib" folder created by Netbeans, but I feel like this is not the right way to go about doing this. Edit: This doesn't seem to work for all dependencies, with ClassNotFoundExceptions being thrown even if a jar with the relevant class is in "[Project-Name]\dist\lib".

I have no problem getting stuff listed in the "Libraries" folder into "[Project-Name]\dist\lib" folder.

I have noticed that the dependencies that are not listed in the "Libraries" folder are various Java EE components. Since this program is an application client that connects to a Java EE server, and this is my first Java EE project, my guess is that there is something basic about Java EE that I don't understand that has led to this issue.

I have two questions:

  1. How can Netbeans run my application when some of my application's dependencies are not in the "Libraries" folder?
  2. Is there any way of automatically exporting all of the dependencies not explicitly listed in the "Libraries" folder to "[Project-Name]\dist\lib"?

Also, my project is not a Maven project.

Logan Grier
  • 61
  • 1
  • 5
  • 1
    From memory, you need to tell maven what it should do with the dependencies, [for example](https://stackoverflow.com/questions/24899985/this-project-cannot-be-added-because-it-does-not-produce-a-jar-file-using-an-ant/24900260#24900260) and [example](https://stackoverflow.com/questions/24028921/in-maven-my-dependencies-are-set-up-but-i-get-a-classnotfoundexception-when-i-r/24030042#24030042) – MadProgrammer Dec 20 '17 at 00:14
  • What if my project does not use Maven? – Logan Grier Dec 20 '17 at 00:15
  • Oh, sorry, thought it was a Maven project for some reason - *"Is there any way of automatically exporting all of the dependencies not explicitly listed in the "Libraries" folder to "[Project-Name]\dist\lib""* - You can customise the Ant script used by the project to do this. A better solution might be to add the dependent `jar`s directly to your project – MadProgrammer Dec 20 '17 at 00:18
  • I kind of curious how you could would compile if the dependencies are within your projects class-path, which is generally controller by the `library` properties of the project – MadProgrammer Dec 20 '17 at 00:20
  • I'm also curious, which is why I asked question 1. My gut feeling is that there is something basic about Netbeans or Java EE applications that I'm missing (my application is a Java EE application client, and this is my first time putting together a Java EE project). – Logan Grier Dec 20 '17 at 00:30
  • Ahh, okay, outside my field of experience. Maybe the exported project needs to be executed within a JEE container, where it should automatically pick up the dependencies, at a guess – MadProgrammer Dec 20 '17 at 00:35

1 Answers1

0

If i understand correctly how Netbeans works, it "should" not add things to the classpath that are not listed in the Library folder. Netbeans in that regard is just a wrapper around the build-tool. Which in your case seems to be ant? At least if you create a standard "Java Application" from the wizard it is. So, when you hit "Clean Compile" you should see something like this in the consoloe/output:

ant -f /home/daniel/NetBeansProjects/MyApp -Dnb.internal.action.name=rebuild clean jar

This means he will use the build.xml in the root of you project. You will find a documentation in that file what targets exists. Also a run-target. So, you should be able to track down what parameters/classpath Netbeans sets to run your application. You can simply try to execute from a console as well and see if you can compile and run it here as well.

Additionally, I am confused that you get a classnotfoundexception for com.sun.xml.internal.ws.spi.ProviderImpl as this is part of the reference implementation of the JAX-WS client coming with the JDK. So, you should have this on the classpath by default. What Java version are you using Java 8 or maybe 9? Under the Libraries-section in Netbeans you should be able to see something like JDK 1.8. If you expand it and look into the rt.jar, you will/should find the class you mention.

https://docs.oracle.com/javase/8/docs/technotes/guides/xml/jax-ws/index.html

38leinad
  • 196
  • 2
  • 11