Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to see the compiler output when running javac through an Ant task?

Is there any clearly explained and simple way to see the compiler output when running javac through an Ant task?

Here is my javac Ant tag:

<javac srcdir="${myproject.src}" destdir="${myproject.class}">
    <!-- ... -->
</javac>

Here is the only error message I get:

/path/to/build.xml:42: Compile failed; see the compiler error output for details.

The problem is that I don't know how to see the compiler error output for details...


Few configuration elements that may help:

  • Ant 1.6.5
  • Windows 7 x64
  • Java 1.6.0_20 x32
  • Launching targets via Eclipse

I know there are some related answered questions on SO, but none of them really answers this simple questions:

  • https://stackoverflow.com/a/1275552/1225328: I can't add the specific library that allows the compile tag;
  • https://stackoverflow.com/a/1264622/1225328: this manages Ant's output rather than the compiler's one;
  • Compile failed; see the compiler error output for details: too vague to solve anything;
  • Ant : Compile failed; see the compiler error output for details: no answer...
  • etc.
like image 400
sp00m Avatar asked Jul 05 '13 15:07

sp00m


People also ask

What is the output of javac?

The output of javac is always classfiles, and the name of the file matches the name of the class contained within it. (A source file with multiple classes in will result in multiple output files.)

Which Ant task does the Java compiling?

Ant Javac task is used to compile Java source file. It scans source and destination directory to compile the source file.

What is includeAntRuntime in ant?

includeAntRuntime. Whether to include the Ant run-time libraries in the classpath. It is usually best to set this to false so the script's behavior is not sensitive to the environment in which it is run. No; defaults to yes , unless build.sysclasspath property is set.

Which command line option do you use to tell the javac compiler where compiled class files should be stored?

Use the --source-path option to specify the locations of additional source files that may be read by javac. Locations on the source path should be organized in a package hierarchy.


2 Answers

I think you're looking for the verbose="true" attribute.

Asks the compiler for verbose output; defaults to no.

You already mentioned in the comments that this doesn't print the cause of your error. Well I think something else is going on in your situation. I have a sample project and either way the cause of my error was printed. Here's the output with verbose="false":

[mkdir] Created dir: C:\Projects\MavenSandbox\target\classes
[javac] C:\Projects\MavenSandbox\mavensandbox.xml:284: warning: 'includeantruntime' was not set, defaulting to build.sysclasspath=last; set to false for repeatable builds
[javac] Compiling 3 source files to C:\Projects\MavenSandbox\target\classes
[javac] C:\Projects\MavenSandbox\src\main\java\com\sandbox\Sandbox.java:8: error: cannot find symbol
[javac]         System.out.prinln("Hello, I\'m the best!");
[javac]                   ^
[javac]   symbol:   method prinln(String)
[javac]   location: variable out of type PrintStream
[javac] 1 error

Something strange and specific to your code is causing the bad error message. Can you create a sample project that reproduces the error?


As you mentioned, debug="true" is not the attribute you're looking for.

Indicates whether source should be compiled with debug information; defaults to off. If set to off, -g:none will be passed on the command line for compilers that support it (for other compilers, no command line argument will be used). If set to true, the value of the debuglevel attribute determines the command line argument.

You know when you get stack trace and it has line numbers in it? That's what debug="true" does. If it's off, you don't get line numbers.

like image 60
Daniel Kaplan Avatar answered Oct 21 '22 16:10

Daniel Kaplan


The problem also occurs when the java-compiler itself cannot start. As an example, when the defined heap is too big. The java2 task of Intellij would display the information

Using external javac compiler
Compilation arguments:
...
'-J-Xmx1600m'
...
Error occurred during initialization of VM
Could not reserve enough space for object heap
Could not create the Java virtual machine.

and the cause in the build.xml file, in my case:

<property name="compiler.args" value="-J-Xmx1600m"/>
like image 35
Olivier Faucheux Avatar answered Oct 21 '22 17:10

Olivier Faucheux