ClassNotFoundException when Using Tyrus and Grizzly with PyCharm Plugin

Answered

Hi everyone,

I'm working on a PyCharm plugin where I'm trying to use Tyrus and Grizzly for WebSockets. The dependencies seem to resolve correctly, and they are included in the `build/distributions` folder within the zip archive. Here are the relevant parts of my setup:

Dependencies in build.gradle.kts:
implementation("jakarta.websocket:jakarta.websocket-api:2.2.0")
// https://mvnrepository.com/artifact/jakarta.servlet/jakarta.servlet-api
implementation("jakarta.servlet:jakarta.servlet-api:6.1.0")
// https://mvnrepository.com/artifact/org.glassfish.tyrus/tyrus-server
implementation("org.glassfish.tyrus:tyrus-server:2.1.5")
// https://mvnrepository.com/artifact/org.glassfish.tyrus/tyrus-container-grizzly-server
implementation("org.glassfish.tyrus:tyrus-container-grizzly-server:2.1.5")

Despite these dependencies being correctly included, I encounter a `ClassNotFoundException` when running the `runIde` task:
java.lang.RuntimeException: java.lang.ClassNotFoundException: org.glassfish.tyrus.container.grizzly.server.GrizzlyServerContainer
    at org.glassfish.tyrus.spi.ServerContainerFactory.createServerContainer(ServerContainerFactory.java:62)
    at org.glassfish.tyrus.server.Server.start(Server.java:199)

I also tried to install the plugin manually via zip-archive.

libs.versions.toml:
# plugins
kotlin = "2.0.0"
changelog = "2.2.0"
gradleIntelliJPlugin = "1.17.4"
qodana = "2024.1.5"
kover = "0.8.2"
 

gradle.properties:
pluginSinceBuild = 223
pluginUntilBuild = 241.*

# IntelliJ Platform Properties
platformType = PC
platformVersion = 2022.3.3

# Plugin Dependencies
platformPlugins = python-ce

# Gradle Releases
gradleVersion = 8.8
 

Environment Details:

IntelliJ IDEA 2024.1 (Ultimate Edition)
Build #IU-241.14494.240, built on March 28, 2024

Runtime version: 17.0.10+8-b1207.12 aarch64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.
macOS 14.5
GC: G1 Young Generation, G1 Old Generation
Memory: 2048M
Cores: 10
Metal Rendering is ON
Registry:
 ide.experimental.ui=true
Non-Bundled Plugins:
 com.jetbrains.space (241.14494.150)
 Pythonid (241.14494.314)
 DevKit (241.14494.247)
 com.intellij.ml.llm (241.14494.320)
Kotlin: 241.14494.240-IJ

Has anyone encountered a similar issue or can provide any insight on how to resolve this ClassNotFoundException? Any help or pointers would be greatly appreciated! Maybe I have a fundamental misunderstanding of the IntelliJ Dependency Management as I am new to Plugin Development. I read the docs but couldn't resolve my problem.

Thanks in advance!

0
6 comments

Hi Julian,

Could you please make sure the class is actually in one of the JARs? On the internet I can see similar issues with exactly the same class, and it seems to be a dependency problem.

0

Hi Karol Lewandowski,

in which jar it should actually be? I see the “missing” library inside the .zip-archive in the build/distributions folder. But I don't find any external library inside one of my Plugin jar-Files.

Thanks for your help!

0

Hi Julian,

I don't know in which library JAR it should be (not a plugin JAR). I don't know this library and class. The error says that class cannot be found, and I don't see any issues in your configuration, so the first step is to ensure the class is actually delivered in your plugin distribution. Please make sure that the class is contained by one of the library JARs.

0

Hi Karol Lewandowski,

the following jar-File are inside the .zip-archive in the build/distributions folder. (For the picture, i unzipped it → build/distributions/$PLUGIN-NAME$/lib → )

The missing class is in tyrus-container-grizzly-server-2.1.5.jar which is inside the zip-archive. I also unzipped this jar-file and found the class inside.

Any ideas?

Best regards

Julian

0

Thanks for checking.

Looking at the implementation:
https://github.com/eclipse-ee4j/tyrus/blob/master/spi/src/main/java/org/glassfish/tyrus/spi/ServerContainerFactory.java#L47-L70

it seems that ServiceLoader is used. Please try to set context class loader to the plugin's class loader as described in the documentation:
https://plugins.jetbrains.com/docs/intellij/plugin-class-loaders.html#using-serviceloader

0

Dear Karol Lewandowski,

that was the issue, thanks! :-) 

Best regards,

Julian

0

Please sign in to leave a comment.