Java – How to force Java 8 wsimport command-line to generate 1.6 target compatible code


I'm trying to upgrade an existing build system to use Java 8 instead of a Java 5/6 compiler, however, I still have to generate outputs compatible with Java 5/6. Overall this is trivial (-target 1.6), but I am having difficulty doing so with code generated from wsimport (using the version in JDK 8 bin).

I'm using Java HotSpot 64-bit server VM (build 25.20-b23), JDK 1.8.0_20.

The wsimport command is being called from a command-line to generate code and the outputs packaged directly from there. For legacy reasons I am unable to change this process (such as to use ant), so I need to solve the problem from the command-line.

What I run is: "wsimport WSDL_FILE" (actual file doesn't matter)
then run "javap -verbose CLASS | grep major" on any of the classes in the output to check the version: it always comes out 52.

I've tried using -J argument to wsimport to pass options to the javac compiler, however none of the below have worked:

wsimport "-J-target 1.6" WSDL  (fails with unrecognized option -target 1.6" coming from wsimport)
wsimport "" WSDL  (no effect)
wsimport "" WSDL (no effect)

Presumably there's either some variation on passing the target through that works or some property settings that should work; if it's one I'm using, then I haven't figured out how to pass it correctly.

Best Solution

Assuming that wsimport creates Java 6 compatible source code, no reason it shouldn't, but who knows, then the solution is to simply add -Xnocompile to wsimport, and then build the source directly yourself, using whatever mechanism is comfortable for your process.