I am trying to develop a plugin for IntelliJ Idea community edition, I am creating the plugin project like shown Creating Plugin Project
I am using Java to develop the plugin and gradle as my build tool, I was able to develop and deploy the plugin successfully.I used Java Swing library to develop the UI part, now I want to use JetBrains libraries like com.intellij.ui.*, icons & etc.
When I try to use the JB libraries I am getting NoClassDefFoundError.
Exception in thread "main"
Exception in thread "main" java.lang.NoClassDefFoundError: com/intellij/ui/components/JBLabel
at Test.main(Test.java:8)
Caused by: java.lang.ClassNotFoundException: com.intellij.ui.components.JBLabel
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:525)
... 1 more
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':Test.main()'.
> Process 'command '/home/dharun/.jdks/jbr-17.0.11/bin/java'' finished with non-zero exit value 1
I guess that this is caused due to there is no class or libraries found during runtime, but I am able to use the JB libraries at compile time most of the UI components are available to use and code with it. but I am getting error while running/execution. Using JB Library in compile time
I have tried configuring different JDKs for the project and checked my dependecies as well when I am able to use the JetBrains libaries in compile time but at runtime throws exception
If I use main method to execute I am able to create new JLabel() of swing library but the same does not apply for new JBLabel() of jetbrains library
The reason why java swing library worked when executed using main method was the classes were available at the time of class loading and execution as well. The reason why jetbrains library was not working when executed using main method was the classes were not available.
usually when a plugin is developed runIde task from the gradle is used to deploy the plugin locally which creates a new IDE instance and loads the plugin for that instance, this loads all the classes, libraries used for the plugin.
So the JetBrains library which was not available when the program was executed using main method, will be available and gets loaded when runIde task is used which creates a new IDE instance, for this instance all the JetBrains UI components which was used to develop the plugin will be loaded and be visible as designed.
To sum it up when I use runIde task the JB libraries are working, if the same is done from a main method and that throws an error