Pages

Tuesday, September 30, 2014

Problems using JAX-WS 2.1 and JAXB 2.1 with JDK1.6 ?

Recently while working on web services I faced following problem where I was bound to use jdk1.6 to create web service because current version of weblogic11g and 12c works on jdk1.6.

       [ERROR] COMPILATION ERROR : 
[INFO] -------------------------------------------------------------
[ERROR] /C:/Data/work/OSB/OSB_Workspace/SOASampleWS_HV3/src/generated/jaxws/at/spardat/soa/osb/soap/osbsoapexample/v1/OsbSoapExample.java:[46,9] C:\Data\work\OSB\OSB_Workspace\SOASampleWS_HV3\src\generated\jaxws\at\spardat\soa\osb\soap\osbsoapexample\v1\OsbSoapExample.java:46: cannot find symbol
symbol  : constructor Service(java.net.URL,javax.xml.namespace.QName,javax.xml.ws.WebServiceFeature[])
location: class javax.xml.ws.Service


I am using Maven and problem that I found that with wsimport code gets generated properly but while compiling generated code I get error as shown above. after investigation I found that code gets generated with JAV-WS2.1 as required but while compiling code with JDK1.6 java uses its own JAX-WS library provided in jdk which is older version and do not have this constructor defined in it. to overcome on this issue following is the way.

1. most simple approach is to copy jaxb-api.jar, jaxws-api.jar in your installed JDK1.6 /lib/endorsed directory.

2. if you do not want to do this and using wsimport/wsgen of JAX-WS2.1 then you can use endorse feature as WSIMPORT_OPTS=-Djava.endorsed.dirs=%JAXWS_HOME%/lib or WSGEN_OPTS=-Djava.endorsed.dirs=%JAXWS_HOME%/lib, option while calling your script, note that JAXWS_HOME points to your JAX-WS2.1 installation directory

3. if you are using maven to do the build of project then set following elements endoresedirs to your maven-compiler-plugin.

&ltplugin&gt
    &ltgroupId&gtorg.apache.maven.plugins&lt/groupId&gt
    &ltartifactId&gtmaven-compiler-plugin&lt/artifactId&gt
    &ltversion&gt3.1&lt/version&gt
        &ltconfiguration&gt
            &ltsource&gt1.6&lt/source&gt
            &lttarget&gt1.6&lt/target&gt
            &ltcompilerArguments&gt
             &ltendorseddirs&gt${project.build.directory}/endorsed&lt/endorseddirs&gt
           &lt/compilerArguments&gt
        &lt/configuration&gt
&lt/plugin&gt