Skip to content

ant: stdout lost over serial console; fork=true NPE; requires public class #596

Description

@LSantha

Summary

ant (Apache Ant 1.7.1 wrapper, org.jnode.command.dev.ant.AntCommand) works for compiling Java and running code, but:

  1. Ant's stdout does not stream over the serial console. Only Buildfile: build.xml (and occasionally part of the target list) appears; BUILD SUCCESSFUL, <echo> task messages, and program System.out are missing from serial output — even though the build actually succeeds and side effects happen.
  2. <java fork="true"> throws a hard JVM-level NullPointerException and the task produces no output/side effect.
  3. <java fork="false"> requires an explicit <classpath>, and additionally the target class must be public — a package-private class fails with IllegalAccessException from org.apache.tools.ant.taskdefs.ExecuteJava.
  4. <javac srcdir="." destdir="."/> compiles fine, and other tasks such as <touch> work — so the issue is not that ant "does nothing", only that its console output is routed away from the serial console.

Repro (JNode all-plugins boot /full.jgz, serial agent console)

All files under /devices/hdb1/devtest/ant1 (JFAT).

1. Ant compile+run with a public class — output invisible over serial

WH3.java:

public class WH3 { public static void main(String[] a) throws Exception {
  java.io.PrintWriter w = new java.io.PrintWriter(new java.io.FileOutputStream("/devices/hdb1/devtest/ant1/wh3.txt"));
  w.println("WH3 RAN"); w.close(); System.out.println("WH3_SYS_OUT");
} }

build.xml:

<project name="t" default="job">
  <target name="job">
    <javac srcdir="." destdir="."/>
    <java classname="WH3" fork="false" failonerror="true">
      <classpath location="."/>
    </java>
  </target>
</project>

Serial output:

Buildfile: build.xml

Expected: [javac], [java], WH3_SYS_OUT, BUILD SUCCESSFUL, Total time. None appear — but wh3.txt is created (8 bytes WH3 RAN), proving the class ran. So ant output (streams) IS lost over serial; execution works.

2. fork="true" breaks

Same build root with fork="true":
Serial output:

Buildfile: build.xml
java.lang.NullPointerException: NPE at address 3CDFE8D6

No wh3.txt created, no class output — ExecuteJava crashes when forking.

3. package-private class + fork="false"

WriteHello2 (no public on the class), built with:

<java classname="WriteHello2" fork="false" failonerror="true">
  <classpath location="/devices/hdb1/devtest/ant1"/>
</java>

Serial output:

Buildfile: build.xml
java.lang.IllegalAccessException: Class org.apache.tools.ant.taskdefs.ExecuteJava can not access a member of class WriteHello2 with modifiers "public static"

(The same class runs fine with the shell's java WriteHello2 from that directory, which uses JCClassLoader + reflection and accepts non-public classes.)

Observations / Analysis

  • Ant output and serial: only Buildfile: goes to the serial buffer. BUILD SUCCESSFUL, [echo], [javac], and program stdout are swallowed (buffered at the ant Project/BuildLogger level, presumably because the task's System.out uses a non-flushing buffered stream that is lost). This is the reason the common "ant does nothing" impression exists for serial usage.
  • WORKAROUND (for serial): ant reliably runs/compiles; verify by side effects (a file the code creates, ls -l timestamps, etc.), and keep target classes public. If you need direct stdout over the agent, use javac + java shell commands (see jnode-serial/jnode-java-coding skills) instead of ant.
  • This VM used this all-plugins image/JFAT /devices/hdb1/devtest and the automatic serial console (SerialConsolePlugin, UART2 /tmp/jnode.serialpipe).

Suggested fixes

  1. Make the ant wrapper (or the AntCommand) brief flush the Project logger / redirect ant log through an output stream that the shell flushes, so [echo], [javac], BUILD SUCCESSFUL reach the serial console.
  2. Fix ExecuteJava / forking path to avoid the fork=true NPE (possibly implement forking with a JNode-owned JVM invocation or document that fork is unsupported).
  3. After fix Fix typo in Unsafe.java class doc: "directy" → "direct" #1, nothing else required — ant will be usable over serial; non-public classes continue to require the shell java.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions