javac cannot find symbol constructor Service
Asked Answered
G

3

8

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?

Gorgeous answered 3/1, 2013 at 0:40 Comment(3)
What version of Java are you using to build your samples?Braddy
The source code you mentioned builds just fine for me with Java 1.6, Ant 1.8.2, Mac OS X 10.7.5. Can you confirm your system stats, and that you have not modified the downloaded source project in any way?Braddy
@Braddy The CXF version is more critical, as implied by #10448829Eversion
E
15

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.

Eversion answered 3/1, 2013 at 18:23 Comment(1)
The %JAVA_HOME%\jre\lib (vs. what I did which was %JAVA_HOME%\lib) was it. Thank you.Gorgeous
T
0

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.

Thamora answered 3/1, 2013 at 1:28 Comment(0)
B
0

Adding webservices-api-2.2.jar alone in %JAVA_HOME%\jre\lib\endorsed has resolved issue for me.

Byelostok answered 22/5, 2014 at 10:52 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.