How to import/create project from existing Ant build.xml file?

Answered

Hi,

I can't seem to find a way to import an existing ant based project that already has the build.xml configured. I am expected the IDE to able to read the file and at least setup the source directory and classpath/External Libraries properly. Can this be done on IDEA 12?

Thanks,
Zemian

1
3 comments

I'm not sure this is the correct, best or easiest way, but it worked for me ;-)
- open your build configuration (e.g. Run - Edit Configurations)
- select the configuration you want to modify and find the "Before launch" area on the bittom right of the window
- Click the grenn "+" sign
- Click "Run external tool"
- Click the green "+" in the pop up window
- Under "Tool settings" enter the path to your ANT as "Program", e.g. "C:\apache-ant-1.9.3\bin\ant.bat"
- Under "Parameters" you can enter command line parameters (i.e the targets)
- and finally you can define the path to your build.xml as "Working directory"

Depending on what you check marked as "Show in" the "Name" you defined for this definitions will show up in the selected menus.
If you confirm your settings with "OK", you'll find the new "script" as the last item in the "Before launch" list as "External tool 'name' ".
And you then can select the position where/when your ANT should run.

Then the ant command file will run before every start of a build process or if called from the menues.In a menu you'll find it with the name you assigned.

Good luck!

0
Avatar
Permanently deleted user

Hi Hans,

Thanks for the help. It's not exactly what I was looking for. The problem I face is I have a large ant based project and want to browse the code quickly. I can run and build the app on command line already. But browsing the code in IDE needs the classpath setup correctly. Unfortunately the nature of Ant project is that they setup java source folder in a not so standard fashion, but they are configured and bulid fine with the ant config. Right now, I have to manually edit IDE settings of where the source folders and add jars manually, despite I have fully working ant build file. I am looking for a better way to browse the code without IDE setup work.

0

Hi.
First of all, you need to enable the Ant plugin. Ctrl+Alt+S --> Plugins --> Check the Ant plugin. (Restart if needed).

Go to File --> New --> Project From Existing Sources...

After that choose the radio button "Create project from existing sources". Choose the directory that contains the build.xml file. (Note that the other option "Import project form existing sources" will not include Ant)

Intellij will create a new project and will automatically detect the "src" folder. If not, choose it on the next page of the wizard.
After that, the "libs" folder should be selected (one containing any *.jar dependencies). Usually, IntelliJ manages to find it automatically.

On the next page, you can choose the build.xml file as an Ant build file. If IntelliJ skips this step you can do it afterward from the Ant view window clicking the '+' sign and selecting the file. (View --> Tool Windows --> Ant).

1

Post is closed for comments.