0

I have found posts in here where people show how to make a single runnable jar with their dependency jars included. But when I tried doing this I am getting signed jar errors. How can I get this to work with the bouncy castle?

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <version>3.1.0</version>
            <configuration>
                <archive>
                    <manifest>
                        <addClasspath>true</addClasspath>
                        <mainClass>${one-jar-main-class}</mainClass>
                    </manifest>
                </archive>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-assembly-plugin</artifactId>
            <version>2.4.1</version>
            <executions>
                <execution>
                    <goals>
                        <goal>attached</goal>
                    </goals>
                    <phase>package</phase>
                    <configuration>
                        <descriptorRefs>
                            <descriptorRef>jar-with-dependencies</descriptorRef>
                        </descriptorRefs>
                        <archive>
                            <manifest>
                                <mainClass>${one-jar-main-class}</mainClass>
                            </manifest>
                        </archive>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
    </build>

My second attempt I did this, but now I get this error.

Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.NoClassDefFoundError: com/netsuite/webservices/platform_2017_1/NetSuiteServiceLocator
    at java.lang.Class.getDeclaredMethods0(Native Method)
    at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
    at java.lang.Class.privateGetMethodRecursive(Class.java:3048)
    at java.lang.Class.getMethod0(Class.java:3018)
    at java.lang.Class.getMethod(Class.java:1784)
    at sun.launcher.LauncherHelper.validateMainClass(LauncherHelper.java:544)
    at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:526)
Caused by: java.lang.ClassNotFoundException: com.netsuite.webservices.platform_2017_1.NetSuiteServiceLocator
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 7 more

Current Build Set up

            <plugin>
                <artifactId>maven-dependency-plugin</artifactId>
                    <executions>
                        <execution>
                            <phase>process-sources</phase>

                            <goals>
                                <goal>copy-dependencies</goal>
                            </goals>

                            <configuration>
                            <outputDirectory>${project.build.outputDirectory}/lib</outputDirectory>
                              <!--   <outputDirectory>${project.build.directory}/dependency</outputDirectory>-->

                            </configuration>
                        </execution>
                    </executions>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>3.0.2</version>
                <configuration>
                <archive>
                    <manifest>
                    <classpathPrefix>lib/</classpathPrefix>
                    <mainClass>${one-jar-main-class}</mainClass>
                        <addClasspath>true</addClasspath>
                    </manifest>
                </archive>
                </configuration>
            </plugin>
ucMedia
  • 4,105
  • 4
  • 38
  • 46
pitchblack408
  • 2,913
  • 4
  • 36
  • 54
  • you can not preserve the integrity of the signed jar's signature if you repack them. Your only way is to reference them using the manifest of the main jar: https://docs.oracle.com/javase/tutorial/deployment/jar/downman.html – spi Aug 30 '18 at 08:59
  • 1
    Easiest way will be to use spring boot. You can also filter out signature files. – talex Aug 30 '18 at 09:30
  • If I use eclipse export, it makes a single jar that works. There is no way to do that with maven? – pitchblack408 Aug 30 '18 at 09:46
  • @pitchblack408 maybe if you (somehow) exclude the signature related files (*.DSA and *.SF), but you lose the security of a signed jar file – spi Aug 30 '18 at 10:54
  • I tried excluding them and then bouncy castle throws another error about the signature missing – pitchblack408 Aug 30 '18 at 10:55
  • maybe you need to rewrite the manifest, too. it contains lots of sha1 digests for every class – spi Aug 30 '18 at 10:56
  • How do I get maven to not compile the jars? Like put the dependencies in a outside folder and then in the next step create the runable jar that includes the dependency jars and the class path in the manifest – pitchblack408 Aug 30 '18 at 10:57
  • I don't know how to rewrite the manifest like you suggested – pitchblack408 Aug 30 '18 at 10:58
  • with maven it could be quite difficult, but you can try some suggestions from here: https://stackoverflow.com/questions/7757083/how-do-i-unsign-a-jar however, I wouldn't recommend doing so unless you have a very good reason - referencing the jar in the main jar's manifest's class-path should do the job, and you don't lose the signature – spi Aug 30 '18 at 11:03
  • to copy the jars in a folder you can use the goal copy-dependencies of the maven-dependency-plugin: https://maven.apache.org/plugins/maven-dependency-plugin/copy-dependencies-mojo.html, then you need to instruct the maven-jar-plugin to append the classpath directive in the manifest of the main jar, referencing the correct path of your dependencies: https://maven.apache.org/shared/maven-archiver/examples/classpath.html#Add – spi Aug 30 '18 at 11:05
  • @spi, I am trying to copy the jars and then create the jar. But now I am getting some other error. I pasted it above – pitchblack408 Aug 30 '18 at 12:21
  • @pitchblack408 there is most likely an issue with your manifest, please look carefully that all paths correspond to an existing file – spi Aug 30 '18 at 13:00
  • Hi I would use [JarClassLoader](http://www.jdotsoft.com/JarClassLoader.php), so I would build a jar which contains the dependencies as is, without any modification (my first suggestion would have been to write a custom classloader after that, but fortunately the guys at JDotSoft did the heavy lifting for you. There are some limitations (you have to have a temp folder), but works. – m4gic Aug 30 '18 at 16:15
  • How were you able to solve this issue @pitchblack408 – Talha Akbar Jun 10 '23 at 23:42
  • @TalhaAkbar, I don't remember, but if there is no answer here, then I most likely wasn't able to do it. I must have came up with something else that wasn't related to get the job done. Or maybe I just used the jar that was created by eclipse. – pitchblack408 Jul 25 '23 at 17:18

0 Answers0