JAXB 1.0 - can I compile using 1.7 JDK? - jaxb

I've inherited a pretty old Ant project, and been asked to 'upgrade it to java 1.7'.
Currently the project is 1.5, and has a mix of JAXB 1.0 and JAXB 2.0.
JAXB 2.0 bits upgrade fine, but when I try and upgrade the JAXB 1.0 bits to jdk1.7 I get errors such as;
Executing 'C:\Program Files\Java\jdk1.7.0_51\bin\java.exe' with arguments:
'-classpath'
'C:\Users\xyz123\development\proj\lib-common\JAXB1\jaxb-xjc-1.0-ea.jar'
'com.sun.tools.xjc.Main'
'C:\Users\xyz123\development/proj/xml/dtd/doodah.dtd'
'C:\Users\xyz123\development/proj/xml/xjs/doodah.xjs'
'-d'
'C:\Users\xyz123\development/proj/packages/mis-reports/doodah/xml'
The ' characters around the executable and arguments are
not part of the command.
An error has occurred in the JAXB compiler.
Please submit a bug report to jaxb-feedback#java.sun.com
containing your input files as well as the output below.
java.lang.NoSuchFieldError: INITIAL_COLOR
at javax.xml.bind.ValidatableObject.<init>(ValidatableObject.java:32)
at javax.xml.bind.MarshallableObject.<init>(MarshallableObject.java:54)
at javax.xml.bind.MarshallableRootElement.<init>(MarshallableRootElement.java:97)
at com.sun.tools.xjc.dtdx.DTDX.<init>(DTDX.java:57)
at com.sun.tools.xjc.dtd.DTD.convert(DTD.java:113)
at com.sun.tools.xjc.dtd.DTDParser.parse(DTDParser.java:92)
at com.sun.tools.xjc.Main.doCompile(Main.java:85)
at com.sun.tools.xjc.Main.compile(Main.java:106)
at com.sun.tools.xjc.Main.main(Main.java:275)
Anyone got any ideas? I don't see much (if any) info on running jaxb 1.0 on a recent JDK.

It seems to me that this is an impossible task because;
JAXB 1.0 and JAXB 2.0 implementations are different, i.e. JAXB 1.0 requires javax.xml.bind.MarshallerObject which does not exist in JAXB 2.0
JAXB 2.0 is provided in the 1.7 runtime
JAXB 2.0 classes will always be present when trying to compile JAXB 1.0 against 1.7jdk
So unless there is some way to load the JAXB 1.0 runtime before the JDK runtime, I think I am stumped.

It also looks like JAXB 2.0 turns element values (rather than attributes) into 'value' rather than JAXV 1.0 'content' so any code getters/setters will have to change to the corresponding getter/setter.

Related

Java 14 support in Groovy?

All groovyconsole binary distros I have found don't support Java 14. The console complains if you try to specify a Jar file that has been compiled with Java 14, for example.
The obvious solution, I thought, was to build Groovy with Java 14. That seems non-trivial.
gradle.wrapper.properties files contain
distributionUrl=http://services.gradle.org/distributions/gradle-2.3-bin.zip
which is a broken URL. Change that to https and then it works, partially.
You then get
FAILURE: Build failed with an exception.
What went wrong:
Could not determine java version from '14.0.2'.
Reading the docs for gradle makes it clear that most (all?) versions of gradle do not support Java 14. Definitely version 2.3 does not. Why - I have no idea.
So... back to my original question. How can I get a groovy installation to support Java 14?
Thanks!
If the Jar cannot be loaded, it is most likely the asm lib, which is unable to read it. To read Java14 you need at least ASM 7.2 I think. ASM in Groovy is not provided as standalone library, because of possible conflicts with other jar dependencies it is shadowed (bytecode is transformed by renaming the packages and directly added to the Groovy jar). I see here 2 options:
compile Groovy yourself and change the dependencies to have at least ASM 7.2. It does not matter if you build Groovy with a lower version of the JDK, the JDK still allows to read "old" jars.
use at least Groovy 2.5.9, 3.0.0 or 2.4.19, as they include asm 7.2 or higher
Of course this does not mean it will change the Groovy Gradle is using easily. For that I would use Groovy 2.5 and read Bumping Groovy version in Gradle?
If this does not solve the problem or answer the question I would need more details.

Groovy-Eclipse 2.5.2: java.lang.ClassNotFoundException: picocli.CommandLine$ParameterException

I'm using Eclipse 4.5 with the Groovy-Eclipse 2.9.2/4.5 plugin which I thought was supposed to have the Groovy 2.5 compiler. However, it didn't have any picocli support so I added the groovy-cli-picocli-2.5.2-indy.jar to my classpath and was able to compile. However #2, when trying to run the script via Eclipse I get:
java.lang.ClassNotFoundException: picocli.CommandLine$ParameterException
It looks like groovy-cli-picocli-2.5.2-indy.jar does not have CommandLine class at all.
I would just throw jars at this from the fullblown picocli distribution but I'm under the impression they all have to somehow wrap nicely into Eclipse Groovy library via groovy.cli.picocli.CliBuilder.
Is my Groovy 2.5.2 missing this or am I somehow missing the boat on how it's supposed to work because picocli is not working for me in this configuration. Thanks!
You are correct: groovy-cli-picocli-2.5.2.jar (and groovy-cli-picocli-2.5.2-indy.jar) do not contain the picocli classes.
You need to add the picocli jar to the classpath.
If you use Maven, the groovy-all POM should include all dependencies.
(My original answer mentioned picocli classes that are shaded into the groovy-2.5.x.jar under the groovyjarjarpicocli package but these are intended for use internally by Groovy and not meant to be used by applications.)

Java 8 Javadoc vs. XJC Warnings & Errors

How do I use xjc to generate Java code from xsd files which have 0 Javadoc Warnings and Errors at build time when using Java 8 and not changing which Doclint being used?
I'm using an Apache-Ant build.xml file to build the codebase.
I can't.
According to JAXB, those build problems are not blockers, "since workaround is to pass -Xdoclint:none to javadoc executable". =(
Yes, it is possible to hand-edit the generated Java files to get 0 Warnings and 0 Errors, but my main goal is to generate Java files that do not require hand edits (or custom plugins) under any and all circumstances.

java.lang.NoClassDefFoundError: Could not initialize class org.apache.poi.openxml4j.opc.internal.marshallers.ZipPackagePropertiesMarshaller

I am trying to generate Excel using Xssf API because its memory footprint is small.
It is working fine in my local machine which is having jdk1.7.
But when I try to run it on UNIX where java version is 1.6.0_75 it gives me the following error.
java.lang.NoClassDefFoundError: Could not initialize class org.apache.poi.openxml4j.opc.internal.marshallers.ZipPackagePropertiesMarshaller
I have following jars in my classpath
poi-3.11-20141221.jar
poi-excelant-3.11-20141221.jar
poi-ooxml-3.11-20141221.jar
poi-ooxml-schemas-3.11-20141221.jar
xmlbeans-2.6.0.jar
xercesImpl.jar
I have verified that poi-3.11-20141221.jar has the ZipPackagePropertiesMarshaller class.
Seems that some jar is missing.
Am I missing something?
I have found a solution to my own problem.
I replaced poi-3.11-20141221.jar with poi-ooxml-3.9.jar. That worked.
Java version 1.6.0_75 does not exists, I suppose you make a typo. The last update of Java 6 is the update 45 (6u45).
The class ZipPackagePropertiesMarshaller is loaded at run-time for sure. The exception NoClassDefFoundError occurs during the initialization phase; if the exception had been ClassNotFoundException, it would have been different...
The class ZipPackagePropertiesMarshaller is unaltered between the versions 3.11 and 3.9, but the class PackagePropertiesMarshaller extended by ZipPackagePropertiesMarshaller is changed: the main change regards the use of StAX in the newer version.
The distribution of StAX coming with Java 6, but the version of Java 6 update 18 (http://www.oracle.com/technetwork/java/javase/6u18-142093.html) introduces the StAX 1.2 API version.
Consider to use Java 6u18 or newer. This should solve your problem.
In the official FAQ there are some indications about a similar problem: https://poi.apache.org/faq.html#faq-N1017E.
Moreover, the workaround you found is not the best one, see the last FAQ of POI.

How tell which jdk contains which versions of JAX-WS

There's a fix in one of the more recent versions of JAXB (2.2.1). I'm trying to determine if that's included in a recent update to Java 6. Is there a way to tell which which versions of a JVM/JRE/JDK contain which versions of JAX-WS/JAXB?
Looking at Sun/Oracle's site, I can view the release notes for the latest versions of Java SE 6, but I can't tell which versions of the XML libs are included. I guess I could download the latest JDK and run 'xjc -version', but there should be a better way (esp. if it was added in a previous release - I don't want to keep downloading JREs to tell which was the first with the version of JAXB I'm interested in).
To my knowledge, libraries are not upgraded on each released of the JDK/JRE, except in major versions. Even then, I don't think they cross the minor-version line.
And, to answer your unwritten question, this is the output from xjc -version on JDK 1.6.0_24:
xjc version "JAXB 2.1.10 in JDK 6"
JavaTM Architecture for XML Binding(JAXB) Reference Implementation, (build JAXB
2.1.10 in JDK 6)
2.1.10 was released on February 6th, 2009, which was updated in Java 6u14.

Resources