.class output in same dir as source? Bug?

IntelliJ IDEA 11.1.1

I am trying to configure a module so that compiler output files (.class files) are produced in the same directory as the corresponding Java source files.

1) Is there a way to directly state "compile to same dir"? There doesn't seem to be that option in the Project Structure dialog Modules > Paths tab, unless the idea is to use dot in some clever way?

2) For module with a single source dir, I tried using the "Use module compile path" and set it to the corresponding src dir.  That cause the IDE to ignore the src directory as a location of source files.

3) I saw in the docs that the "Exclude output paths" checkbox really means "Ignore source code in output path directories", so I unchecked that. The source files reappearedin the IDE project tree.

4) I recompiled, and the result was that the IDE actually deleted all the source files!  I assume that this was following the logic that old files in the output directory should all be deleted prior to compiling?

At any rate, if the IDE has an explicit checkbox to permit output to source directories, it seems like a bug to me for the IDE to delete the source files.

Bottom line:  Is there a way to "compile to same directory"?

--  Graham

2 comments
Comment actions Permalink

Why do you need to have .class files in the same directory as source code? This is not how things are done in the Java world, and IntelliJ IDEA does not support this kind of arrangement.

Note that if you need to distribute the .class files of your project together with the source code, you can set up an artiffact that would package .class and source files in the same directory and archive them together.

0
Comment actions Permalink

Hi Dmitry, thanks for your quick answer. Let me answer your question:

Why do you need to have .class files in the same directory as source code? This is not how things are done in the Java world, and IntelliJ IDEA does not support this kind of arrangement.


I am aware that for any substantial project, the custom is to have .class output in a separate directory branch, including the possibility of even separating out production versus test output files.

However, in this particular case, I am working with a long series of small exercises, each of which consists of a single directory with a few source files, some data files and some other inputs to the build process. In this situation it is very convenient to have the class files generated into the same directory, because when you subsequently test, the input files are right in the same directory.  Indeed, that coincides with the simplest invocation of javac:

javac *.java

... so it's not so unspeakable a case.:)

I have now found in the help that the intent of the  "Exclude output paths" checkbox is to exclude output directories from deployment. Unchecking it should allow output directories to be included in deployment.  So it's a puzzle to me why "allow output directories for deployment" interacts with the IDE's idea of which directories are eleigible to be source directories, which contributed to me finding the issue where compiling caused all source files to be deleted.  Anyhow, it sounds like the answer is: "don't do use IDEA that way"!

-- Graham

0

Please sign in to leave a comment.