4

The following command used to work flawlessly:

C:\tools\apache-cxf-3.3.1\bin\wsdl2java -client -d generated foo.wsdl

It no longer works with the latest version of JDK - 12. I have downloaded the latest version of Apache CXF, and still get the same error:

-Djava.endorsed.dirs=C:\tools\apache-cxf-3.3.1\bin\..\lib\endorsed is not supported. Endorsed standards and standalone APIs
in modular form will be supported via the concept of upgradeable modules.
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.

Could anyone offer a tip on how to remedy this?

Hong
  • 17,643
  • 21
  • 81
  • 142
  • 1
    The endorsed standard override mechanism was deprecated in a Java SE 8 update and removed in Java SE 9. I don't know anything about Apache XCF but do they have a version that runs on JDK 9 and newer? – Alan Bateman Apr 03 '19 at 06:41
  • @AlanBateman according to their FAQ, it supports Java 9+ http://cxf.apache.org/faq.html#FAQ-CanCXFrunwithJDK/Java9+(10,11)? – Hong Apr 03 '19 at 09:40
  • 1
    I don't know anything abut Apache CXF but that web page says "CXF will support Java 9-11 with the next 3.3.x release". The file path in your question suggests you are using 3.1.6. In any case, the endorsed standards override mechanism has been removed since JDK 9. – Alan Bateman Apr 03 '19 at 10:17
  • @AlanBateman I am sorry but 3.1.6 is a typo. I was using 3.3.1. I have just corrected it. – Hong Apr 03 '19 at 10:28
  • @AlanBateman I am no expert in CXF. wsdl2java is the only thing of CXF that I use once in a while. This is why I am asking the question here. I really appreciate your trying to help out. – Hong Apr 03 '19 at 11:38
  • @AlanBateman I have little knowledge of the inner workings of wsdl2java. All I know is that it reads a file and other files pointed to by the file, creates a directory and its sub-directories, and produce many files in those sub-directories. – Hong Apr 04 '19 at 11:31
  • If bin/wsdl2java is specifying -Djava.endorsed.dirs on the command line then this is a bug in this tool, it should not set it when running on JDK 9 or newer. All I can suggest is check the script and if it is setting this property then submit a bug that it does not work on JDK 9 or newer. – Alan Bateman Apr 04 '19 at 12:47
  • I installed Java 8 and apache-cxf-3.3.1 works with it flawlessly now. This is the easiest and quickest solution for me until someone from Apache CFX team sheds some light on this. – Hong Apr 04 '19 at 15:57
  • Make sure to submit a bug to Apache CFX to upgrade their scripts to work with JDK 9 or newer. It is surprising that the website suggests it works on newer releases when the scripts haven't been updated. – Alan Bateman Apr 07 '19 at 08:25
  • Hi @Hong, I think I'm having the same issue, can you please update what you did please. Thanks! – Pasan Eeriyagama Apr 17 '19 at 02:39

1 Answers1

5

I got the Apache CXF 3.3.1 wsdl2java utility to work with the latest OpenJDK 11 by doing 4 things:

  1. Pull down this jar and place it into the {CXF_HOME}/lib directory: https://mvnrepository.com/artifact/javax.jws/jsr181-api/1.0-MR1
  2. Pull down this jar and also place it in the {CXF_HOME}/lib directory: https://mvnrepository.com/artifact/javax.xml.ws/jaxws-api/2.3.1
  3. In my case, since I'm running on a Mac, I vi'd the wsdl2java script and made sure these two jars are explicitly being set on the CXF classpath, by doing the following declaration within the script right before the execution of the java command:cxf_classpath=${cxf_classpath}:../lib/jaxws-api-2.3.1.jar:../lib/jsr181-api-1.0-MR1.jar

  4. Lastly, I removed the '-Djava.endorsed.dirs="${cxf_home}/lib/endorsed"' parameter from the java command at the end of the script, since newer JDKs no longer support this argument, so my command now looks like this:$JAVA_HOME/bin/java -Xmx${JAVA_MAX_MEM} -cp "${cxf_classpath}" -Djava.util.logging.config.file=$log_config org.apache.cxf.tools.wsdlto.WSDLToJava "$@"

Now, using OpenJDK11, I'm able to point to an external WSDL file and successfully generate the client code I need to consume this SOAP service with the following command:

./wsdl2java -client -d src https://somewhere.com/service\?wsdl

Whether or not this all works yet is TBD in terms of being able to call and consume the SOAP service I'm coding against, but I've at least now overcome the Java9+ support issue with this tool specific to generating client code from a WSDL.

If your needs are different, I would at least remove the '-Djava.endorsed.dirs="${cxf_home}/lib/endorsed"' JVM parameter and start calling the wsd2java command with the parameters you need set and just start iteratively adding back in the missing libs it starts throwing java.lang.NoClassDefFoundError errors for.

Their FAQ specifically says starting in 3.3.x, Java 9+ will be supported but something clearly dropped the ball between the no-longer-supported hardcoded JVM arguments still being passed in the utility and the missing libraries to support the newer JDKs where these legacy libs have been removed.

Hope this helps someone out there unfortunate enough to ALSO still be programming against SOAP endpoints but trying to at least keep the client-side code you're writing up to date and taking advantage of the newer features of the modern JDK.

Youssef NAIT
  • 1,362
  • 11
  • 27
  • Thank you for the answer. I am using Windows. It is much easier for me to use Java 8 to solve this problem. I have not tested your answer that may work on a Windows machine as well, but I have accepted your answer. – Hong Apr 13 '19 at 17:33
  • I can't believe I found an answer for this. – geochr Apr 16 '20 at 15:25
  • Sure this will execute the code generation but your generated code will not compile with Java 11+ because packages such as javax.xml.bind.annotation have been deleted. – Mark Oct 27 '21 at 13:22