问题
I am in the process of learning CXF with the help of this Apache CXF Web Service Development book but, alas, one of the book's sample projects won't even compile!
The code in question is Chapter 3's contractfirst
and it's not a typo problem because I am using the source code verbatim as downloaded from the book's support site.
The 3 compilation errors point actually to a single problem:
Chapter3\contractfirst\src\demo\order\OrderProcessService.java:52: cannot find symbol
symbol: constructor Service(java.net.URL,javax.xml.namespace.QName,javax.xml.ws.WebServiceFeature[])
location: class javax.xml.ws.Service
super(WSDL_LOCATION, SERVICE, features);
^
In the file OrderProcessService.java.
Initial research suggests that this may be a JAX-WS 2.2 vs. 2.1 issue but I have no idea how to make this ANT-based compilation environment "endorse" JAX-WS 2.2.
I tried placing a jaxws-api.jar
in %JAVA_HOME%\lib\endorsed
and I tried adding that jar to the project's libraries list but none seemed to help.
I am not using Maven, so I can't even list it as a dependency and hope that this will be magically resolved.
Any idea how to solve this problem? So that I can make this very simple project build?
回答1:
From your description this sounds similar to the problem described in this post.
To get around this issue, You can simply copy jaxb-api.jar
, jaxws-api.jar
to JDK's JRE's
/lib/endorsed
Note that "endorsing" means placing the relevant JAR files (jaxb-api.jar, jaxws-api.jar in this case) in %JAVA_HOME%\jre\lib\endorsed
(note the jre
in the path). Do not create the endorsed directory directly under the JDK's lib directory.
or... if you prefer not to touch your JDK install, use these env vars is using wsimport and wsgen (where JAXWS_HOME points to JAX-WS 2.1 installation):
WSIMPORT_OPTS=-Djava.endorsed.dirs=%JAXWS_HOME%/lib
WSGEN_OPTS=-Djava.endorsed.dirs=%JAXWS_HOME%/lib
or... If you use ant tasks, you can pass -Djava.endorsed.dirs=%JAXWS_HOME%/lib
as jvmarg while calling wsimport and wsgen ant tasks (for this to work, you need to set fork="true" attribute of wsimport and wsgen ant tasks).
Credit goes to Rama Pulavarthi.
回答2:
Endorsing the 2.2 version of the jaxws-api jar should work. You could also pass the "-fe jaxws21" flag to the CXF wsdl2java command to make it generate 2.1 compatible code instead.
回答3:
Adding webservices-api-2.2.jar alone in %JAVA_HOME%\jre\lib\endorsed has resolved issue for me.
来源:https://stackoverflow.com/questions/14131503/javac-cannot-find-symbol-constructor-service