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.
Please don't beat me, but after setting the 'Generate Ant Build'-dialog like:
the errors are gone:
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.
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"/>
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.
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.
Related
I'm trying to use jacoco to perform unit tests on files but it keeps popping with NoClassDefFoundError and keeps giving new class names every time I sort the previous error out. Till now I've been manually providing the pathelement location to the bin folders which contain the required .class files.
I'd like to fasten the process by using dirset if possible. I've compiled a dirset which contains the bin folders of all the main folders that are required.
Questions:
1. How do I include this dirset in the classpath such that jacoco looks for the .class files in these set of bin directories?
2. Is there any way in which I can echo the dirset to the cmd to check its contents?
3. Why does this not work?
<echo message="Build path is: ${toString:ALL.dirs}"/>
dirset:
<path id="ALL.dirs">
<dirset dir="${classes.dir}">
<include name="projects-framework/**/bin"/>
</dirset>
</path>
jacoco code coverage:
Code I've written till now. The "**" in the code are the full locations to the bin folders which I do not think is relevant here.
<target name="cov-test">
<mkdir dir="${report.dir}"/>
<jacoco:coverage>
<junit fork="true" forkmode="once" showoutput="true" printsummary="on" enabletestlistenerevents="true">
<test name="full.qualified.name.ABC"/>
<classpath>
<path refid="classpath"/>
<path refid="application"/>
<pathelement location="projects-framework/**/bin"/>
<pathelement location="projects-framework/**/bin"/>
<pathelement location="projects-framework/**/bin"/>
<pathelement location="projects-framework/**/bin"/>
</classpath>
<formatter type="plain"/>
<formatter type="plain" usefile="false" />
</junit>
</jacoco:coverage>
</target>
I have my jar files in Assignment2\lib folder and my build file is in Assignment2. The name of the jar file is Assignment1.jar The following is how I tried to compile my Assignment2 from build file through ant.
<project name="Assignment1" default="run" basedir=".">
<property name="classes" value="classes" />
<path id="project.class.path">
<pathelement location="src"/>
<pathelement path="${java.class.path}/"/>
<pathelement path="${additional.path}"/>
</path>
<path id="lib.jars">
<fileset dir="lib" includes="**/*.jar" />
</path>
......
<target name="compile" description="compaling java files with Assignment2">
<mkdir dir="build"/>
<javac srcdir="src" destdir="build" debug="on" failonerror="true">
<classpath refid="project.class.path"/>
<classpath refid="lib.jars"/>
</javac>
</target>
<Project/>
I am getting compile errors. I'm using windows. Is that the problem? Is there any way to compile?
Well,Everything looks good to me but, you can try the following to validate the same,
Check if the lib folder has all the necessary library jars required to compile you application
You can try assigning the relative path of the lib folder to a property and refer it in the classpath eg: Property lib value=".\Lib"
Try the following before you call the compile target to see the list of jars being included in the classpath
<pathconvert property="libjars" refid="lib.jars"/>
<echo>libjars is ${classpathProp}</echo>
hey guys thanx for the answers actually i found probelm. i was trying to use a jar file created by netbeans files. Apparently netbeans jar files can be used only by netbeans. at the end i made a new jar file of Assingment1 and used it. now everything is fine. Thanx again for the answers.
I am trying to build my Android project with Ant. I have some reference libs which I defined in build.xml like below mentioned in this question:
<target name="-pre-compile">
<!-- HACK to add the android-support-v4.jar to the classpath directly from the SDK -->
<echo>ORIGINAL jars.path : ${toString:project.all.jars.path}</echo>
<path id="project.all.jars.path.hacked">
<path path="${toString:project.all.jars.path}"/>
<path path="${sdk.dir}/extras/android/support/v4/android-support-v4.jar"/>
</path>
<path id="project.all.jars.path">
<path path="${toString:project.all.jars.path.hacked}"/>
</path>
<echo>HACKED jars.path : ${toString:project.all.jars.path}</echo>
</target>
I have no problem while compiling with my external jars and it builds apk properly.
My problem starts when I use an external lib having exact package similar to system package.
For example, I have some customized frameworks.jar and I have linked it to my project in the same fashion mentioned above. But ANT considers system frameworks and ignores my frameworks.jar.
This works fine in Eclipse when I order it and keep my custom frameworks.jar above system Android libs (Eclipse > Project > Right Click > Build Path > Configure Build Path > Order and Export)
Is there any way how we can define order of libraries to be consider while compiling by ANT. Like how we do it in Eclipse?
Just replace javac bootclasspath param to solve this problem.
The original bootclasspath is platform/android-xx/android.jar, and this class path has the the highest priority.
So we have to replace it with your own external jar, and replace it back after compile is finished to prevent proguard from adding platform/android-xx/android.jar to obfuscated.jar.
Code as follows:
<path id="project.org.path" >
</path>
<path id="project.org.android.jar" >
</path>
<target name="-pre-compile" >
<path id="project.org.path" >
<path path="${toString:project.all.jars.path}" />
</path>
<path id="project.org.android.jar" >
<path path="${toString:project.target.class.path}" />
</path>
<path id="project.all.jars.path.hacked" >
<path path="${toString:project.target.class.path}" />
<path path="${toString:project.all.jars.path}" />
</path>
<path id="project.all.jars.path" >
<path path="${toString:project.all.jars.path.hacked}" />
</path>
<path id="project.target.class.path" >
<path path="./framework.jar" />
</path>
</target>
<target name="-post-compile">
<path id="project.all.jars.path" >
<path path="${toString:project.org.path}" />
</path>
<path id="project.target.class.path" >
<path path="${toString:project.org.android.jar}" />
</path>
</target>
I'm having a problem getting the javac used by Ant to find and use certain packages. When I invoke javac directly from the command line the packages are found and used.
The .jar files are located in my home directory under lib/java. This is my classpath:
/home/bliskovs/lib/java/*:/home/bliskovs/vendor/cytoscape-v2.7.0/cytoscape.jar
This is the relevant section in my build.xml:
<target name="compile">
<javac srcdir="." debug="true"/>
<javac srcdir="tools/" debug="true"/>
<javac srcdir="core/" debug="true"/>
</target>
How can I get Ant to recognize these packages?
Check out this.
<property name="build.classes.dir" location="build/classes"/>
<path id="compile.classpath">
<fileset dir="lib"/>
<pathelement location="/home/bliskovs/vendor/cytoscape-v2.7.0"/>
</path>
<target name="compile" description="Compile src dir">
<javac destdir="${build.classes.dir}" debug="true" includeantruntime="true">
<src location="src"/>
<classpath refid="compile.classpath"/>
</javac>
</target>
Define a classpath for the javac task. Relying on the CLASSPATH environment variable is a bad practice. It's even more true for the build process of a project, which should work without having to setup a whole lot of environment variables. If you start developing three or four projects at once, you'll understand why using a single CLASSPATH env variable is a bad idea.
See http://ant.apache.org/manual/Tasks/javac.html to know how to define a classpath inside the build.xml and use it in the javac task.
I need to add a folder in current classpath for ant script that I have written for running java files. How can it be done?
You could add it as an attribute
<java classpath="${extraDir}"
classname="pkg.Class">
...
</java>
Or using the nested <classpath> tag:
<java classname="pkg.Class">
<classpath>
<pathelement path="${extraDir}"/>
</classpath>
</java>
See the documentation for the Java task.
i added the following line in the tag of the task and it ran successfully.
<pathelement path="C:\JunitTest\folderIsHere"/>
and after this the script ran successfully.