How to use GCJ with Ant?
Asked Answered
G

1

6

I'm fairly new to both Apache Ant and GCJ, and I'm having a hard time trying to build with GCJ via Ant.

My app is in Scala, so I need to use GCJ to take .class files as source. No problem compiling .scala to .class with Ant.

First I figured out how to manually compile a .class file to .o (object), this way:

gcj --classpath=(...) -c (somepath)MouseClickListener.class -o (somepath)MouseClickListener.o

I see here that Ant supports GCJ compilation through the javac tag. So I figured this should work:

<target name="gcjCompile" depends="compile">
    <mkdir dir="${object.dir}" />
    <javac srcdir="${build.dir}"
           destdir="${object.dir}"
           compiler="gcj"
           executable="C:/gcc/gcc-4.3/bin/gcj.exe"
           classpathref="gcjProject.classpath">
        <include name="**/*.class"/>
    </javac>
</target>

But this javac task does nothing and I get no errors. Any clues? Thanks

Gaberones answered 8/3, 2010 at 21:10 Comment(2)
> My app is in Scala, so I need to use > GCJ to take .class files as source. That's a non sequitur. GCJ is not Java. I can't recommend you use it. If you must have native compilation there are current products out there.Mcclurg
Which would you recommend?Torrell
B
1

It sounds like you want to link your app into a native executable. That means that you've already compiled the source into JVM bytecode (as you've figured out to do by compiling .scala into .class files). You'll need to run the gcj command manually using the <exec> task to compile the bytecode into gcc object code files.

I'd recommend something like this:

<property name="main.class" value="Main" />
<property name="class.dir" value="${basedir}/classes" />
<target name="compile">
  <mkdir dir="${class.dir}" />
  <javac srcdir="${build.dir}"
         destdir="${class.dir}"
         compiler="gcj"
         executable="C:/gcc/gcc-4.3/bin/gcj.exe"
         classpathref="gcjProject.classpath">
    <include name="**/*.java"/>
  </javac>
</target>
<target name="link" depends="compile">
  <mkdir dir="${object.dir"} />
  <exec cmd="C:/gcc/gcc-4.3/bin/gcj.exe">
    <arg value="-classpath=${object.dir}" />
    <arg value="-c" />
    <arg value="*.class" />
  </exec>
</target>

Keep in mind that you need to define the build.dir and object.dir properties, and you may need to add a depends task before the javac in the compile target (or just recompile from scratch each time). I may have missed a lot of things, you should check the manual pages (for gcj, gcc, and ant) if it doesn't work at first.

Barbital answered 17/1, 2011 at 13:4 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.