Introduction

Axis comes with command line tools whose usage is pretty fundamental for a new user. These are wsdl2java, java2wsdl, tcpmon and adminclient. All of these tools need to be invoked via java, and need a fairly complex classpath to work correctly.

java <classpath> <fully qualified name of class> <parameters>

Using the tools in this way is very frustrating because the command lines are very long and it is easy to make mistakes, so its probably wise to create some tools to help.

Can someone do unix versions of this please? - Andrew Premdas OK, see below.

Setting Up Command Line Tools

There are several useful batch files for axis we have created:

The source code of these tools could be found below. It would be a good idea to store these somewhere on your path.

Setting up Logging

All the command line tools have logging, so you can create a simple log4j.properties file to ensure the logging is initialised properly (it is a good practice to setup logging before using AXIS).

# simple log4j configutation for axis #
# direct log messages to stdout #
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n
# change logging level here.
log4j.rootLogger=info, stdout

We need to put this in a location which we will define as LOG4J_PROPERTIES_HOME

Setting up the classpath

The command line tools need access to all the axis jars, activation.jar, mail.jar, xml parser jars, and log4j.properties file. So the first thing we do is create paths to their locations.

 set AXIS_HOME=C:\lib.dir\axis-1_2beta  
 set ACTIVATION_HOME=C:\lib.dir\jaf-1.0.2
 set MAIL_HOME=C:\lib.dir\javamail-1.3.1
 set XML_HOME=C:\lib.dir\xalan-j_2_6_0\bin
 set ["LOG4J"]_PROPERTIES_HOME=C:\axisUtils
 set AXIS_LIB=%AXIS_HOME%\lib

Then we add paths to each library. I do this one at a time, because following the user guide (http://ws.apache.org/axis/java/user-guide.html) or the installation guide (http://ws.apache.org/axis/java/install.html#deploy) didn't work. This makes it easier to diagnose any problems caused by typos.

 set AXISCP=.
 set AXISCP=%AXISCP%;%ACTIVATION_HOME%\activation.jar
 set AXISCP=%AXISCP%;%AXIS_LIB%\axis.jar
 set AXISCP=%AXISCP%;%AXIS_LIB%\commons-discovery.jar
 set AXISCP=%AXISCP%;%AXIS_LIB%\commons-logging.jar 
 set AXISCP=%AXISCP%;%AXIS_LIB%\jaxrpc.jar
 set AXISCP=%AXISCP%;%AXIS_LIB%\saaj.jar
 set AXISCP=%AXISCP%;%AXIS_LIB%\log4j-1.2.8.jar
 set AXISCP=%AXISCP%;%AXIS_LIB%\wsdl4j.jar
 set AXISCP=%AXISCP%;%MAIL_HOME%\mail.jar
 set AXISCP=%AXISCP%;%XML_HOME%\xml-apis.jar
 set AXISCP=%AXISCP%;%XML_HOME%\xercesImpl.jar

Now we add the location of log4j.properties to the path.

 set AXISCP=%AXISCP%;%LOG4J_PROPERTIES_HOME%

Save this as setaxiscp.bat, my complete version of this is at the bottom of this page.

Create convenience tools for calling the command line tools

Create a batch file for each tool.

Windows

java2wsdl.bat

  java -cp %AXISCP% org.apache.axis.wsdl.Java2WSDL %*

wsdl2java.bat

  java -cp %AXISCP% org.apache.axis.wsdl.WSDL2Java %*

adminclient.bat

  java -cp %AXISCP% org.apache.axis.client.AdminClient %*

tcpmon.bat

  java -cp %AXISCP% org.apache.axis.utils.tcpmon %*

Unix/Linux

On Unix/Linux I suggest to use the following datastructure:

axis
  bin
      //all scripts here
  lib
      //all necessary libraries here
  log4j.properties

In case of different files locations you have to correct AXISLIB and LOG4J_PROPERTIES_HOME variables.

java2wsdl

export AXISLIB=`echo $(dirname $0)`/../lib
export LOG4J_PROPERTIES_HOME=`echo $(dirname $0)`/..
export AXISCLASSPATH=$AXISLIB/activation.jar:$AXISLIB/mail.jar:$AXISLIB/axis.jar:$AXISLIB/commons-discovery.jar:$AXISLIB/commons-logging.jar:$AXISLIB/jaxrpc.jar:$AXISLIB/saaj.jar:$AXISLIB/log4j-1.2.8.jar:$AXISLIB/wsdl4j.jar:$LOG4J_PROPERTIES_HOME:
java -cp $AXISCLASSPATH org.apache.axis.wsdl.Java2WSDL $*

wsdl2java

export AXISLIB=`echo $(dirname $0)`/../lib
export LOG4J_PROPERTIES_HOME=`echo $(dirname $0)`/..
export AXISCLASSPATH=$AXISLIB/activation.jar:$AXISLIB/mail.jar:$AXISLIB/axis.jar:$AXISLIB/commons-discovery.jar:$AXISLIB/commons-logging.jar:$AXISLIB/jaxrpc.jar:$AXISLIB/saaj.jar:$AXISLIB/log4j-1.2.8.jar:$AXISLIB/wsdl4j.jar:$LOG4J_PROPERTIES_HOME:
java -cp $AXISCLASSPATH org.apache.axis.wsdl.WSDL2Java $*

adminclient

export AXISLIB=`echo $(dirname $0)`/../lib
export LOG4J_PROPERTIES_HOME=`echo $(dirname $0)`/..
export AXISCLASSPATH=$AXISLIB/activation.jar:$AXISLIB/mail.jar:$AXISLIB/axis.jar:$AXISLIB/commons-discovery.jar:$AXISLIB/commons-logging.jar:$AXISLIB/jaxrpc.jar:$AXISLIB/saaj.jar:$AXISLIB/log4j-1.2.8.jar:$AXISLIB/wsdl4j.jar:$LOG4J_PROPERTIES_HOME:
java -cp $AXISCLASSPATH org.apache.axis.client.AdminClient $*

tcpmon

export AXISLIB=`echo $(dirname $0)`/../lib
export LOG4J_PROPERTIES_HOME=`echo $(dirname $0)`/..
export AXISCLASSPATH=$AXISLIB/activation.jar:$AXISLIB/mail.jar:$AXISLIB/axis.jar:$AXISLIB/commons-discovery.jar:$AXISLIB/commons-logging.jar:$AXISLIB/jaxrpc.jar:$AXISLIB/saaj.jar:$AXISLIB/log4j-1.2.8.jar:$AXISLIB/wsdl4j.jar:$LOG4J_PROPERTIES_HOME:
java -cp $AXISCLASSPATH org.apache.axis.utils.tcpmon $*

Usage

Open up a command window, run setaxiscp, now you can use the other batch files, for help with them just pass the -h parameter.

setaxiscp.bat

 @ECHO OFF
 REM Locations: Change these to match your environment
 set AXIS_HOME=C:\lib.dir\axis-1_2beta
 set ACTIVATION_HOME=C:\lib.dir\jaf-1.0.2
 set MAIL_HOME=C:\lib.dir\javamail-1.3.1
 set XML_HOME=C:\lib.dir\xalan-j_2_6_0\bin
 set ["LOG4J"]_PROPERTIES_HOME=C:\axisUtils
 set AXIS_LIB=%AXIS_HOME%\lib
 REM Create the class path 
 set AXISCP=.
 set AXISCP=%AXISCP%;%ACTIVATION_HOME%\activation.jar
 set AXISCP=%AXISCP%;%AXIS_LIB%\axis.jar
 set AXISCP=%AXISCP%;%AXIS_LIB%\commons-discovery.jar
 set AXISCP=%AXISCP%;%AXIS_LIB%\commons-logging.jar 
 set AXISCP=%AXISCP%;%AXIS_LIB%\jaxrpc.jar
 set AXISCP=%AXISCP%;%AXIS_LIB%\saaj.jar 
 set AXISCP=%AXISCP%;%AXIS_LIB%\log4j-1.2.8.jar
 set AXISCP=%AXISCP%;%AXIS_LIB%\wsdl4j.jar
 set AXISCP=%AXISCP%;%MAIL_HOME%\mail.jar
 set AXISCP=%AXISCP%;%XML_HOME%\xml-apis.jar
 set AXISCP=%AXISCP%;%XML_HOME%\xercesImpl.jar
 ECHO set up classpath
 REM set logging to the console using log4j
 set AXISCP=%AXISCP%;%LOG4J_PROPERTIES_HOME%
 ECHO initialised logging
 ECHO Should now be able to call
 ECHO adminclient, tcpmon, wsdl2java, java2wsdl ...

Unix version

I'm just a hack, but here goes: The log4j.properties file above is OS agnostic, so no change there. This process assumes you have $JAVA_HOME defined somewhere. On my RH9 system, I created a /etc/profile.d/java.sh file to define all desired Java-related environment variables:

 if [ -z "$JAVA_HOME" ] ; then
        JAVA_HOME="/usr/java/j2sdk1.4.2"
        PATH=$PATH:$JAVA_HOME"/bin"
        export PATH
 fi
 if [ -z "$JDK_HOME" ] ; then
        JDK_HOME="/usr/java/j2sdk1.4.2"
 fi
 if [ -z "$TOMCAT_HOME" ] ; then
        TOMCAT_HOME="/var/tomcat"
 fi
 if [ -z "$CATALINA_HOME" ] ; then
        CATALINA_HOME=$TOMCAT_HOME
 fi
 if [ -z "$ANT_HOME" ] ; then
        ANT_HOME="/usr/java/ant"
 fi

Cutting to the chase, create (on one line):

/usr/bin/wsdl2java: java -classpath $JAVA_HOME"/lib":$JAVA_HOME"/lib/axis.jar":
$JAVA_HOME"/lib/commons-discovery.jar":$JAVA_HOME"/lib/commons-logging.jar":
$JAVA_HOME"/lib/jaxrpc.jar":$JAVA_HOME"/lib/log4j-1.2.8.jar":$JAVA_HOME"/lib/saaj.jar:
wsdl4j.jar":. org.apache.axis.wsdl.WSDL2Java $* 

From shell, execute:

chmod 755 /usr/bin/wsdl2java
wsdl2java <your_service.wsdl>

Makefile Version

I want to contribute some Makefile rules, once I'm ready testing them. Thanks for the good information.

FrontPage/Axis/UsingCommandLineTools (last edited 2009-09-20 22:48:39 by localhost)