aspose file tools*
The moose likes EJB and other Java EE Technologies and the fly likes Eclipse 3.3, Glassfish, WebServices and wsimport Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Eclipse 3.3, Glassfish, WebServices and wsimport" Watch "Eclipse 3.3, Glassfish, WebServices and wsimport" New topic
Author

Eclipse 3.3, Glassfish, WebServices and wsimport

Stephanie Hehreuer
Greenhorn

Joined: Jul 22, 2007
Posts: 4
These are a beginner's dumb questions. More about eclipse than Glassfish, perhaps.

I'm using eclipse 3.3 with Glassfish on Mac OS X. I'm attempting to build a toy "Hello World" level web service example, both the service and a client to connect to it.

Deploying the web service to Glassfish, from within eclipse, was easy: "Run As -> Run on server". Bingo; code compiled, web service deployed and running.

The client side is what I'm struggling to do from within eclipse, and maybe there isn't a way to do that? The examples I've encountered online for this all seem to, in a shell, manually invoke the wsimport script to generate the client-side stub classes from the web service's WSDL file. Is there a way to perform this step from within eclipse? Or is it not integrated into the JavaEE perspective, and you really must drop outside eclipse to do it?

And if that's true, I can't quite figure out how to generate the stubs into a place in the client project in eclipse, in a way that eclipse can see and use those classes in the client code. I know I need to modify the client project's build path. Is there a canonical way people do this -- I mean, do they generate the stub classes in <client-project>/build/classes? (I can't seem to make eclipse be happy about a path beneath there...) Surely you don't generate the stub classes into the web service project?? Or do I plop them into the client project in (say) <client-project>/wsimports (i.e., a new directory not below the "build" directory that eclipse makes)?

Told you they were dumb questions. :-) Thanks in advance, --SR
purushottaman dwarkanathan
Greenhorn

Joined: Apr 26, 2005
Posts: 25
I had done a sample web service project in eclipse europa with the glassfish server integrated. This program invokes a web service via Java

Since it is using the new spec JAX-WS and not the AXIS java2WSDL and WSDL2Java conversion, the implementation is slightly different.

Since, it seems that you have been able to deploy and run the project, your main concern was about generating the artifacts from the eclipse.

Here are a few suggestions, which will assist you...

You need to write a build file. Open it from the ant view in eclipse .

goto menu window ---> show view --other --ANT

Run the tasks and the wsimport and wsgen will run and place the files in the respective folders.

I am pasting a sample build file, you can modify that according to your needs

My src directory name is fromjava.

This is how my deploy-targets.xml looks like

<project>
<property environment="env"/>

<property name="as.home" value="${env.AS_HOME}"/>
<property name="lib.home" value="${env.JAXWS_HOME}/lib"/>
<property name="lib.sample.home" value="${basedir}/../lib"/>
<property name="build.home" value="${basedir}/build"/>
<property name="build.war.home" value="${build.home}/war"/>
<property name="build.classes.home" value="${build.home}/classes"/>

<property name="domain" value="domain1"/>

<target name="deploy" depends="deploy-tomcat, deploy-appserver"/>

<target name="deploy-appserver" unless="tomcat">
<copy file="${build.war.home}/jaxws-${ant.project.name}.war"
todir="${as.home}/domains/${domain}/autodeploy"/>
</target>

<target name="deploy-tomcat" if="tomcat">
<copy file="${build.war.home}/jaxws-${ant.project.name}.war"
todir="${env.CATALINA_HOME}/webapps"/>
</target>
</project>

THis is the build.xml file

<?xml version="1.0" encoding="UTF-8"?>

<project basedir="." default="help" name="fromjava">

<import file="etc/deploy-targets.xml"/>

<path id="jaxws.classpath">
<pathelement location="${java.home}/../lib/tools.jar"/>
<pathelement location="${lib.sample.home}/jaxwsSampleUtils.jar"/>
<fileset dir="${lib.home}">
<include name="*.jar"/>
<exclude name="j2ee.jar"/>
</fileset>
</path>


<taskdef name="apt" classname="com.sun.tools.ws.ant.Apt">
<classpath refid="jaxws.classpath"/>
</taskdef>

<taskdef name="wsimport" classname="com.sun.tools.ws.ant.WsImport">
<classpath refid="jaxws.classpath"/>
</taskdef>


<target name="setup">
<mkdir dir="${build.home}"/>
<mkdir dir="${build.classes.home}"/>
<mkdir dir="${build.war.home}"/>
</target>

<target name="build-server-java" depends="setup">
<apt
fork="true"
debug="true"
verbose="${verbose}"
destdir="${build.classes.home}"
sourcedestdir="${build.classes.home}"
sourcepath="${basedir}/src">
<classpath>
<path refid="jaxws.classpath"/>
<pathelement location="${basedir}/src"/>
</classpath>
<option key="r" value="${build.home}"/>
<source dir="${basedir}/src">
<include name="**/server/*.java"/>
<include name="**/common/*.java"/>
</source>
</apt>
<!-- copy handlers descriptor file -->
<copy todir="${build.classes.home}">
<fileset dir="${basedir}/src">
<include name="**/server/**/*.xml"/>
</fileset>
</copy>
</target>

<target name="clean">
<delete dir="${build.home}" includeEmptyDirs="true"/>
</target>

<target name="create-war">
<war warfile="${build.war.home}/jaxws-${ant.project.name}.war" webxml="etc/web.xml">
<webinf dir="${basedir}/etc" includes="sun-jaxws.xml"/>
<zipfileset
dir="${basedir}/etc"
includes="*.wsdl, *.xsd"
prefix="WEB-INF/wsdl"/>
<classes dir="${build.classes.home}"/>
</war>
</target>

<target name="generate-client" depends="setup">
<wsimport
debug="true"
verbose="${verbose}"
keep="true"
destdir="${build.classes.home}"
package="fromjava.client"
wsdl="http://localhost:8080/jaxws-fromjava/addnumbers?wsdl">
</wsimport>
</target>

<target name="client" depends="generate-client">
<javac
fork="true"
srcdir="${basedir}/src"
destdir="${build.classes.home}"
includes="**/client/**,**/common/**">
<classpath refid="jaxws.classpath"/>
</javac>
</target>

<target name="run">
<java fork="true" classname="fromjava.client.AddNumbersClient">
<classpath>
<path refid="jaxws.classpath"/>
<pathelement location="${build.classes.home}"/>
<pathelement location="${basedir}/etc"/>
</classpath>
</java>
</target>

<target name="help">
<echo message="server: Builds and deploy the service endpoint WAR"/>
<echo message="client: Builds the client"/>
<echo message="run: Runs the client"/>
<echo message="server-j2se: Builds and deploy the Endpoint API based service"/>
<echo message="server-j2se-stop: Stops Endpoint API based service"/>

</target>

<target name="server" depends="setup">

<antcall target="clean"/>

<antcall target="build-server-java"/>

<antcall target="create-war"/>

<antcall target="deploy"/>
</target>

<target name="server-j2se" depends="setup">
<antcall target="clean"/>

<antcall target="build-server-java"/>

<echo message="Starting endpoint... To stop: ant server-j2se-stop "/>

<java fork="true" classname="fromjava.server.AddWebservice">
<classpath>
<path refid="jaxws.classpath"/>
<pathelement location="${build.classes.home}"/>
</classpath>
</java>
</target>

<target name="server-j2se-stop" depends="setup">
<get src="http://localhost:9090/stop" dest="stop.status"/>
</target>



</project>

You also need to have the following files

This is the sun-jaxws.xml

<?xml version="1.0" encoding="UTF-8"?>
<endpoints xmlns='http://java.sun.com/xml/ns/jax-ws/ri/runtime' version='2.0'>
<endpoint
name='fromjava'
implementation='fromjava.server.AddNumbersImpl'
url-pattern='/addnumbers'/>
</endpoints>

This is the web.xml file

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<description>fromjava</description>
<display-name>fromjava</display-name>
<listener>
<listener-class>com.sun.xml.ws.transport.http.servlet.WSServletContextListener</listener-class>
</listener>
<servlet>
<description>JAX-WS endpoint - fromjava</description>
<display-name>fromjava</display-name>
<servlet-name>fromjava</servlet-name>
<servlet-class>com.sun.xml.ws.transport.http.servlet.WSServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>fromjava</servlet-name>
<url-pattern>/addnumbers</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>60</session-timeout>
</session-config>
</web-app>


IBM Certified SOA Associate
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Eclipse 3.3, Glassfish, WebServices and wsimport