How to get Java 8 wsimport command line to generate 1.6 target compatible code

I am trying to upgrade an existing build system to use Java 8 instead of the Java 5/6 compiler, however I still have to create Java 5/6 compatible outputs. This is generally trivial (-target 1.6), but I am having difficulty with code created from wsimport (using the version in JDK 8 bin).

I am using the 64-bit Java HotSpot virtual machine (build 25.20-b23), JDK 1.8.0_20.

The wsimport command is called from the command line to generate code and outputs packaged directly from there. For old reasons, I cannot change this process (for example, use ant), so I need to solve the problem from the command line.

What I ran: "wsimport WSDL_FILE" (the actual file does not 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 tried using the -J argument to wsimport to pass parameters to the javac compiler, however none of the following 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 is either some kind of variation regarding the transfer of the target through this, or some properties parameters that should work; if I use it, then I do not understand how to transfer it correctly.

+6
source share
1 answer

Assuming wsimport is creating Java 6 compatible source code, for some reason it shouldn't, but who knows, then the solution is to simply add -Xnocompile to wsimport and then build the source yourself using any mechanism, convenient for your process.

+3
source

Source: https://habr.com/ru/post/977144/


All Articles