How to use GCJ with Ant?

99封情书 提交于 2019-12-12 10:44:50

问题


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


回答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.



来源:https://stackoverflow.com/questions/2404763/how-to-use-gcj-with-ant

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!