Ant task for compiling GUI forms (Intellij IDEA)

2019-04-26 23:32发布

How I can create a Ant task to compile GUI forms (XML) in Intellij IDEA? I use Scala and Java in my project. Java only for GUI class, and I create it with Intellij IDEA UI Designer.

5条回答
混吃等死
2楼-- · 2019-04-26 23:48

Here's the correct way:

<property  name="javac2.home" value="C:\\Program Files (x86)\\JetBrains\\\IntelliJ IDEA 14.1.4\\lib"/>
<path id="javac2.classpath">
      <pathelement location="${javac2.home}/asm.jar"/>
      <pathelement location="${javac2.home}/asm-all.jar"/>
      <pathelement location="${javac2.home}/javac2.jar"/>
      <pathelement location="${javac2.home}/jdom.jar"/>
      <pathelement location="${javac2.home}/asm-commons.jar"/>
      <pathelement location="${javac2.home}/jgoodies-forms.jar"/>
 </path>

Works for both Intellij Community and Ultimate. Tested in both. Just change it to your Intellij Community path, so "IntelliJ IDEA Community Edition 14.1.4", for example.

查看更多
别忘想泡老子
3楼-- · 2019-04-26 23:48

Since this comes up on google, here is what is needed:

<property name="javac2.home" value="${idea.home}/lib"/>
<path id="javac2.classpath">
    <pathelement location="${javac2.home}/asm.jar"/>
    <pathelement location="${javac2.home}/asm-all.jar"/>
    <pathelement location="${javac2.home}/javac2.jar"/>
    <pathelement location="${javac2.home}/jdom.jar"/>
    <pathelement location="${javac2.home}/asm-commons.jar"/>
    <pathelement location="${javac2.home}/jgoodies-forms.jar"/>
</path>

The key is asm and asm-all which solves ClassReader and ClassWriter errors. I had to look in the jars to find that out. "javac2.home" will be OS dependent. This is on Intellij Ultimate.

查看更多
兄弟一词,经得起流年.
4楼-- · 2019-04-26 23:57

Same problem here. Solved this way:

<property  name="idea.lib" value="C:\\Program Files (x86)\\JetBrains\\IntelliJ IDEA Community Edition 9.0.3\\lib"/>

<path id="javac2.classpath">
    <pathelement location="${idea.lib}/javac2.jar"/>
    <pathelement location="${idea.lib}/jdom.jar"/>
    <pathelement location="${idea.lib}/asm.jar"/>
    <pathelement location="${idea.lib}/asm-commons.jar"/>
    <pathelement location="${idea.lib}/jgoodies-forms.jar"/>
</path>
<taskdef name="javac2" classname="com.intellij.ant.Javac2" classpathref="javac2.classpath"/>
查看更多
Root(大扎)
5楼-- · 2019-04-26 23:59

Please don't beat me, but after setting the 'Generate Ant Build'-dialog like:

enter image description here

the errors are gone:

enter image description here

查看更多
兄弟一词,经得起流年.
6楼-- · 2019-04-27 00:09

IDEA provides a Ant task, javac2, that does this. It's a drop-in replacement for the standard javac Ant task.

First, you'll need to include something like the following near the top of your Ant build file.

<path id="javac2.class.path">
    <pathelement location="${idea.dir}/redist/forms_rt.jar"/>
    <pathelement location="${idea.dir}/redist/javac2.jar"/>
    <pathelement location="${idea.dir}/redist/annotations.jar"/>
</path>
<taskdef name="javac2" classname="com.intellij.ant.Javac2" classpathref="javac2.class.path"/>

Here "${idea.dir}" refers to the directory of your IDEA installation. Those jars are redistributable, so you can copy them into your project if you wish, and refer to them there. Once you've done that, just replace any calls to "javac" tasks with "javac2", and everything should just work.

To compile scala, of course, you'll need calls to either scalac or fsc, but those are unaffected by all of this.

查看更多
登录 后发表回答