-4

I have two maven projects targeting java 10:

project structure

Project A depends on project B:

build path for A

build path for A - order

I've created run configuration for project A, which works as expected. Now, I want to create runnable jar from this run configuration,

runnable jar config

... but .jar file doesn't contain .class file from project B:

.jar content

So when I try to run this .jar it throws:

Exception in thread "main" java.lang.NoClassDefFoundError: b/B
    at a.A.main(A.java:7)
Caused by: java.lang.ClassNotFoundException: b.B
    at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(Unknown Source)
    at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(Unknown Source)
    at java.base/java.lang.ClassLoader.loadClass(Unknown Source)
    ... 1 more

How can I fix this? I've tested it on freshly dowloaded Eclipse Photon (4.8.0)

T A
  • 1,677
  • 4
  • 21
  • 29
kolar
  • 1,010
  • 1
  • 9
  • 21
  • 2
    As you are working with maven projects you should look into the [maven assembly plugin](http://maven.apache.org/plugins/maven-assembly-plugin/). You can automatically build a jar packaged with all it's dependencies using maven. – T A Sep 05 '18 at 11:39
  • @TA I know I can use maven, but here I'm asking about eclipse export. – kolar Sep 05 '18 at 11:45
  • https://stackoverflow.com/questions/11033603/how-to-create-a-jar-with-external-libraries-included-in-eclipse – efex09 Sep 05 '18 at 11:53

1 Answers1

0

Ok, I've found an answer. I have to add also dependent project (B) to maven dependencies:

<dependencies>
  <dependency>
    <groupId>B</groupId>
    <artifactId>B</artifactId>
    <version>0.0.1-SNAPSHOT</version>
  </dependency>
</dependencies>

As I beleive it wasn't required in previous Eclipse versions.

kolar
  • 1,010
  • 1
  • 9
  • 21
  • 1
    I doubt this has anything to do with the Eclipse version. – T A Sep 05 '18 at 12:11
  • I've exported runnable jar for the same project multiple times in the past using Eclipse Oxygen and Java 8. The problems have appeared after upgrading java to 10 and Eclipse to Photon, maybe Eclipse handles java 10 differently (due to new module system etc). – kolar Sep 05 '18 at 12:21