26

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.

Community
  • 1
  • 1
Mike S
  • 11,329
  • 6
  • 41
  • 76

4 Answers4

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.

hitz
  • 1,100
  • 8
  • 12
  • 7
    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? – Mike S May 23 '15 at 20:26
  • 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` menu – hitz May 24 '15 at 20:47
  • 1
    Yes I see the errors after running build. No I don't have multiple `build.xml` files. – Mike S May 26 '15 at 23:25
  • 1
    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)? – hitz May 27 '15 at 16:05
  • 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. – Mike S May 28 '15 at 18:17
  • intellij may need `build.xml` to follow certain format. Please try checking if your `build.xml` is compatible to format mentioned [Intellij and Ant Files](https://www.jetbrains.com/idea/help/ant.html#d784316e18570) – hitz May 28 '15 at 20:10
  • 8
    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. :D – JakeRobb Sep 03 '15 at 14:57
  • @JakeRobb 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. – Mike S Jul 14 '16 at 18:26
  • 1
    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! – JakeRobb Jul 15 '16 at 00:31
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

Amir Razmjou
  • 512
  • 6
  • 10
  • 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. – Dynamite Aug 25 '23 at 12:34
11

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.

matanster
  • 15,072
  • 19
  • 88
  • 167
2

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

Arefe
  • 11,321
  • 18
  • 114
  • 168