File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Ant, Maven and Other Build Tools and the fly likes Can I debug in IDEA using ant to build? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Ant, Maven and Other Build Tools
Bookmark "Can I debug in IDEA using ant to build?" Watch "Can I debug in IDEA using ant to build?" New topic
Author

Can I debug in IDEA using ant to build?

Rob Ross
Bartender

Joined: Jan 07, 2002
Posts: 2205
I'm just starting to use ant with IntelliJ IDEA.
Over time, I have used many different IDEs to manage my build environment, I have used ant, and I have written manual build scripts (batch files).
But I'm having trouble understanding what I can and can't do with respect to using ant in my IDE. For example, in an IDEA-only project, I set up my source paths, my classpaths for compilation, and my output path. It compiles *all* the source files, using any pre-compiled libs in the classpaths, and writes the output .class files to another directory. When I "run" the project, it calls the main method of a class I just compiled in that output directory, and it uses the same classpath for any libraries it needs at runtime; it doesn't have to copy all the .jar files for example to the output directory to run.
So I am a happy camper, building and running and getting to use the debugger for free! I really like the debugger.
Now, I know ant has many advantages as a build tool, so I'd like to use that with IDEA. I'd like to click my "run" button in IDEA, and have it know (because I configured it that way) to run a certain ant task, THEN use the files that ant created; for example, if my ant task creates a "build" directory of its own, look for my main class in that directory, NOT the compiler output directory it normally uses. In this way, I could get seamless ant integration, and debugging.
As it is now, all I seem to be able to do is select an ant task from my build.xml file to be executed. It does all the work outside the IDEA. I can even have an ant task to run the app after it is done building it; but again it's outside the IDE and so I can't use the debugger.
Since I'm new to this, I'd appreciate some pointers.
Thanks in advance!


Rob
SCJP 1.4
Rob Ross
Bartender

Joined: Jan 07, 2002
Posts: 2205
Ok after much searching and burning-of-oil late at night, here's what I have found out...
Well after a lot of searching on the web and in the IDEA forums, I have come to the conclusion that what I am trying to do cannot be done in IDEA at this time. I think there is an existing feature request for this item, however.
But the "solution" I have employed is to manually (ick, yea I know!) configure the project paths to look in the directories ant creates. The IDEA editor needs the source path set up to display the source files and correctly parse the source code for display and hyperlinking, etc. This is probably pretty stable over the life of the project.
The output directories are a different matter. Since I will be building exclusively with ant (from IDEA), these directories are more delicate; if the build.xml file re-configures the target directory structure, it will break my output path setting in IDEA and I will have to manually fix that. Also, it only allows for one target configuration, whereas with ant, I could conceivably have multiple target directory structures for each task. But for my simple project there's just one build directory and one place where the class files go, so I'm ok for now.
The real pain though is I also have to manually add all my lib jar files to IDEA's classpath tab. This is the area of pain, since these will surely change much during the evolution of a project as jars are added and removed to the project, renamed, etc. This is a total duplication of effort and it would be great if IDEA could get the classpath info from the build.xml file.
So what I can now do is under the Project Properties-->Run/Debug, make sure the "make project before running/debugging" is NOT checked, so that IDEA won't try to build the project when I run it.
Then, I make sure my compile ant task has been selected to "Execute On-->Before Run/Debug".
Now, the only thing I have to remember is NOT to select compile or make project from the IDEA menus; instead, I can select Run/Debug for a class, and I will be assured that ant will compile the project, then IDEA will run the class file (just compiled by ant). I can also manually build the project *from IDEA* by going to the Build menu and choosing one of the ant tasks that show up there.
This is a pretty reasonable solution, and is working for my particular case. The only downside really is having to manually add all the lib jar files to the IDEA project. It really would be great if IDEA could have a command to "Import settings from build.xml".
Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9044
    
  10
So what you are saying is that you want Ant to build to different directories than you want IntelliJ to build to, but you still want IntelliJ to be able to debug those directories that it knows nothing about?

Why not have Ant and IntelliJ using the same directory structure? i.e. src, build/classes, dist, etc.


JavaBeginnersFaq
"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
Rob Ross
Bartender

Joined: Jan 07, 2002
Posts: 2205
Originally posted by Marilyn de Queiroz:
Why not have Ant and IntelliJ using the same directory structure? i.e. src, build/classes, dist, etc.

This is actually exactly what I am trying to accomplish, but without having to manually configure IDEA separately. I want ant to drive the build, and have IDEA use the classes that ant has compiled to run and debug.
Originally posted by Marilyn de Queiroz:
So what you are saying is that you want Ant to build to different directories than you want IntelliJ to build to, but you still want IntelliJ to be able to debug those directories that it knows nothing about?

I want the knowledge about the build process to exist in only one place, in the build.xml file, so that I eliminate the possibility of introducing errors if I have to manually keep both the IDEA project file and the build.xml file in synch.
Ant is much more powerful and flexible in its build options than IDEA, or any IDE for that matter, which is a good reason to use it. If I have a complex project with many subprojects, I will have many different build tasks. A particular sub-project may only use a subset of libs, sources, and class files, resources, etc, and I may want to package it differently than if I'm building the whole project, or a different subproject. IDEA only lets me configure only ONE output path. (I do have an option to have multiple output paths, but that only pertains to multiple source directories, i.e., a one-to-one correspondence; each source dir will produce a class dir with the same file structure. But that's different than what I described above.)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Can I debug in IDEA using ant to build?