Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to tell ant to build using a specific javac executable?

How can I tell ant to use a specific javac executable from the command line?

I have an installation of gcj, built as part of gcc, within a library we distribute, and I'd like to have a particular piece of Java software built against that. However, it just seems to use the system-gcc, and options such as "-Dbuild.compiler" seem to want me to specify some kind of Java class rather than a filepath.

I was hoping for something similar to CC in Makefiles.

I'm sure it's something really simple, and I'm just being stupid.


To be clear, I'd like to avoid editing the build file myself if possible. Is there not some standard way to simply specify the compiler on the command-line to ant? I don't mind the assumption that the buildfile is "well-behaved" in some sense.

like image 485
MGwynne Avatar asked Oct 20 '11 07:10

MGwynne


People also ask

Which is the Ant command to build the project?

To run the ant build file, open up command prompt and navigate to the folder, where the build. xml resides, and then type ant info. You could also type ant instead. Both will work,because info is the default target in the build file.

How do you pass an argument to an Ant build?

Discussion. If you want to pass arguments to Ant, you can enter those arguments in the Arguments box of the dialog opened by right-clicking your build file, clicking Run Ant, and clicking the Main tab. You can see that dialog in Figure 7-15 (note that you also can set the build file location and base directory here).

Which of the following arguments can we use to compile and specify a directory to place source and class files?

By default, javac compiles each source file to a class file in the same directory as the source file. However, it is recommended to specify a separate destination directory with the -d option.


1 Answers

If you are using Ant 1.6 or higher, you can set the javac attribute fork="yes". This gives you the ability to specify the path of your executable when using jikes, jvc, gcj, sj, or whatever version of javac you are using.

  <javac srcdir="${src}"
         destdir="${build}"
         fork="yes"
         executable="/opt/java/jdk1.1/bin/javac"
         compiler="javac1.1"
  />
like image 192
Kayser Avatar answered Oct 23 '22 19:10

Kayser