Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Duplicate class found" - IntelliJ and .class files

I recently imported one of our company's project into IntelliJ Idea (10.5.1). We build and run the project using an ant build script and IntelliJ supports that just fine.

However, IntelliJ seems to have a distinct problem when the compile output directory equals the source code directory, ie .class files are placed in the same directories as their corresponding .java sources.

(Note that I am aware that is not a proper way to go, but tell my boss that. This project is over 15 years old and correspondingly large, too many things depend on it to be this way, there is nothing I can do about that.)

So once things are compiled, IntelliJ detects the .class files and adds them to the project tree. The problem here is that it considers them class declarations, thus I get a "duplicate class found" message for each and every class. This doesn't make me unable to work, but it is extremely annoying as you may guess.

I tried making the IDE ignore .class files, but apparently that makes it not load any classes at all, including the JRE runtime and anything else located inside of .jar files.

Is there any way to make IntelliJ Idea ignore .class files which are in the same location as their .java sources?

like image 447
pdinklag Avatar asked Jul 05 '11 09:07

pdinklag


People also ask

How do you fix a duplicate class error in Java?

In such a case, the module is copied in the javasource folder in the app directory with a new name and the old folder is kept, resulting in two identical folders with different names. Simply delete the copied folder with the modulename that is not used and you should be fine.

Where are class files stored in IntelliJ?

class files. Inside the output directory, IntelliJ IDEA also creates subdirectories for each of your modules. The default paths for subdirectories are as follows: Sources: <ProjectFolder>/out/production/<ModuleName>

How do I see all classes in IntelliJ?

By default, IntelliJ IDEA shows all classes, methods, and other elements of the current file. To toggle the elements you want to show, click the corresponding buttons on the Structure tool window toolbar. to show class fields. to have protected class members shown in the tree.


1 Answers

Make sure that you've configured the output directory to the source directory, disable the Exclude of the output directory to see your files.

like image 109
CrazyCoder Avatar answered Oct 25 '22 07:10

CrazyCoder