Reputation: 23
so i am currently creating an OPC UA client project in java. The only / best open source up to date library i have found is Eclipse Milo. Im importing it using maven at org.eclipse.milo:skd-client:0.6.8 . I need the final project to be a runnable jar. When running the project in InteliJ i get no compile errors but after compiling into a jar i get the exception:
error: a jni error has occurred, please check your installation and
try again exception in thread "main" java.lang.securityexception:
invalid signature file digest for manifest main attributes at java.base/sun.security.util.signaturefileverifier.processimpl(signaturefileverifier.java:339) at
java.base/sun.security.util.signaturefileverifier.process(signaturefileverifier.java:281) at
java.base/java.util.jar.jarverifier.processentry(jarverifier.java:320) at java.base/java.util.jar.jarverifier.update(jarverifier.java:232) at
java.base/java.util.jar.jarfile.initializeverifier(jarfile.java:760) at
java.base/java.util.jar.jarfile.getinputstream(jarfile.java:858) at java.base/jdk.internal.loader.urlclasspath$jarloader$2.getinputstream(urlclasspath.java:837) at
java.base/jdk.internal.loader.resource.cachedinputstream(resource.java:77) at
java.base/jdk.internal.loader.resource.getbytebuffer(resource.java:163) at java.base/jdk.internal.loader.builtinclassloader.defineclass(builtinclassloader.java:853) at
java.base/jdk.internal.loader.builtinclassloader.findclassonclasspathornull(builtinclassloader.java:760) at
java.base/jdk.internal.loader.builtinclassloader.loadclassornull(builtinclassloader.java:681) at
java.base/jdk.internal.loader.builtinclassloader.loadclass(builtinclassloader.java:639) at
java.base/jdk.internal.loader.classloaders$appclassloader.loadclass(classloaders.java:188) at
java.base/java.lang.classloader.loadclass(classloader.java:528) at java.base/java.lang.class.forname0(native method) at java.base/java.lang.class.forname(class.java:578) at
java.base/java.lang.class.forname(class.java:557) at java.base/sun.launcher.launcherhelper.loadmainclass(launcherhelper.java:847) at
java.base/sun.launcher.launcherhelper.checkandloadmain(launcherhelper.java:732)
however weirdly enough that exception has recently changed to:
Error: Could not find or load main class Main
Caused by: java.lang.ClassNotFoundException: Main
no idea why it changed but the culprit seems the be the same. After doing some research it seems the culprit is eclipse milos library including 'signed jars'. A solution i found was running: zip -d file.jar 'META-INF/.SF' 'META-INF/.RSA' in command prompt which removes any signed jars and after that the jar will launch correctly without either of the above exceptions. However it turns out i need these signed jars as other aspects of the project dont work correctly without them.
Does anyone know how i can resolve this or why the exception has recently changed to class not found? As mentioned i NEED these signed libraries and i NEED an executable jar.
ALSO im pretty dang sure i have my jar configured correctly. I recreated the artifact selecting my Main class as the Main class. I also checked the Manifest and the correct name is there as well... removing the library or signed jars and doing nothing else will stop the main class not found exception...
Upvotes: 1
Views: 41
Reputation: 628
If i were you i would use the maven shaded plugin and try the following :
1- Exclude the jars you don't want which cause exceptions in your main jar using plugins :
<project>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.4</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<filters>
<!-- Filter out the signature files which cause SecurityException -->
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
</excludes>
</filter>
</filters>
<!-- Configure your main class -->
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>your.package.MainClass</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
2- Run mvn clean package
to have the jar build, and check if it works as expected.
Upvotes: 0