How to force Java 8 wsimport command-line to generate 1.6 target compatible code
Asked Answered
M

1

7

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 "-J-Djavac.target=1.6" WSDL  (no effect)
wsimport "-J-Djavac.opt.target=1.6" 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.

Metcalf answered 23/10, 2014 at 16:56 Comment(0)
K
4

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.

Koetke answered 23/10, 2014 at 17:9 Comment(1)
Nice! I believe that will work, that I can reasonably incorporate a second command where the build occurs. I'll accept once I prove that works (until then, if anyone knows how to fix within wsimport, would love to know).Metcalf

© 2022 - 2024 — McMap. All rights reserved.