ToolProvider. getSystemJavaCompiler() returns null in IntelliJ plugin

Answered

I am creating a plugin where i ask user to enter the java code int a TextArea.

I have created an Action for this and, when clicked on Action, i am able to show a dialog box with TextArea in it.

After the user has entered the code and click on “Ok” button, i am trying to compile the code.

I used ToolProvider.getSystemJavaCompiler() but it is returning null.

0
5 comments

After googling a bit about the command you mentioned, I found this:

https://bugs.java.com/bugdatabase/view_bug?bug_id=6477844

Essentially IntelliJ itself is running using a JRE, not a JDK. What you can do is check the SDKs used in the current project or module and use the JDK set there, however they could also be Python SDKs for example, so be cautious and check their types.

0

I solved it in my plugin, you can search Cool Request, or go to my github https://github.com/houxinlin/cool-request

0

Hi Bradan,

Thanks for the tip. I will try to get the current JDK of project and invoke javac from there.

Hi Hxl49508,

I checked your repository. it seems you are shipping a javac.jar along with your plugin. However i am not allowed to add any extra jar unless extremely necessary. Can you please confirm if i understood your project correctly and you are shipping an additional jar.

 

0

Yes, this is the only solution I've found so far

0

This javac.jar file is only 3M, very small

0

Please sign in to leave a comment.