Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to get IntelliJ to recognize proto compiled Java class files

We have a build.xml in our project, but IntelliJ is unable to import from it. I get a:

Cannot import anything from <path_to>/build.xml file.

On Eclipse I can do a:

File -> Import -> General -> Existing Projects into workspace.

and chose top-level folder. I did the same in IJ. The project imported and indexed fine, I can do a search for any class. However, it does not recognize protobuf compiled class files. I installed the proto plugin, so it syntax highlights my .proto files, but still doesn't realize that there's a compiled class output that it needs to refer to. Do I need to do something special to get it to recognize those files?

like image 555
Siddhartha Avatar asked May 05 '15 18:05

Siddhartha


People also ask

Why is IntelliJ not recognizing Java files?

What to do if your IntelliJ Idea doesn't detect your existing project. Sometimes it may be due to it doesn't find the JDK on you configure path. If you have such a problem reconfigure the JDK. Click New >> JDK and provide the path and select JDK.

How do I open a .class file in IntelliJ?

You can automatically locate a class in the Project tool window. If the class is opened in the editor, press Alt+F1 to open the Select In popup. In the popup, select Project View and press Enter . IntelliJ IDEA locates your target in the Project tool window.


1 Answers

since this is pretty much the only place I could find an exact description for the issue I was facing with Idea, I'm replying even if it's an old question.

It turns out that if the .java file that's generated by the protocol buffers compiler is larger than 2.5MB (default setting), Idea ignores it altogether. Even if there is a .class file, even if compile/make succeed, even if you build your project just fine with Maven.

To fix that, simply edit your idea.properties file (it's inside the bin folder in your Idea installation folder), and either comment out this setting, or set it to something larger than your generated .java file (in my case, I set it to 15000, as my generated file is currently about 8MB in size):

#---------------------------------------------------------------------
# Maximum file size (kilobytes) IDE should provide code assistance for.
# The larger file is the slower its editor works and higher overall system memory requirements are
# if code assistance is enabled. Remove this property or set to very large number if you need
# code assistance for any files available regardless their size.
#---------------------------------------------------------------------
idea.max.intellisense.filesize=2500

Note: at least on Linux, where the default update policy seems to be "overwrite the old Idea folder with what you just downloaded", this change must be applied after every update/upgrade.

like image 129
michele b Avatar answered Sep 26 '22 05:09

michele b