javaee / jaxb-v2

Other
211 stars 100 forks source link

Compile failure in the modify-marshal sample with <xjc/> but fixed it somehow. #1147

Open ericjvandervelden opened 7 years ago

ericjvandervelden commented 7 years ago

Hello,

In the build.xml of the modify-marshal sample there is:

<taskdef name="xjc" classname="com.sun.tools.xjc.XJCTask">
    <classpath refid="classpath" />
 </taskdef>

<xjc schema="po.xsd" package="primer.po" destdir="gen-src">
      <produces dir="gen-src/primer.po" includes="**/*.java" />
</xjc> 

This does not work on my machine with java 8. When I do in the modify-marshal sample (in eclipse) : ant compile, then the Java files are generated, but then I see an error:

compile:
     [echo] Compiling the schema...
    [mkdir] Created dir: C:\Users\ervelden\java\jaxb-v2\jaxb-ri\bundles\ri\target\stage\jaxb-ri\samples\modify-marshal\gen-src
      [xjc] C:\Users\ervelden\java\jaxb-v2\jaxb-ri\bundles\ri\target\stage\jaxb-ri\samples\modify-marshal\gen-src\primer.po is not found and thus excluded from the dependency check
      [xjc] Compiling file:/C:/Users/ervelden/java/jaxb-v2/jaxb-ri/bundles/ri/target/stage/jaxb-ri/samples/modify-marshal/po.xsd
      [xjc] Writing output to C:\Users\ervelden\java\jaxb-v2\jaxb-ri\bundles\ri\target\stage\jaxb-ri\samples\modify-marshal\gen-src
      [xjc] Command invoked: xjc"C:\Program Files\Java\jdk1.8.0_144\jre\bin\java.exe"
      [xjc] failure in the XJC task. Use the Ant -verbose switch for more details

BUILD FAILED
C:\Users\ervelden\java\jaxb-v2\jaxb-ri\bundles\ri\target\stage\jaxb-ri\samples\modify-marshal\build.xml:65: xjc failed

I saw that com.sun.tools.xjc.XJCFacade de main class is in de executable jaxb-xjc.jar.
So instead of the `<xjc/>` above, I do :
or,
This works with java 8. I wanted to do:

but XJCFacade has no execute method.
pedro-w commented 6 years ago

I also had this error running the xjc task from an Ant script. Previous version 2.2.5 was OK. As far as I can see the task runs correctly but throws a BuildException anyway. Looking at the code: https://github.com/javaee/jaxb-v2/blob/5d4083371d10b541fee9b2f74ae32a0ea00fc95e/jaxb-ri/xjc/src/main/java/com/sun/tools/xjc/XJCBase.java#L729-L732 The variable ok is set to false on line 670 but, if the process is not forked (which I think is the default) then it is never set to true and the code will always throw the exception. Hope that helps.

ericjvandervelden commented 6 years ago

I found out that in your samples that in build.xml you must add thefork="true" attribute to the <xjc .../>. So for example in modify-marshal's build.xml:

<xjc schema=" po.xsd" package="primer.po" destdir="gen-src" fork="true">
...
</xjc>

When you do this, compile works, otherwise an error message appears. I think you should modify the samples at this point.

pedro-w commented 6 years ago

As a matter of interest what version of jaxb are you using? When I tried with 2.3.0 it wouldn't accept fork="true" as an attribute.

highsource commented 6 years ago

Another workaround is to set failonerror="false".

highsource commented 6 years ago

The problem is in com.sun.tools.xjc.XJCBase.execute(). There is a boolean ok variable which is set to true if and only if forked process returned status 0. The variable is not set to true in other cases - for instance if XJC is executed directly. However, the variable is checked later on in any case.

The fix is actually trivial: set ok to true after doXJC(); successfully completed.

Below is a reproducing test case.

jaxb2-sample-po-ant.zip

I can provide a pull request with a fix. But first please tell me if you'll be willing to accept it (I am an official contributor with signed OCA) and against which branch should it be (jaxb-2.3.0?). Don't get me wrong, I just don't want to invest time in a PR which will be in vain.

bravehorsie commented 6 years ago

It should be fixed already in master: https://github.com/javaee/jaxb-v2/pull/1170

On Sun, Jun 3, 2018 at 10:51 PM, Alexey Valikov notifications@github.com wrote:

The problem is in com.sun.tools.xjc.XJCBase.execute(). There is a boolean ok variable which is set to true if and only if forked process returned status 0. The variable is not set to true in other cases - for instance if XJC is executed directly. However, the variable is checked later on in any case.

The fix is actually trivial: set ok to true after doXJC(); successfully completed.

Below is a reproducing test case.

jaxb2-sample-po-ant.zip https://github.com/javaee/jaxb-v2/files/2066338/jaxb2-sample-po-ant.zip

I can provide a pull request with a fix. But first please tell me if you'll be willing to accept it (I am an official contributor with signed OCA) and against which branch should it be (jaxb-2.3.0?). Don't get me wrong, I just don't want to invest time in a PR which will be in vain.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/javaee/jaxb-v2/issues/1147#issuecomment-394190445, or mute the thread https://github.com/notifications/unsubscribe-auth/AI8ZtiDr8LO9PZ43cXlx3nrii3z0TC0Oks5t5ExugaJpZM4P4Dcb .

pedro-w commented 6 years ago

So, can this bug (and #1144) be closed?

Happy to test it if you need additional confirmation.

bravehorsie commented 6 years ago

closing..

On Mon, Jun 4, 2018 at 5:51 PM, pedro-w notifications@github.com wrote:

So, can this bug (and #1144 https://github.com/javaee/jaxb-v2/issues/1144) be closed?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/javaee/jaxb-v2/issues/1147#issuecomment-394404847, or mute the thread https://github.com/notifications/unsubscribe-auth/AI8Ztj0cVcPImLb4Hr0c07ICTJiw1n-9ks5t5Vd9gaJpZM4P4Dcb .