java - Cannot import webservice stubs in client -
i trying learn jax-ws , created simple bottom-up helloworld webservice in order train myself:
import org.jboss.annotation.ejb.localbinding; import javax.ejb.remote; import javax.ejb.stateless; import javax.jws.webmethod; import javax.jws.webservice; import javax.jws.soap.soapbinding; @webservice(servicename = "helloworldwebserviceexperiment", portname = "helloworldport", name = "helloworld") @soapbinding(style = soapbinding.style.document, use = soapbinding.use.literal, parameterstyle = soapbinding.parameterstyle.wrapped) @stateless @remote @localbinding(jndibinding = "training.webservice.helloworldwebserviceremote/local") public class helloworldwebservicebean { private static final string hello_world = "hello world"; @webmethod public string helloworld() { return hello_world; } }
when deploy webservice can access wsdl, seems work fine. tried generate webservice client. , needed create stubs, tried create maven plugin jaxws-maven-plugin. here pom.xml:
<?xml version="1.0" encoding="utf-8"?> <project xmlns="http://maven.apache.org/pom/4.0.0" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xsi:schemalocation="http://maven.apache.org/pom/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelversion>4.0.0</modelversion> <groupid>training.webservice</groupid> <artifactid>helloworldwebserviceexperiment</artifactid> <version>1.0-snapshot</version> <packaging>war</packaging> <properties> <wsdlpath>${project.build.directory}</wsdlpath> </properties> <build> <plugins> <plugin> <groupid>org.apache.maven.plugins</groupid> <artifactid>maven-compiler-plugin</artifactid> <version>2.3</version> <configuration> <source>1.5</source> <target>1.5</target> </configuration> <executions> <execution> <goals> <goal>compile</goal> </goals> </execution> </executions> </plugin> <plugin> <groupid>org.apache.maven.plugins</groupid> <artifactid>maven-war-plugin</artifactid> <configuration> <webresources> <resource> <targetpath>web-inf</targetpath> <directory>src/main/webapp/web-inf</directory> <includes> <include>web.xml</include> </includes> <filtering>true</filtering> </resource> </webresources> </configuration> </plugin> <plugin> <groupid>org.codehaus.mojo</groupid> <artifactid>jaxws-maven-plugin</artifactid> <executions> <execution> <id>genwsdl</id> <phase>process-classes</phase> <goals> <goal>wsgen</goal> </goals> <configuration> <genwsdl>true</genwsdl> <sei>training.webservice.helloworldwebservicebean</sei> </configuration> </execution> <execution> <id>consumewsdlforstubs</id> <phase>process-classes</phase> <goals> <goal>wsimport</goal> </goals> <configuration> <wsdldirectory>target/jaxws/wsgen/wsdl</wsdldirectory> <wsdlfiles> <wsdlfile>helloworldwebserviceexperiment.wsdl</wsdlfile> </wsdlfiles> <keep>true</keep> <destdir>target/classes</destdir> <sourcedestdir>target/stubs</sourcedestdir> <verbose>true</verbose> </configuration> </execution> </executions> </plugin> <plugin> <groupid>org.apache.maven.plugins</groupid> <artifactid>maven-jar-plugin</artifactid> <executions> <execution> <id>package-wsclient-jars</id> <phase>package</phase> <goals> <goal>jar</goal> </goals> <configuration> <classesdirectory>target/stubs</classesdirectory> <classifier>wsclient</classifier> </configuration> </execution> </executions> </plugin> </plugins> </build> <dependencies> <!-- jax-ws annotations --> <dependency> <groupid>javax.jws</groupid> <artifactid>jsr181-api</artifactid> <version>1.0-mr1</version> <scope>provided</scope> </dependency> <dependency> <groupid>jboss</groupid> <artifactid>jbossws-spi</artifactid> <version>1.0.0.ga</version> <scope>provided</scope> </dependency> <dependency> <groupid>org.jboss</groupid> <artifactid>jboss-ejb3x</artifactid> <version>4.2.2</version> <!--<scope>provided</scope>--> </dependency> <dependency> <groupid>jboss</groupid> <artifactid>jboss-annotations-ejb3</artifactid> <version>4.2.2.ga</version> <!--<scope>provided</scope>--> </dependency> <dependency> <groupid>org.jboss</groupid> <artifactid>jboss-jaxws</artifactid> <version>4.2.2</version> <scope>provided</scope> </dependency> </dependencies>
the build maven generate follwoing output , .jar file generated .java files:
> mvn clean install [info] scanning projects... [info] ------------------------------------------------------------------------ [info] building unnamed - training.webservice:helloworldwebserviceexperiment:war:1.0-snapshot [info] task-segment: [clean, install] [info] ------------------------------------------------------------------------ [info] [clean:clean {execution: default-clean}] [info] deleting directory ---/helloworldwebserviceexperiment/target [info] [resources:resources {execution: default-resources}] [warning] using platform encoding (utf-8 actually) copy filtered resources, i.e. build platform dependent! [info] copying 0 resource [info] [compiler:compile {execution: default-compile}] [warning] file encoding has not been set, using platform encoding utf-8, i.e. build platform dependent! [info] compiling 2 source files ---/helloworldwebserviceexperiment/target/classes [info] [compiler:compile {execution: default}] [info] nothing compile - classes date [info] [jaxws:wsgen {execution: genwsdl}] [info] [jaxws:wsimport {execution: consumewsdlforstubs}] [info] processing: ---/helloworldwebserviceexperiment/target/jaxws/wsgen/wsdl/helloworldwebserviceexperiment.wsdl [info] jaxws:wsimport args: [-s, ---/ /helloworldwebserviceexperiment/target/jaxws/wsimport/java, -d, ---/helloworldwebserviceexperiment/target/classes, -verbose, -xnocompile, ---/helloworldwebserviceexperiment/target/jaxws/wsgen/wsdl/helloworldwebserviceexperiment.wsdl] parsing wsdl... generating code... training/webservice/helloworld.java training/webservice/helloworldresponse.java training/webservice/helloworldwebserviceexperiment.java training/webservice/helloworld_type.java training/webservice/objectfactory.java training/webservice/package-info.java [info] [resources:testresources {execution: default-testresources}] [warning] using platform encoding (utf-8 actually) copy filtered resources, i.e. build platform dependent! [info] skip non existing resourcedirectory ---/helloworldwebserviceexperiment/src/test/resources [info] [compiler:testcompile {execution: default-testcompile}] [info] nothing compile - classes date [info] [surefire:test {execution: default-test}] [info] no tests run. [info] [war:war {execution: default-war}] [info] packaging webapp [info] assembling webapp[helloworldwebserviceexperiment] in [---/helloworldwebserviceexperiment/target/helloworldwebserviceexperiment-1.0-snapshot] [info] processing war project [info] copying webapp webresources[---/helloworldwebserviceexperiment/src/main/webapp/web-inf] to[---/helloworldwebserviceexperiment/target/helloworldwebserviceexperiment-1.0-snapshot] [info] copying webapp resources[---/helloworldwebserviceexperiment/src/main/webapp] [info] webapp assembled in[33 msecs] [info] building war: ---/helloworldwebserviceexperiment/target/helloworldwebserviceexperiment-1.0-snapshot.war [info] [jar:jar {execution: package-wsclient-jars}] [warning] jar empty - no content marked inclusion! [info] building jar: ---/helloworldwebserviceexperiment/target/helloworldwebserviceexperiment-1.0-snapshot-wsclient.jar [info] [install:install {execution: default-install}] [info] installing ---/helloworldwebserviceexperiment/target/helloworldwebserviceexperiment-1.0-snapshot.war ~/.m2/repository/training/webservice/helloworldwebserviceexperiment/1.0-snapshot/helloworldwebserviceexperiment-1.0-snapshot.war [info] installing ---/helloworldwebserviceexperiment/target/helloworldwebserviceexperiment-1.0-snapshot-wsclient.jar ~/.m2/repository/training/webservice/helloworldwebserviceexperiment/1.0-snapshot/helloworldwebserviceexperiment-1.0-snapshot-wsclient.jar [info] ------------------------------------------------------------------------ [info] build successful [info] ------------------------------------------------------------------------ [info] total time: 2 seconds [info] finished at: tue aug 25 09:31:20 cest 2015 [info] final memory: 32m/487m [info] ------------------------------------------------------------------------
edit (for precision): when try use stub archive in project create webclient, (i intellij idea), idea automatically finds file maven repository , suggests me, generating following dependency:
<dependency> <groupid>training.webservice</groupid> <artifactid>helloworldwebserviceexperiment</artifactid> <version>1.0-snapshot-wsclient</version> </dependency>
however none of genereated .java files can imported , used in code! e.g. idea fails on usage or import
import training.webservice.helloworld; private training.webservice.helloworld helloworld;
with error message "cannot resolve symbol 'helloworld'" doing wrong? connected fact stub contains .java files, no .class files? plugin jaxws-maven-plugin runs wsimport -xnocompile flag, haven't been able figure out how configure maven not that, none of options keep, destdir or sourcedestdir have had effect on that! or irrelevant, project importing stubs should able compile them , problem somewhere else? appreciated!
i found temporary work arround: generate client stub .jar file manually. company still works java 1.5, had install metro in order use wsimport (i chose version 1.6.2) , call:
wsimport target/generated-sources/wsdl/helloworldwebserviceexperiment.wsdl -d target/generated-sources/wsdl/ -keep
afterwards had .java , .class files manually package .jar file, moved .jar ressource folder of webservice client project , manually added dependency pom.xml:
<dependency> <groupid>training.webservice</groupid> <artifactid>helloworldwebserviceexperiment</artifactid> <version>1.0</version> <scope>system</scope> <systempath>${project.basedir}/src/main/resources/client.jar</systempath> </dependency>
i prefer automatic build , deploy maven, , sure problem must lie within maven setup, have still no clue how better. @ least can continue working on webservice client now, , revisit issue @ later point again!
Comments
Post a Comment