How to import existing Ant build.xml into IntelliJ IDEA
Asked Answered
S

4

27

I have an existing project that uses an Ant build.xml file to maintain the location of dependency jars.

In Eclipse it's very easy to import from an existing Ant file. I have searched online and looked through all of the "new project" options in IntelliJ but cannot figure out how to do this.

The closest thing I've done is File > New > Project from Existing Sources. But my whole project is full of errors because it didn't use the build.xml to include the jars.

Salpiglossis answered 22/5, 2015 at 17:43 Comment(0)
K
19

Intellij supports Ant projects via built in Ant plugin which is included by default in IDE. To check if it is enabled go to Settings > Plugins > Ant

After enabling plugin, you can use build.xml from View > Tool Windows > Ant Build

You should then have option(+) of importing your build.xml file.

Koeppel answered 22/5, 2015 at 21:17 Comment(9)
Thanks, that does allow me to build. But when I'm viewing the code in the editor it's still littered with errors, which makes it pretty annoying to use. Do you know of a way to deal with that?Salpiglossis
Do you see error even after running build? Does your project have multiple build files? Then you will have to add all files in Ant menuKoeppel
Yes I see the errors after running build. No I don't have multiple build.xml files.Salpiglossis
If build runs successfully, compilation errors should go away. Do you have external dependencies and are you sure they are downloaded(e.g in External Libraries folder)?Koeppel
And yes the external dependencies are downloaded and properly referenced to in the build.xml file. I'm sure of this because the Ant import in Eclipse works flawlessly.Salpiglossis
intellij may need build.xml to follow certain format. Please try checking if your build.xml is compatible to format mentioned Intellij and Ant FilesKoeppel
IntelliJ's editor does not use your Ant build file to figure out the classpath. You need to configure libraries on your project's module(s) separately (in the Project Structure dialog), and keep them in sync. If you convert your build to use Maven or Gradle instead, this problem goes away, and you get a bunch of other nice benefits too. :DNovara
@Novara I wish I could convert to Maven or Gradle :) but as lower ranked dev on an existing project I did not have that option. It would be nice if IntelliJ copied the Eclipse feature that uses the Ant build file to determine the classpath but I understand why they wouldn't bother to add that.Salpiglossis
As a lower ranked dev, if you did the work to convert (say, on a branch), that would save you and all of your coworkers a ton of time, which might then address the "lower-ranked" problem!Novara
P
12

You should use File > New > Module instead of File > New > Project from Existing Sources for Ant project. You also need to set your Content root and Module file location to your current Ant project directory.

You may also need to set right path to project output in Project Structure > Use module compile output path and set proper content route in Project Structure > Sources

Purcell answered 12/7, 2016 at 17:19 Comment(1)
Thanks a lot, that helped ! Strange that we can't import a full Ant project just as a Maven Project by selecting the main build.xml though.Truckload
B
12

Import the project "from existing sources" without choosing any build tool (ant is not on the list, only maven, sbt, etc...). Then after completing the import wizard, in the project files view, right click ant's build.xml file, and choose the option relating to ant which is hiding at the bottom of the menu.

Byrn answered 21/8, 2019 at 12:2 Comment(1)
you mean "add as ant build file"?Sumrall
S
3

Please, follow the steps below if you use the IntellIj:

  1. Check the Ant plugin for the project.

enter image description here

  1. select the build.xml file and add as the Ant build file

enter image description here

  1. Use the side button to deploy the project

enter image description here

Sestos answered 5/3, 2021 at 10:52 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.