-3

I have a Maven project with certain set of dependencies. One of the dependencies is:

<dependency>
    <groupId>net.java.dev.jna</groupId>
    <artifactId>jna</artifactId>
    <version>4.5.0</version>
</dependency>

As long as I work in Eclipse, all is good. But when I package and try to use the resulting jar file(from command line if that matters), I get this error message:

Exception in thread "main" java.lang.NoClassDefFoundError: com/sun/jna/NativeLibrary

while this class is definitely accessible in IDE.

My guess is that Maven is not packaging project's dependencies by default but in that case why don't I get more error messages complaining about more classes that were not found?

Eugene S
  • 6,709
  • 8
  • 57
  • 91

1 Answers1

1

Maven will only create a jar for your project/component. This does not include the external jars (dependencies). If you want/need to include the contents of the dependencies in your jar, you should create a fat jar or uber jar. For an uber jar, you may use shade plugin.

Luiggi Mendoza
  • 85,076
  • 16
  • 154
  • 332