1

I try to resolve issue, which I've posted in this topic

with this solution

I try to create a shaded-jar with 'shaded-plugin' from Maven. But I've stuck with problem to load this shaded jar to another project. This 'jar' is a non-executable library for using somewere... I simply add this jar to the external libraries in separate project(using IDEA) and everything looks fine until I run the application.

It throws 'ClassNotFoundException: Test' (Test - is my only one class in this project and it has main method). I want to mention, that when I use 'assembly plugin' and make jar-with-dependencies everything works fine, without any exceptions.

What have I missed?

Full stacktrace:

Exception in thread "main" java.lang.ClassNotFoundException: Test
    at java.net.URLClassLoader$1.run(URLClassLoader.java:372)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:360)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:259)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:116)
Cœur
  • 37,241
  • 25
  • 195
  • 267
maret
  • 1,826
  • 1
  • 13
  • 18
  • how do you include the shaded jar in your build? Neo4j has standard (non-shaded) jar in maven central. Generally, I'd really avoid using the shaded plugin if the jar-with-dependencies jar target works for you. – Nikola Yovchev Oct 14 '14 at 13:49
  • jar-with-dependencies don't works correct. In separate project which use this jar 'web-interface' of db don't work at all (because of rewriting META-INF/service files-I have couple of neo4j component in maven dependencies), but non-web functions works. I use shaded plugin to concatenate implementations in META-INF/service. But it is possible this cause a mess and my project crush... – maret Oct 14 '14 at 14:08

2 Answers2

1

I think I have faced your problem before. I even wrote a blog post about it:

https://ath3nd.wordpress.com/2013/12/25/packaging-a-multimodule-maven-spring-app-in-a-standalone-jar/

Basically, the shaded-jar plugin rewrote so much and concatenated so much that classpaths and files that were spring-related or manifests all went into a huge blackbox and I ended up with a shaded jar which from time to time threw ClassNotFound exception. That is why I used the suggestion of this guy:

Invalid or corrupt JAR File built by Maven shade plugin

And used a combination of 3 plugins-> maven dependency plugin, maven jar plugin and maven assembly plugin. With the combination of those three you can achieve the same thing you can achieve with shade plugin, but with less magic happening behind the scenes, or at least it was easier to me to comprehend what was happening. You can try using those, or you can post part of your config so we can help you further.

Working with ClassLoaders in Java, unfortunately, is a fairly nasty and unpleasant business, so I wish you good luck anyway.

Community
  • 1
  • 1
Nikola Yovchev
  • 9,498
  • 4
  • 46
  • 72
1

Thanks you all!

I've resolved my issue. In my case - everithyng works fine, when I add this lines to the 'shade-plugin' configuration in the 'pom' file:

...
<configuration>
     ...
        <filters>
           <filter>
               <artifact>*:*</artifact>
                    <excludes>
                         <exclude>META-INF/*.SF</exclude>
                         <exclude>META-INF/*.DSA</exclude>
                         <exclude>META-INF/*.RSA</exclude>
                    </excludes>
           </filter>
        </filters>
...
</configuration>
...
maret
  • 1,826
  • 1
  • 13
  • 18