Plugin Classpath needed for launching new Java Process with Plugin Classpath for use in RunAsConfiguration
Planned
I am trying to create a new RunAsConfiguration plugin, as part of its creation I do understand that we need to launch a new process.
I am trying to launch a new Java Process that executes a class present in my plugin. I am trying to determine the following:
- SDK to use: Ideally I want to use the SDK with which the plugin is running, but I cannot seem to find how to get that, I have currently used
ProjectRootManager.getInstance(env.getProject).getProjectSdk
- Classpath to use: I wanted to use the classpath that the plugin is running with. In my search on how to determine the class path I was able to do the following for the plugin classpath, but I am missing how to determine the remaining classpath e.g. slf4j that is bundled by Intellij Idea
val libPath = PathUtil.getParentPath(PathUtil.getJarPathForClass(this.getClass))
params.getClassPath.add(s"$libPath/*")
Any suggestions is much appreciated:
- How to determine the platform sdk?
- How to get the complete classpath that the plugin is running with towards use in a new JavaCommandLineState
Please sign in to leave a comment.
The plugin executes in the scope of the current IDE. What kind of functionality do you want to execute specifically? And why would it need to access classes from IJ Platform SDK, when it's actually run as separate process?
Yann Cebron
Thanks for following up.
The plugin tries to launch a new process that executes commands on a K8s cluster using the K8s APIs. Towards this I have the following:
1. For the SDK to launch a new Java Process, I was thinking that I should be using the Platform SDK instead of the Project SDK as there is no dependency with the Project SDK for the Plugin. Hope this explains why I need the Platform SDK.
2. When I create the plugin I have not bundled Jars provided by Intellij e.g. log4j, when I launch the new process I still need to provide these dependencies that is why I need access to the platform libraries available to supply to the new Java Process.
Hope that gives you some context. I am happy to elaborate further as needed.
Sorry for delay
I still don't quite understand why the class executed needs/uses the IntelliJ Platform SDK. What exactly does it do?
The plugin needs to launch a Java Process, this would need an SDK.
The choices I see here are:
* Platform SDK
* Project SDK
* Configured SDK for plugin
I was thinking that I am able to use the Platform SDK to launch the Java Process as I don't have any other specific requirements. You might be indicating that I should not be using the Platform SDK and look at either the Project SDK or a custom SDK configured for the plugin.
Yes. I don't quite understand why getting Project SDK does not work for you (https://plugins.jetbrains.com/docs/intellij/sdk.html).
Thanks Yann Cebron that clears it up. I was thinking that the preferred option should be to use the Platform SDK as compared to the project SDK.
Any thoughts on the classpath for the execution of the JavaProcess? Here ideally what I would like is the classpath of the plugin as the classpath of the new Java Process.
The snippet from initial post for building classpath LGTM
Thanks Yann Cebron that answers all my questions. Your guidance is much appreciated.