Maven 2, JAX-WS RI And Tomcat Deploy (Part I)

I have been experimenting with some of the Java EE 5 modules, mainly the JAX-WS RI the Sun’s implementation as part of the Glassfish project. Since I could not find any post on how to integrate this cleanly with Maven2, hopefully this would help some souls out there trying to get a head start to quickly develop some applications with JAX-WS RI and Maven2. Since this is going to be a long article I will try to break it down into multiple blog posts.

What I will do is create a simple project using the contract-last paradigm (i.e. we start with Java classes) as many of my current projects involve exposing existing applications as web service, this is the approach I will take for this entry. Most of the documentations or references you find deal with the contract-first paradigm and the maven plugins are available. Hopefully, this will help people using maven2 who want to try out the JAX-WS RI.

After some initial frustrations, I am beginning to like the Netbeans/Mevenide2 (plugin for Maven2) combination. Once, you get used to the project pattern, it has been really tough to get back to doing it the ant way (although I do make use of the maven-antrun-plugin a lot). One of problems with using the (Glassfish) JAX-WS RI has been that a lot of the artifacts dependencies are not yet sorted out in the java.net repository. In addition the RI 2.1-EA3 has not been pushed out to the repository yet and neither are all the artifacts necessary for using JAX-WS RI available in the repository (http.jar and resolver.jar). Instead sorting out the whole dependencies and versioning, I decided to do a local install so I could easily expose all of our java applications.

1. Setting up Maven2 Local Repository for JAX-WS RI 2.1-EA3

The JAX-WS RI 2.1-EA3 was released couple of weeks ago and this is what we will use to build our application. First thing to do is download the jarball JAXWS2.1EA3_20061115.jar. As per the instruction executing the following will unjar it:

java -jar JAXWS2.1EA3_20061115.jar

It should create a directory jaxws-ri. What we need to do is push those jars into our maven repository and specify as dependencies to our project. I will show you couple of approaches one is the brute force where you manually add all the dependencies by browsing for the poms in the java.net repository or do the mvn install:install-file, then create a pom project with all the dependencies wrapped as our project. I will describe the second approach now.

1.1 Pushing the JAX-WS RI jars to the local repository

First we need to push all the jars (note, you probably don’t need all the jars but I like to play it safe). Let’s assess our jars first, here is the listing of the lib directory:

activation.jar
FastInfoset.jar
http.jar
jaxb-api.jar
jaxb-impl.jar
jaxb-xjc.jar
jaxws-api.jar
jaxws-rt.jar
jaxws-tools.jar
jsr173_api.jar
jsr181-api.jar
jsr250-api.jar
resolver.jar
saaj-api.jar
saaj-impl.jar
sjsxp.jar
stax-ex.jar
streambuffer.jar

Here is a small shell script I wrote to push it to my local repository, you could push it to a company wide repository by changing $cmd_install to $cmd_deploy (sorry pc users). Create the following script, cd to the jaxws-ri/lib directory and execute it:

#!/bin/sh

prog=`basename $0`
cmd_deploy=”mvn deploy:deploy-file”
cmd_install=”mvn install:install-file”
#:##
#: Depending on deploy/install changed it to $cmd_deploy or $cmd_install
#:##
cmd=$cmd_install
jaxws_home=${JAXWS_HOME:-.}
if [ -d ${jaxws_home}/lib ]
then
jaxws_libdir=${jaxws_home}/lib
else
jaxws_libdir=${jaxws_home}
fi
group_id=local.sun.java.net
version=2.1-EA3

for f in `ls ${jaxws_libdir}`
do
#echo “Found file: $f, `basename $f`”
fbase=`basename $f`
ext=`echo ${fbase}|cut -f2 -d. -`
artifact_name=`echo ${fbase}|cut -f1 -d. -`
#echo “ext is :$ext”
if [ X”$ext” = Xjar ]
then
echo “Installing jar file: ${jaxws_libdir}/$f”
artifact_id=${artifact_name}
$cmd -DgroupId=${group_id} -DartifactId=${artifact_id} -Dversion=${version} -Dfile=${jaxws_libdir}/$f -Dpackaging=jar -DgeneratePom=true
else
echo “SKIPPING: $f <not a jar file>”
fi
done
exit

Please be aware of newlines (especially the line starting with $cmd). In a nutshell what the script does is:

  • Sets the groupId to local.sun.java.net (you can name it anything).
  • Sets the version to 2.1-EA3 (again arbitrary, but we would like to keep it inline with the java.net versions).
  • The artifactId is set to the filename of the jar without the extension.

At this point all the jaxws-ri jars needed for our project should be available in the maven local repository. Now, lets us build a pom project that we create representing these jars.

1.2 JAX-WS RI pom Project

This is really easy, just create any directory and place the following pom.xml in it. Then cd to the directory and issue mvn install. Here is the pom file:

<?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/maven-v4_0_0.xsd”>
<modelVersion>4.0.0</modelVersion>

<groupId>local.sun.java.net</groupId>
<artifactId>jaxws-ri</artifactId>
<version>2.1-EA3-SNAPSHOT</version>
<packaging>pom</packaging>

<name>JAXWS-RI Master POM</name>
<url>http://mydomain.org</url&gt;

<properties>
<jaxws.ri.version>2.1-EA3</jaxws.ri.version>
</properties>

<dependencies>
<dependency>
<groupId>local.sun.java.net</groupId>
<artifactId>FastInfoset</artifactId>
<version>${jaxws.ri.version}</version>
</dependency>
<dependency>
<groupId>local.sun.java.net</groupId>
<artifactId>activation</artifactId>
<version>${jaxws.ri.version}</version>
</dependency>
<dependency>
<groupId>local.sun.java.net</groupId>
<artifactId>http</artifactId>
<version>${jaxws.ri.version}</version>
</dependency>
<dependency>
<groupId>local.sun.java.net</groupId>
<artifactId>jaxb-api</artifactId>
<version>${jaxws.ri.version}</version>
</dependency>
<dependency>
<groupId>local.sun.java.net</groupId>
<artifactId>jaxb-impl</artifactId>
<version>${jaxws.ri.version}</version>
</dependency>
<dependency>
<groupId>local.sun.java.net</groupId>
<artifactId>jaxb-xjc</artifactId>
<version>${jaxws.ri.version}</version>
</dependency>
<dependency>
<groupId>local.sun.java.net</groupId>
<artifactId>jaxws-api</artifactId>
<version>${jaxws.ri.version}</version>
</dependency>
<dependency>
<groupId>local.sun.java.net</groupId>
<artifactId>jaxws-rt</artifactId>
<version>${jaxws.ri.version}</version>
</dependency>
<dependency>
<groupId>local.sun.java.net</groupId>
<artifactId>jaxws-tools</artifactId>
<version>${jaxws.ri.version}</version>
</dependency>
<dependency>
<groupId>local.sun.java.net</groupId>
<artifactId>jsr173_api</artifactId>
<version>${jaxws.ri.version}</version>
</dependency>
<dependency>
<groupId>local.sun.java.net</groupId>
<artifactId>jsr181-api</artifactId>
<version>${jaxws.ri.version}</version>
</dependency>
<dependency>
<groupId>local.sun.java.net</groupId>
<artifactId>jsr250-api</artifactId>
<version>${jaxws.ri.version}</version>
</dependency>
<dependency>
<groupId>local.sun.java.net</groupId>
<artifactId>resolver</artifactId>
<version>${jaxws.ri.version}</version>
</dependency>
<dependency>
<groupId>local.sun.java.net</groupId>
<artifactId>saaj-api</artifactId>
<version>${jaxws.ri.version}</version>
</dependency>
<dependency>
<groupId>local.sun.java.net</groupId>
<artifactId>saaj-impl</artifactId>
<version>${jaxws.ri.version}</version>
</dependency>
<dependency>
<groupId>local.sun.java.net</groupId>
<artifactId>sjsxp</artifactId>
<version>${jaxws.ri.version}</version>
</dependency>
<dependency>
<groupId>local.sun.java.net</groupId>
<artifactId>stax-ex</artifactId>
<version>${jaxws.ri.version}</version>
</dependency>

<dependency>
<groupId>local.sun.java.net</groupId>
<artifactId>streambuffer</artifactId>
<version>${jaxws.ri.version}</version>
</dependency>

</dependencies>
</project>

Things to pay attention are:

  • The artifactId is set to jaxws-ri (it really is up to you).
  • The version is set to 2.1-EA3-SNAPSHOT (again arbitrary, I gave it a snapshot so that if I need to refresh the jars I could just do the step described in previous section and just change the jaxws.ri.version property to it and install this project again.
  • Notice the bold element values are the same ones we used in the shell script to install the jars.

That’s it, if you open it in Netbeans/Mevenide you should be able to see the dependencies as shown in the figure below:

dependencies.png

1.3 JAX-WS RI pom Project

So if you need to work with the JAX-RI, in any maven project all you need to do is include the following dependency to your maven2 project file (pom.xml):

<!– MASTER JAXWS-RI POM –>
<dependency>
<groupId>local.sun.java.net</groupId>
<artifactId>jaxws-ri</artifactId>
<version>2.1-EA3-SNAPSHOT</version>
<type>pom</type>

You should see all the JAX-WS RI jars. Notice, the <type> element, it is pom (which is required). In the next part I will describe how to use the JAX-WS in a toy project.

1.4 Conclusion

Hopefully the JAX-WS RI will make it into the java.net repository with the proper dependencies soon, then you wouldn’t have to depend on this. But I have used this neat trick for other libraries that are not available in maven2 repository. I don’t know whether this is a known maven2 (dread) pattern!

Advertisements

11 Comments

  1. SMG said

    Dear Sir,

    Thankyou for the great article, I have been looking for a quick fix to this problem for a while – yet I am new to shell scripting.

    I have a problem – I copied your script to a new file ‘installLibs.sh’ and executed with ‘./installLibs.sh’,yet I get the following errors:

    ./installLibs.sh: line 4: deploy:deploy-file”: command not found
    ./installLibs.sh: line 5: install:install-file”: command not found
    ./installLibs.sh: line 33: not: No such file or directory
    ./installLibs.sh: line 33: not: No such file or directory
    ./installLibs.sh: line 33: not: No such file or directory
    ./installLibs.sh: line 33: not: No such file or directory
    ./installLibs.sh: line 33: not: No such file or directory
    ./installLibs.sh: line 33: not: No such file or directory
    ./installLibs.sh: line 33: not: No such file or directory
    ./installLibs.sh: line 33: not: No such file or directory
    ./installLibs.sh: line 33: not: No such file or directory
    ./installLibs.sh: line 33: not: No such file or directory
    ./installLibs.sh: line 33: not: No such file or directory
    ./installLibs.sh: line 33: not: No such file or directory
    ./installLibs.sh: line 33: not: No such file or directory
    ./installLibs.sh: line 33: not: No such file or directory
    ./installLibs.sh: line 33: not: No such file or directory
    ./installLibs.sh: line 33: not: No such file or directory

    Can you help?

  2. SMG said

    Please disregard the last comment. The error is caused by a non-compliant quotation characters which are derived as a result of copy and paste from the HTML.

  3. Elad said

    Thanks for a great post. It was very helpful.

    Since I’m running windows on my dev machine, I couldn’t use the shell script, so I translated it to ruby:

    cmd_type = ARGV.empty? ? “install” : ARGV[0]
    group_id = ARGV.empty? ? “local.sun.java.net” : ARGV[1]
    version = ARGV.empty? ? “2.1-EA3” : ARGV[2]

    if cmd_type == “install”
    cmd_base = “mvn install:install-file”
    elsif cmd_type == “deploy”
    cmd_base = “mvn deploy:deploy-file”
    else
    abort “Wrong command parameter!”
    end

    jaxws_home = ENV[‘JAXWS_HOME’]
    abort “JAXWS_HOME env variable not set” if jaxws_home.nil?

    jaxws_libdir = File.join(jaxws_home, ‘lib’)
    abort “Directory #{jaxws_libdir} not found” unless File.exist?(jaxws_libdir)

    temp_file = ‘jaxws-mvn-install-temp.bat’

    Dir.chdir(jaxws_libdir)
    Dir.glob(“*.jar”).each do |f|
    artifact_id = File.basename(f, “.*”)
    #puts “Installing #{File.basename(f)} …”
    cmd = cmd_base + ” -DgroupId=#{group_id} -DartifactId=#{artifact_id}” + \
    ” -Dversion=#{version} -Dfile=#{File.join(jaxws_libdir, f)}” + \
    ” -Dpackaging=jar -DgeneratePom=true”
    outf = File.new(temp_file, ‘w’)
    puts “Executing #{cmd}\n”
    outf.write(cmd)
    outf.close
    %x{#{temp_file}}
    end

    File.delete(temp_file)

  4. Mohan said

    Elad,
    I am glad this was helpful to you! I did want to create a bat file for windows users, a ruby solution if fine 🙂 thanks.

  5. Koval said

    Thank You for your great post!

  6. Fernand said

    For those who want to execute it boldly – I just was executing the following on all Jars (Jax-WS RI 2.1.2)…

    call mvn install:install-file -DgroupId=local.sun.java.net -DartifactId=fastInfoset -Dversion=2.1.2 -Dpackaging=jar -Dfile=FastInfoset.jar -DgeneratePom=true
    call mvn install:install-file -DgroupId=local.sun.java.net -DartifactId=activation -Dversion=2.1.2 -Dpackaging=jar -Dfile=activation.jar -DgeneratePom=true
    call mvn install:install-file -DgroupId=local.sun.java.net -DartifactId=http -Dversion=2.1.2 -Dpackaging=jar -Dfile=http.jar -DgeneratePom=true
    call mvn install:install-file -DgroupId=local.sun.java.net -DartifactId=jaxb-api -Dversion=2.1.2 -Dpackaging=jar -Dfile=jaxb-api.jar -DgeneratePom=true
    call mvn install:install-file -DgroupId=local.sun.java.net -DartifactId=jaxb-impl -Dversion=2.1.2 -Dpackaging=jar -Dfile=jaxb-impl.jar -DgeneratePom=true
    call mvn install:install-file -DgroupId=local.sun.java.net -DartifactId=jaxb-xjc -Dversion=2.1.2 -Dpackaging=jar -Dfile=jaxb-xjc.jar -DgeneratePom=true
    call mvn install:install-file -DgroupId=local.sun.java.net -DartifactId=jaxws-api -Dversion=2.1.2 -Dpackaging=jar -Dfile=jaxws-api.jar -DgeneratePom=true
    call mvn install:install-file -DgroupId=local.sun.java.net -DartifactId=jaxws-rt -Dversion=2.1.2 -Dpackaging=jar -Dfile=jaxws-rt.jar -DgeneratePom=true
    call mvn install:install-file -DgroupId=local.sun.java.net -DartifactId=jaxws-tools -Dversion=2.1.2 -Dpackaging=jar -Dfile=jaxws-tools.jar -DgeneratePom=true
    call mvn install:install-file -DgroupId=local.sun.java.net -DartifactId=jsr173_api -Dversion=2.1.2 -Dpackaging=jar -Dfile=jsr173_api.jar -DgeneratePom=true
    call mvn install:install-file -DgroupId=local.sun.java.net -DartifactId=jsr181-api -Dversion=2.1.2 -Dpackaging=jar -Dfile=jsr181-api.jar -DgeneratePom=true
    call mvn install:install-file -DgroupId=local.sun.java.net -DartifactId=jsr250-api -Dversion=2.1.2 -Dpackaging=jar -Dfile=jsr250-api.jar -DgeneratePom=true
    call mvn install:install-file -DgroupId=local.sun.java.net -DartifactId=resolver -Dversion=2.1.2 -Dpackaging=jar -Dfile=resolver.jar -DgeneratePom=true
    call mvn install:install-file -DgroupId=local.sun.java.net -DartifactId=saaj-api -Dversion=2.1.2 -Dpackaging=jar -Dfile=saaj-api.jar -DgeneratePom=true
    call mvn install:install-file -DgroupId=local.sun.java.net -DartifactId=saaj-impl -Dversion=2.1.2 -Dpackaging=jar -Dfile=saaj-impl.jar -DgeneratePom=true
    call mvn install:install-file -DgroupId=local.sun.java.net -DartifactId=sjsxp -Dversion=2.1.2 -Dpackaging=jar -Dfile=sjsxp.jar -DgeneratePom=true
    call mvn install:install-file -DgroupId=local.sun.java.net -DartifactId=stax-ex -Dversion=2.1.2 -Dpackaging=jar -Dfile=stax-ex.jar -DgeneratePom=true
    call mvn install:install-file -DgroupId=local.sun.java.net -DartifactId=streambuffer -Dversion=2.1.2 -Dpackaging=jar -Dfile=streambuffer.jar -DgeneratePom=true

    Regards,

    – Fernand

  7. Fernand said

    And refer it from a using pom as:

    local.sun.java.net
    fastInfoset
    2.1.2

    local.sun.java.net
    fastInfoset
    2.1.2

    local.sun.java.net
    fastInfoset
    2.1.2

    local.sun.java.net
    fastInfoset
    2.1.2

    local.sun.java.net
    stax-ex
    2.1.2

    local.sun.java.net
    resolver
    2.1.2

    local.sun.java.net
    jsr250-api
    2.1.2

    local.sun.java.net
    jsr181-api
    2.1.2

    local.sun.java.net
    activation
    2.1.2

    local.sun.java.net
    saaj-api
    2.1.2

    local.sun.java.net
    http
    2.1.2

    local.sun.java.net
    jaxb-api
    2.1.2

    local.sun.java.net
    jaxb-impl
    2.1.2

    local.sun.java.net
    sjsxp
    2.1.2

    local.sun.java.net
    jaxws-rt
    2.1.2

    local.sun.java.net
    fastInfoset
    2.1.2

    local.sun.java.net
    jaxb-xjc
    2.1.2

    local.sun.java.net
    jaxws-api
    2.1.2

    local.sun.java.net
    jaxws-tools
    2.1.2

    local.sun.java.net
    jsr173_api
    2.1.2

    local.sun.java.net
    streambuffer
    2.1.2

    local.sun.java.net
    saaj-impl
    2.1.2

    org.apache.maven.plugins
    maven-compiler-plugin

    1.5
    1.5

    – Fernand

  8. Fernand said

    I mean:

    <dependencies>
    <dependency>
    <groupId>local.sun.java.net</groupId>
    <artifactId>fastInfoset</artifactId>
    <version>2.1.2</version>
    </dependency>
    <dependency>
    <groupId>local.sun.java.net</groupId>
    <artifactId>fastInfoset</artifactId>
    <version>2.1.2</version>
    </dependency>
    <dependency>
    <groupId>local.sun.java.net</groupId>
    <artifactId>fastInfoset</artifactId>
    <version>2.1.2</version>
    </dependency>
    <dependency>
    <groupId>local.sun.java.net</groupId>
    <artifactId>fastInfoset</artifactId>
    <version>2.1.2</version>
    </dependency>
    <dependency>
    <groupId>local.sun.java.net</groupId>
    <artifactId>stax-ex</artifactId>
    <version>2.1.2</version>
    </dependency>
    <dependency>
    <groupId>local.sun.java.net</groupId>
    <artifactId>resolver</artifactId>
    <version>2.1.2</version>
    </dependency>
    <dependency>
    <groupId>local.sun.java.net</groupId>
    <artifactId>jsr250-api</artifactId>
    <version>2.1.2</version>
    </dependency>
    <dependency>
    <groupId>local.sun.java.net</groupId>
    <artifactId>jsr181-api</artifactId>
    <version>2.1.2</version>
    </dependency>
    <dependency>
    <groupId>local.sun.java.net</groupId>
    <artifactId>activation</artifactId>
    <version>2.1.2</version>
    </dependency>
    <dependency>
    <groupId>local.sun.java.net</groupId>
    <artifactId>saaj-api</artifactId>
    <version>2.1.2</version>
    </dependency>
    <dependency>
    <groupId>local.sun.java.net</groupId>
    <artifactId>http</artifactId>
    <version>2.1.2</version>
    </dependency>
    <dependency>
    <groupId>local.sun.java.net</groupId>
    <artifactId>jaxb-api</artifactId>
    <version>2.1.2</version>
    </dependency>
    <dependency>
    <groupId>local.sun.java.net</groupId>
    <artifactId>jaxb-impl</artifactId>
    <version>2.1.2</version>
    </dependency>
    <dependency>
    <groupId>local.sun.java.net</groupId>
    <artifactId>sjsxp</artifactId>
    <version>2.1.2</version>
    </dependency>
    <dependency>
    <groupId>local.sun.java.net</groupId>
    <artifactId>jaxws-rt</artifactId>
    <version>2.1.2</version>
    </dependency>
    <dependency>
    <groupId>local.sun.java.net</groupId>
    <artifactId>fastInfoset</artifactId>
    <version>2.1.2</version>
    </dependency>
    <dependency>
    <groupId>local.sun.java.net</groupId>
    <artifactId>jaxb-xjc</artifactId>
    <version>2.1.2</version>
    </dependency>
    <dependency>
    <groupId>local.sun.java.net</groupId>
    <artifactId>jaxws-api</artifactId>
    <version>2.1.2</version>
    </dependency>
    <dependency>
    <groupId>local.sun.java.net</groupId>
    <artifactId>jaxws-tools</artifactId>
    <version>2.1.2</version>
    </dependency>
    <dependency>
    <groupId>local.sun.java.net</groupId>
    <artifactId>jsr173_api</artifactId>
    <version>2.1.2</version>
    </dependency>
    <dependency>
    <groupId>local.sun.java.net</groupId>
    <artifactId>streambuffer</artifactId>
    <version>2.1.2</version>
    </dependency>
    <dependency>
    <groupId>local.sun.java.net</groupId>
    <artifactId>saaj-impl</artifactId>
    <version>2.1.2</version>
    </dependency>
    </dependencies>

    <build>
    <plugins>
    <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <configuration>
    <source>1.5</source>
    <target>1.5</target>
    </configuration>
    </plugin>
    </plugins>
    <finalName>jaxws1</finalName>
    </build>

  9. Lean said

    It is possible to integrate this with Spring or should I use XFire?

  10. […] is a continuation of the previous entry, where we dealt pimarily with building a pom project for the JAX-WS RI 2.1 EA3 jars so that we can […]

  11. www animal planet games commando 1

    Maven 2, JAX-WS RI And Tomcat Deploy (Part I) | Wind Up

RSS feed for comments on this post · TrackBack URI

Comments are closed.

%d bloggers like this: