Basic SslPlugin question about getting ClassNotFoundException: nl.altindag.ssl.exception.GenericSecurityException
scjwong opened this issue · 5 comments
Hi, this is probably a basic/dummy question but figured someone can point me to the right direction. Thanks in advance.
I'm migrating my Javalin 3.x project to Javalin 6.0 and trying out the SslPlugin to replace SSL code used in Javalin 3.x ( SslContextFactory...etc). When this app runs, I am getting ClassNotFoundException: nl.altindag.ssl.exception.GenericSecurityException at the new SslPlugin line.
I have a very minimal setup (using OpenJDK 21):
public static void main(String[] args) {
SslPlugin plugin = new SslPlugin(conf -> {
conf.pemFromPath("/keystore/cert.pem", "/keystore/key.pem");
conf.securePort = 7070;
});
var app = Javalin.create(config -> {
config.registerPlugin(plugin);
config.staticFiles.add("src/main/resources/public", Location.EXTERNAL);
config.router.mount(router -> {
router.ws("/api/abc", CadetPairing::websocket);
});
})
.start(7070);
}
===========
Exception in thread "main" java.lang.NoClassDefFoundError: nl/altindag/ssl/exception/GenericSecurityException
at java.base/java.lang.ClassLoader.defineClass1(Native Method)
at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1027)
at java.base/java.security.SecureClassLoader.defineClass(SecureClassLoader.java:150)
at java.base/jdk.internal.loader.BuiltinClassLoader.defineClass(BuiltinClassLoader.java:862)
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:526)
at java.base/java.lang.ClassLoader.defineClass1(Native Method)
at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1027)
at java.base/java.security.SecureClassLoader.defineClass(SecureClassLoader.java:150)
at java.base/jdk.internal.loader.BuiltinClassLoader.defineClass(BuiltinClassLoader.java:862)
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:526)
at io.javalin.community.ssl.SslConfig.pemFromPath(SslConfig.kt:141)
at io.javalin.community.ssl.SslConfig.pemFromPath$default(SslConfig.kt:136)
at io.javalin.community.ssl.SslConfig.pemFromPath(SslConfig.kt)
at com.example.Application.lambda$main$0(Application.java:22)
at io.javalin.plugin.Plugin.(PluginApi.kt:52)
at io.javalin.community.ssl.SslPlugin.(SslPlugin.kt:24)
at com.example.Application.main(Application.java:20)
Caused by: java.lang.ClassNotFoundException: nl.altindag.ssl.exception.GenericSecurityException
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:526)
... 25 more
Hi! Are you shading your JAR in some way?
No...
here's the section of my pom.xml:
<build>
<finalName>server</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.10.1</version>
<configuration>
<source>21</source>
<target>21</target>
<release>21</release>
<annotationProcessorPaths>
<annotationProcessorPath>
<groupId>io.javalin.community.openapi</groupId>
<artifactId>openapi-annotation-processor</artifactId>
<version>${javalin.version}</version>
</annotationProcessorPath>
</annotationProcessorPaths>
</configuration>
</plugin>
<!-- create executable jar -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.2.0</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>com.example.Application</mainClass>
<classpathPrefix>lib/</classpathPrefix>
</manifest>
</archive>
</configuration>
</plugin>
<!-- copy dependencies / jars to ${project.build.directory}/lib/ -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.1.2</version>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>
${project.build.directory}/lib/
</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.3.0</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
<configuration>
<finalName>server-fat</finalName>
<appendAssemblyId>false</appendAssemblyId>
<descriptorRefs>
<!-- This tells Maven to include all dependencies -->
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<mainClass>com.example.Application</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
I noticed I can get rid of the GenericSecurityException by including this dependency, but would still get GenericIOException:
<dependency>
<groupId>io.github.hakky54</groupId>
<artifactId>sslcontext-kickstart</artifactId>
<version>8.3.1</version>
</dependency>
============Exception in thread "main" java.lang.NoClassDefFoundError: nl/altindag/ssl/exception/GenericIOException
at io.javalin.community.ssl.SslConfig.pemFromPath(SslConfig.kt:141)
at io.javalin.community.ssl.SslConfig.pemFromPath$default(SslConfig.kt:136)
at io.javalin.community.ssl.SslConfig.pemFromPath(SslConfig.kt)
at com.example.Application.lambda$main$0(Application.java:22)
at io.javalin.plugin.Plugin.(PluginApi.kt:52)
at io.javalin.community.ssl.SslPlugin.(SslPlugin.kt:24)
at com.example.Application.main(Application.java:20)
Caused by: java.lang.ClassNotFoundException: nl.altindag.ssl.exception.GenericIOException
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:526)
... 7 more
I can tell you it does have something to do with those plugins for creating the Jar. When copying the dependencies into the jar you must be missing some classes.
Shadowing/bundling jars always comes with these kinds of problems, unfortunately I can't help you more on my side, since it's not a problem of the library but of the packaging.
If you try running the application directly from maven or the IDE it will most likely work.
Those classes are part of a dependency of the plugin, and are included during build and run time.
Good luck! If you manage to figure this out I would appreciate it if you could mention how you did on the pinned issue I have on shadowing.
will do, thanks!