"Duplicate class found" - IntelliJ and .class files - intellij-idea

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?

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

I coped with this same problem when cloning a project from Bitbucket. To solve it in IntelliJ:
Project Structure > Modules > Source > Source folder > <<"Eliminate the unwanted source folder">>
In my case, I had non-implemented classes in one source folder and a second source folder with the implemented classes (same class names).
I deleted one, built again, and the problem got solved.
Give it a try!

Related

How to use a JAR file in IntelliJ after downloading?

I want to use the import javax.ide in IntelliJ, specifically exploring MetaClass and seeing what it can do. I've downloaded the JAR (198) from https://download.oracle.com/otndocs/jcp/standard_extension_ide-1.0-fr-oth-JSpec/, and I know I'm supposed to somehow add it to dependencies under Project Settings -> Modules -> Dependencies, but I'm not sure what exactly I'm supposed to add from the downloaded folder. The folder containing javax/ide itself is somewhat buried, but I tried adding different levels of directories and none of them worked. The actual folder doesn't even contain java files, it contains a bunch of htmls so I might just be downloading the wrong thing. Thanks for the consideration
I've downloaded the JAR (198) from
It is not a JAR. This is a .zip archive and it does not contain compiled classes in a form of a JAR. It has only source files.
If you are working with a JAR - you need to add such a jar file which contains the needed for your classes into the module's dependencies.
If you do not have the JAR but only have sources - you can create a separate module from these sources and then use it as a module dependency to the module where you want to use these classes.

IntelliJ IDEA directory-based format and .iml file(s)

We started a directory-based project in IntelliJ IDEA (currently using version 2016.3 build 163.7743.44). Everything is fine, the .iml file is inside .idea/modules and we can easily share/update it.
The issue is that, sometimes, when someone clones the project and start using it the IDE doesn't care about that file (or project structure) and puts an .iml outside the project's root. It's an intermittent/random issue and I'm not able to reproduce it step by step.
We opted for deleting the .idea directory from Git and keep the configurations/settings in a JAR file.
Is there any way to tell the IDE to use one approach or the other? It's not a big deal, but I would like to know what's the reason behind that behavior.
The reason for that behavior may be that people don't use the "Open" action to open the project but use the "Import project from existing sources" action instead. The latter action does not use the existing .idea directory, but instead recreates the project structure from scratch. You should teach your colleagues not to use that action.
Note that storing the settings in a .jar file is not a replacement for sharing the project structure, because shared settings do not include project-specific items such as libraries and run configurations.

xml files are not copied to target intellij idea

I have some xml files within the source folder along with the java files.
Intellij Idea is not copying them to the target folder.
I want those xml files to be along with the classes in the target.
Eclipse does this fine.
Can anyone please tell how to achieve this in Intellij Idea?
If, like me, the other answer didn't solve your problem -
If IDEA thinks your project is a Maven module (or once was), and it isn't, it'll behave like this. You can fix this by closing the project, editing the .iml file to remove the isMavenModule property, reopening, and rebuilding:
<moduleorg.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true"type="JAVA_MODULE" version="4">
In its default configuration, IDEA should copy any xml file that are in a source directory into the target directory. Other build tools may not. So this answer is assuming you are making the project via IDEA's internal build/make. If using maven (or gradle), you should place your resources in src/main/resources and not src/main/java as Engineer Dollery mentions in his/her comment.
If you are using the IDEA builds and it is still not copying them over, there is a setting you can check. Go into Settings > Build, Execution, Development > Compiler. On the Compiler settings dialog at the top is a "Resource Patterns" text field. This will define what files IDEA will and will not copy over. The default entry is:
!?*.java
!?*.form
!?*.class
!?*.groovy
!?*.scala
!?*.flex
!?*.kt
!?*.clj
!?*.aj
It is just a set of negation patterns of things not to copy over. So XML files should be copied. Check this setting and see if there is something in it to prevent xml files from being copied.

Configure automatic excluded directories and other directory types when they are present

In the Community Edition when I import a module IntelliJ goes through and tries to figure out which directories are what types. The modules I deal with sometimes have a src and a test directory, which work fine, but more often than not the test directory is actually named tst. IntelliJ likes to mark is as a "Sources" directory rather than "Tests". With the tools I am working with, the dependency configuration and generation of the .iml file happens after this, as well as using a modified build system that is not IntelliJ supported. I have to build via commandline which generates a build folder which I would like to have automatically excluded.
So a couple questions.
Can I configure IntelliJ to automatically recognize different folder names "Tests" and mark them as such?
Can I configure IntelliJ to automatically mark a folder as excluded when it is present in a module?
You can't configure it, the list is hard-coded. However, I've added "tst" to the list of names that are recognized as test source roots; that fix will be included in IntelliJ IDEA 14.1.
You can add "build" to Settings | File Types | Files and folders to ignore. Then IntelliJ will ignore the directories and files named "build" anywhere in your project structure. Given that "build" is a fairly common name, this may or may not be what you want.

Some classes can't be resolved when compiling Apache Drill?

I built the Drill project according to the wiki specification
but, the project has some errors. Some classes (BigIntVector, BitHolder,BigIntHolder) can't be resolved and the workspace don't really contain these class files. Any suggestions as to what's going on?
These clases are generated during build.
exec/java-exec/target/generated-sources/org/apache/drill/exec/expr/holders/BigIntHolder.java
There is a problem in that the Maven import into eclipse results in target/generated-sources/org being added to the Source Folder build path. I have found that in the two cases, comon and java-exec, if you remove these folders from the source folder build path and add them as target/generated-sources this will help.
This is a workaround, there is obviously a misconfigured pom.xml somewhere.