Thursday, June 25, 2009

Maven And Weblogic

Goal


This post is a follow-up to a previous entry on running Weblogic Ant tasks without calling setDomainEnv. The purpose is to perform the same actions from Maven. Fortunately, the weblogic-maven-plugin does not have the same requirement for setting environment variables from outside the build script. Unfortunately, development on the mojos appears to be a few versions behind the latest release of Weblogic. The code and examples here demonstrate how to use this Maven plug-in to run goals for deloying a WAR, building a web service skeleton and generating a web service client for Weblogic 10.3.

Listing the Applications Deployed to Weblogic


We can begin by creating an m2eclipse Maven project, timezra.blog.maven.weblogic, with the webapp-jee5 archetype. The Wizard materializes a simple hello world application that will be packaged as a WAR.

In order to list the applications deployed to Weblogic, we first need to setup a Weblogic domain if we do not already have one. For this example, we can create one called maven_example using the defaults provided by the Configuration Wizard.
There is already a good starting point for configuring the weblogic-maven-plugin in our pom.xml, but for 10.3 these instructions are incomplete. One problem becomes evident when we compose an Eclipse Run Configuration for the weblogic:listapps goal (being sure to use the External Maven 2.10 Runtime).
An Eclipse Run Configuration for the weblogic:listapps goal.

In our console, we would see a stack trace.


java.lang.NoClassDefFoundError: weblogic/utils/Debug
 at weblogic.Deployer.(Deployer.java:23)
 at org.codehaus.mojo.weblogic.DeployMojoBase.executeDeployer(DeployMojoBase.java:509)
 at org.codehaus.mojo.weblogic.ListAppsMojo.execute(ListAppsMojo.java:51)
 at org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPluginManager.java:483)
 at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:678)
 at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeStandaloneGoal(DefaultLifecycleExecutor.java:553)
 at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoal(DefaultLifecycleExecutor.java:523)
 at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalAndHandleFailures(DefaultLifecycleExecutor.java:371)
 at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegments(DefaultLifecycleExecutor.java:332)
 at org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLifecycleExecutor.java:181)
 at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:356)
 at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:137)
 at org.apache.maven.cli.MavenCli.main(MavenCli.java:356)
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
 at java.lang.reflect.Method.invoke(Method.java:597)
 at org.codehaus.classworlds.Launcher.launchEnhanced(Launcher.java:315)
 at org.codehaus.classworlds.Launcher.launch(Launcher.java:255)
 at org.codehaus.classworlds.Launcher.mainWithExitCode(Launcher.java:430)
 at org.codehaus.classworlds.Launcher.main(Launcher.java:375)
Caused by: java.lang.ClassNotFoundException: weblogic.utils.Debug
 at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
 at java.security.AccessController.doPrivileged(Native Method)
 at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
 at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
 at org.codehaus.classworlds.RealmClassLoader.loadClassDirect(RealmClassLoader.java:195)
 at org.codehaus.classworlds.DefaultClassRealm.loadClass(DefaultClassRealm.java:255)
 at org.codehaus.classworlds.DefaultClassRealm.loadClass(DefaultClassRealm.java:274)
 at org.codehaus.classworlds.RealmClassLoader.loadClass(RealmClassLoader.java:214)
 at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
 at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
 ... 21 more



We must manually install a few libraries in addition to those the Wiki entry lists into our local Maven repository.


  mvn install:install-file -DgroupId=weblogic -DartifactId=weblogic -Dversion=10.3 -Dpackaging=jar -Dfile=C:\webservers\bea\wlserver_10.3\server\lib\weblogic.jar
  mvn install:install-file -DgroupId=weblogic -DartifactId=webservices -Dversion=10.3 -Dpackaging=jar -Dfile=C:\webservers\bea\wlserver_10.3\server\lib\webservices.jar
  mvn install:install-file -DgroupId=weblogic -DartifactId=com.bea.core.weblogic.rmi.client -Dversion=1.4.0.0 -Dpackaging=jar -Dfile=C:\webservers\bea\modules\com.bea.core.weblogic.rmi.client_1.4.0.0.jar
  mvn install:install-file -DgroupId=weblogic -DartifactId=javax.enterprise.deploy -Dversion=1.2 -Dpackaging=jar -Dfile=C:\webservers\bea\modules\javax.enterprise.deploy_1.2.jar
  mvn install:install-file -DgroupId=weblogic -DartifactId=com.bea.core.management.core -Dversion=2.3.0.0 -Dpackaging=jar -Dfile=C:\webservers\bea\modules\com.bea.core.management.core_2.3.0.0.jar
  mvn install:install-file -DgroupId=weblogic -DartifactId=com.bea.core.weblogic.security.identity -Dversion=1.1.0.0 -Dpackaging=jar -Dfile=C:\webservers\bea\modules\com.bea.core.weblogic.security.identity_1.1.0.0.jar
  mvn install:install-file -DgroupId=weblogic -DartifactId=com.bea.core.weblogic.security -Dversion=1.0.0.0_5-0-2-0 -Dpackaging=jar -Dfile=C:\webservers\bea\modules\com.bea.core.weblogic.security_1.0.0.0_5-0-2-0.jar
  mvn install:install-file -DgroupId=weblogic -DartifactId=com.bea.core.weblogic.security.wls -Dversion=1.0.0.0_5-0-2-0 -Dpackaging=jar -Dfile=C:\webservers\bea\modules\com.bea.core.weblogic.security.wls_1.0.0.0_5-0-2-0.jar
  mvn install:install-file -DgroupId=weblogic -DartifactId=com.bea.core.weblogic.workmanager -Dversion=1.4.0.0 -Dpackaging=jar -Dfile=C:\webservers\bea\modules\com.bea.core.weblogic.workmanager_1.4.0.0.jar
  mvn install:install-file -DgroupId=weblogic -DartifactId=com.bea.core.transaction -Dversion=2.5.0.0 -Dpackaging=jar -Dfile=C:\webservers\bea\modules\com.bea.core.transaction_2.5.0.0.jar
  mvn install:install-file -DgroupId=weblogic -DartifactId=com.bea.core.logging -Dversion=1.4.0.0 -Dpackaging=jar -Dfile=C:\webservers\bea\modules\com.bea.core.logging_1.4.0.0.jar
  mvn install:install-file -DgroupId=weblogic -DartifactId=com.bea.core.utils.classloaders -Dversion=1.4.0.0 -Dpackaging=jar -Dfile=C:\webservers\bea\modules\com.bea.core.utils.classloaders_1.4.0.0.jar
  mvn install:install-file -DgroupId=weblogic -DartifactId=com.bea.core.descriptor -Dversion=1.4.0.0 -Dpackaging=jar -Dfile=C:\webservers\bea\modules\com.bea.core.descriptor_1.4.0.0.jar
  mvn install:install-file -DgroupId=weblogic -DartifactId=com.bea.core.timers -Dversion=1.4.0.0 -Dpackaging=jar -Dfile=C:\webservers\bea\modules\com.bea.core.timers_1.4.0.0.jar
  mvn install:install-file -DgroupId=weblogic -DartifactId=com.bea.core.weblogic.socket.api -Dversion=1.0.0.0 -Dpackaging=jar -Dfile=C:\webservers\bea\modules\com.bea.core.weblogic.socket.api_1.0.0.0.jar
  mvn install:install-file -DgroupId=weblogic -DartifactId=com.bea.core.common.security.api -Dversion=1.0.0.0_5-0-2-0 -Dpackaging=jar -Dfile=C:\webservers\bea\modules\com.bea.core.common.security.api_1.0.0.0_5-0-2-0.jar
  mvn install:install-file -DgroupId=weblogic -DartifactId=com.bea.core.weblogic.security.digest -Dversion=1.0.0.0 -Dpackaging=jar -Dfile=C:\webservers\bea\modules\com.bea.core.weblogic.security.digest_1.0.0.0.jar
  mvn install:install-file -DgroupId=weblogic -DartifactId=com.bea.core.weblogic.lifecycle -Dversion=1.1.0.0 -Dpackaging=jar -Dfile=C:\webservers\bea\modules\com.bea.core.weblogic.lifecycle_1.1.0.0.jar
  mvn install:install-file -DgroupId=weblogic -DartifactId=com.bea.core.workarea -Dversion=1.4.0.0 -Dpackaging=jar -Dfile=C:\webservers\bea\modules\com.bea.core.workarea_1.4.0.0.jar
  mvn install:install-file -DgroupId=weblogic -DartifactId=com.bea.core.utils.wrapper -Dversion=1.3.0.0 -Dpackaging=jar -Dfile=C:\webservers\bea\modules\com.bea.core.utils.wrapper_1.3.0.0.jar
  mvn install:install-file -DgroupId=weblogic -DartifactId=com.bea.core.store -Dversion=1.4.0.0 -Dpackaging=jar -Dfile=C:\webservers\bea\modules\com.bea.core.store_1.4.0.0.jar
  mvn install:install-file -DgroupId=weblogic -DartifactId=com.bea.core.management.jmx -Dversion=1.1.0.0 -Dpackaging=jar -Dfile=C:\webservers\bea\modules\com.bea.core.management.jmx_1.1.0.0.jar
  mvn install:install-file -DgroupId=weblogic -DartifactId=com.bea.core.descriptor.wl -Dversion=1.1.0.0 -Dpackaging=jar -Dfile=C:\webservers\bea\modules\com.bea.core.descriptor.wl_1.1.0.0.jar



We will configure the plug-in to depend on these and other publicly available libraries in our project pom.xml.

<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>timezra.blog.maven.weblogic</groupId>
    <artifactId>timezra.blog.maven.weblogic</artifactId>
    <packaging>war</packaging>
    <version>0.0.1-SNAPSHOT</version>
    <name>timezra.blog.maven.weblogic JEE5 Webapp</name>
    <url>http://maven.apache.org</url>
    <dependencies>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>servlet-api</artifactId>
            <version>2.5</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>javax.servlet.jsp</groupId>
            <artifactId>jsp-api</artifactId>
            <version>2.1</version>
            <scope>provided</scope>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.0.2</version>
                <configuration>
                    <source>1.5</source>
                    <target>1.5</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>weblogic-maven-plugin</artifactId>
                <version>2.9.2-SNAPSHOT</version>
                <configuration>
                    <adminServerHostName>localhost</adminServerHostName>
                    <adminServerPort>7001</adminServerPort>
                    <adminServerProtocol>t3</adminServerProtocol>
                    <userId>weblogic</userId>
                    <password>weblogic</password>
                    <upload>false</upload>
                    <remote>false</remote>
                    <verbose>false</verbose>
                    <debug>false</debug>
                    <targetNames>AdminServer</targetNames>
                </configuration>
                <dependencies>
                    <dependency>
                        <groupId>weblogic</groupId>
                        <artifactId>com.bea.core.utils.full</artifactId>
                        <version>1.4.0.0</version>
                        <scope>provided</scope>
                    </dependency>
                    <dependency>
                        <groupId>weblogic</groupId>
                        <artifactId>com.bea.core.i18n</artifactId>
                        <version>1.4.0.0</version>
                        <scope>provided</scope>
                    </dependency>
                    <dependency>
                        <groupId>weblogic</groupId>
                        <artifactId>com.bea.core.weblogic.rmi.client</artifactId>
                        <version>1.4.0.0</version>
                        <scope>provided</scope>
                    </dependency>
                    <dependency>
                        <groupId>weblogic</groupId>
                        <artifactId>javax.enterprise.deploy</artifactId>
                        <version>1.2</version>
                        <scope>provided</scope>
                    </dependency>
                    <dependency>
                        <groupId>weblogic</groupId>
                        <artifactId>com.bea.core.management.core</artifactId>
                        <version>2.3.0.0</version>
                        <scope>provided</scope>
                    </dependency>
                    <dependency>
                        <groupId>weblogic</groupId>
                        <artifactId>com.bea.core.weblogic.security.wls</artifactId>
                        <version>1.0.0.0_5-0-2-0</version>
                        <scope>provided</scope>
                    </dependency>
                    <dependency>
                        <groupId>weblogic</groupId>
                        <artifactId>com.bea.core.weblogic.security</artifactId>
                        <version>1.0.0.0_5-0-2-0</version>
                        <scope>provided</scope>
                    </dependency>
                    <dependency>
                        <groupId>weblogic</groupId>
                        <artifactId>com.bea.core.weblogic.security.identity</artifactId>
                        <version>1.1.0.0</version>
                        <scope>provided</scope>
                    </dependency>
                    <dependency>
                        <groupId>weblogic</groupId>
                        <artifactId>com.bea.core.weblogic.workmanager</artifactId>
                        <version>1.4.0.0</version>
                        <scope>provided</scope>
                    </dependency>
                    <dependency>
                        <groupId>weblogic</groupId>
                        <artifactId>com.bea.core.transaction</artifactId>
                        <version>2.5.0.0</version>
                        <scope>provided</scope>
                    </dependency>
                    <dependency>
                        <groupId>weblogic</groupId>
                        <artifactId>com.bea.core.logging</artifactId>
                        <version>1.4.0.0</version>
                        <scope>provided</scope>
                    </dependency>
                    <dependency>
                        <groupId>weblogic</groupId>
                        <artifactId>com.bea.core.utils.classloaders</artifactId>
                        <version>1.4.0.0</version>
                        <scope>provided</scope>
                    </dependency>
                    <dependency>
                        <groupId>weblogic</groupId>
                        <artifactId>com.bea.core.descriptor</artifactId>
                        <version>1.4.0.0</version>
                        <scope>provided</scope>
                    </dependency>
                    <dependency>
                        <groupId>weblogic</groupId>
                        <artifactId>com.bea.core.timers</artifactId>
                        <version>1.4.0.0</version>
                        <scope>provided</scope>
                    </dependency>
                    <dependency>
                        <groupId>weblogic</groupId>
                        <artifactId>com.bea.core.weblogic.socket.api</artifactId>
                        <version>1.0.0.0</version>
                        <scope>provided</scope>
                    </dependency>
                    <dependency>
                        <groupId>weblogic</groupId>
                        <artifactId>com.bea.core.common.security.api</artifactId>
                        <version>1.0.0.0_5-0-2-0</version>
                        <scope>provided</scope>
                    </dependency>
                    <dependency>
                        <groupId>weblogic</groupId>
                        <artifactId>com.bea.core.weblogic.security.digest</artifactId>
                        <version>1.0.0.0</version>
                        <scope>provided</scope>
                    </dependency>
                    <dependency>
                        <groupId>weblogic</groupId>
                        <artifactId>com.bea.core.weblogic.lifecycle</artifactId>
                        <version>1.1.0.0</version>
                        <scope>provided</scope>
                    </dependency>
                    <dependency>
                        <groupId>weblogic</groupId>
                        <artifactId>com.bea.core.workarea</artifactId>
                        <version>1.4.0.0</version>
                        <scope>provided</scope>
                    </dependency>
                    <dependency>
                        <groupId>weblogic</groupId>
                        <artifactId>com.bea.core.utils.wrapper</artifactId>
                        <version>1.3.0.0</version>
                        <scope>provided</scope>
                    </dependency>
                    <dependency>
                        <groupId>javax.transaction</groupId>
                        <artifactId>jta</artifactId>
                        <version>1.1</version>
                        <scope>provided</scope>
                    </dependency>
                    <dependency>
                        <groupId>weblogic</groupId>
                        <artifactId>com.bea.core.store</artifactId>
                        <version>1.4.0.0</version>
                        <scope>provided</scope>
                    </dependency>
                    <dependency>
                        <groupId>weblogic</groupId>
                        <artifactId>com.bea.core.management.jmx</artifactId>
                        <version>1.1.0.0</version>
                        <scope>provided</scope>
                    </dependency>
                    <dependency>
                        <groupId>weblogic</groupId>
                        <artifactId>com.bea.core.descriptor.wl</artifactId>
                        <version>1.1.0.0</version>
                        <scope>provided</scope>
                    </dependency>
                </dependencies>
            </plugin>
        </plugins>
        <finalName>timezra.blog.maven.weblogic</finalName>
    </build>
    <pluginRepositories>
        <pluginRepository>
            <id>Maven Snapshots</id>
            <url>http://snapshots.repository.codehaus.org/</url>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
            <releases>
                <enabled>false</enabled>
            </releases>
        </pluginRepository>
    </pluginRepositories>
</project>


The output from our Eclipse weblogic:listapps launcher should now show

  There is no application to list.


Deploying a WAR


Our Maven archetype has already configured the packaging for our application, and building the WAR is not Weblogic-specific. Deploying to the AdminServer is, however.
If we were to create another Eclipse Run Configuration, here called full_deploy, which calls the package and deploy goals, we would see an error.


[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] Failed to configure plugin parameters for: org.apache.maven.plugins:maven-deploy-plugin:2.4

check that the following section of the pom.xml is present and correct:

<distributionManagement>
  <!-- use the following if you're not using a snapshot version. -->
  <repository>
    <id>repo</id>
    <name>Repository Name</name>
    <url>scp://host/path/to/repo</url>
  </repository>
  <!-- use the following if you ARE using a snapshot version. -->
  <snapshotRepository>
    <id>repo</id>
    <name>Repository Name</name>
    <url>scp://host/path/to/repo</url>
  </snapshotRepository>
</distributionManagement>


For this example, it is sufficient for the distribution manager to point to our local repository and to hook into the weblogic:deploy goal in our pom.xml.

<project ....>
    ....
    <build>
        <plugins>
            ....
            <plugin>
                <executions>
                    <execution>
                        <id>deploy.to.weblogic</id>
                        <phase>deploy</phase>
                        <goals>
                            <goal>deploy</goal>
                        </goals>
                    </execution>
                </executions>
                <groupId>org.codehaus.mojo</groupId>
                ....
            </plugin>
        </plugins>
    </build>
    ....
    <distributionManagement>
        <snapshotRepository>
            <id>localRepository</id>
            <name>Local Repository</name>
            <url>file://${HOMEDRIVE}/Docume~1/${USERNAME}/.m2/repository</url>
          </snapshotRepository>
    </distributionManagement>
</project>



If you are developing on Windows, at this point you may see a misleading error about an incorrect protocol.


[INFO] Weblogic Deployment parameters [-adminurl, t3://localhost:7001, -username, weblogic, -password, weblogic, -name, timezra.blog.maven.weblogic, -targets, AdminServer, -source, C:\programming\workspaces\blog\timezra.blog.maven.weblogic\target/timezra.blog.maven.weblogic.war, -deploy]
weblogic.Deployer invoked with options: -adminurl t3://localhost:7001 -username weblogic -name timezra.blog.maven.weblogic -targets AdminServer -source C:\programming\workspaces\blog\timezra.blog.maven.weblogic\target/timezra.blog.maven.weblogic.war -deploy
<Jun 24, 2009 4:36:08 PM PDT> <Info> <J2EE Deployment SPI> <BEA-260121> <Initiating deploy operation for application, timezra.blog.maven.weblogic [archive: C:\programming\workspaces\blog\timezra.blog.maven.weblogic\target\timezra.blog.maven.weblogic.war], to AdminServer .>
no protocol: and



The problem is that weblogic-maven-plugin goals do not properly handle spaces in the classpath. The solution is simply to eliminate these spaces in the ~/$USER/.m2/settings.xml file.

<settings>
    <localRepository>${HOMEDRIVE}/Docume~1/${USERNAME}/.m2/repository</localRepository>
</settings>



The output from our Eclipse weblogic:listapps launcher should now show


   timezra.blog.maven.weblogic
  Number of Applications Found : 1


If we open http://localhost:7001/timezra.blog.maven.weblogic/ in a browser, we will see Hello World!

Compile A Web Service


The trial-and-error process for deploying a Web Service is very similar to publishing our packaged WAR: setup project dependencies, implement the service in Java, call the weblogic:jwsc goal, work out any unresolved dependencies and deploy the application.
Our web service will depend on annotations from the javax.jws library, which is provided by Weblogic. We can install this JAR, as above.


  mvn install:install-file -DgroupId=weblogic -DartifactId=javax.jws -Dversion=2.0 -Dpackaging=jar -Dfile=C:\webservers\bea\modules\javax.jws_2.0.jar



We will configure this project dependency in our pom.xml.

<project ....>
    ....
    <dependencies>
        ....
        <dependency>
            <groupId>weblogic</groupId>
            <artifactId>javax.jws</artifactId>
            <version>2.0</version>
            <scope>provided</scope>
        </dependency>
    </dependencies>
    ....
</project>



We can write an echo service with interface /src/main/java/timezra/blog/maven/weblogic/ws/IEcho.java, that simply resonates the client's input.

package timezra.blog.maven.weblogic.ws;

public interface IEcho {
    String echo(final String holla);
}



We will implement the web service as described in a previous post in /src/main/java/timezra/blog/maven/weblogic/ws/Echo.java.

package timezra.blog.maven.weblogic.ws;

import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebResult;
import javax.jws.WebService;
import javax.jws.WebParam.Mode;
import javax.jws.soap.SOAPBinding;

@WebService(name = "Echo", targetNamespace = Echo.NAMESPACE, serviceName = "Echo")
@SOAPBinding(style = SOAPBinding.Style.DOCUMENT, use = SOAPBinding.Use.LITERAL, parameterStyle = SOAPBinding.ParameterStyle.WRAPPED)
public class Echo implements IEcho {
    static final String NAMESPACE = "http://timezra.blog.maven.weblogic";
    private static final String ELLIPSIS = " ... ";

    @WebMethod(operationName = "echo")
    @WebResult(name = "holla_back", targetNamespace = NAMESPACE)
    public String echo(@WebParam(name = "holla", targetNamespace = NAMESPACE, mode = Mode.IN) final String holla) {
        if (holla == null) {
            return null;
        }
        final String[] what = holla.split("\\s");
        final StringBuilder echo = new StringBuilder(what[0]);
        for (int i = 1; i < what.length; i++) {
            echo.append(' ');
            echo.append(what[i]);
        }
        final String theLastWord = what[what.length - 1];
        echo.append(ELLIPSIS);
        echo.append(theLastWord);
        echo.append(ELLIPSIS);
        echo.append(theLastWord);
        return echo.toString();
    }
}



The weblogic:jwsc goal has dependencies on more Weblogic modules.


  mvn install:install-file -DgroupId=weblogic -DartifactId=com.bea.core.annogen -Dversion=1.2.0.0 -Dpackaging=jar -Dfile=C:\webservers\bea\modules\com.bea.core.annogen_1.2.0.0.jar
  mvn install:install-file -DgroupId=weblogic -DartifactId=com.bea.core.descriptor.j2ee.binding -Dversion=1.1.0.0 -Dpackaging=jar -Dfile=C:\webservers\bea\modules\com.bea.core.descriptor.j2ee.binding_1.1.0.0.jar
  mvn install:install-file -DgroupId=weblogic -DartifactId=com.bea.core.xml.staxb.runtime -Dversion=1.3.0.0 -Dpackaging=jar -Dfile=C:\webservers\bea\modules\com.bea.core.xml.staxb.runtime_1.3.0.0.jar
  mvn install:install-file -DgroupId=weblogic -DartifactId=com.bea.core.xml.beaxmlbeans -Dversion=1.0.0.0_2-4-0 -Dpackaging=jar -Dfile=C:\webservers\bea\modules\com.bea.core.xml.beaxmlbeans_1.0.0.0_2-4-0.jar
  mvn install:install-file -DgroupId=weblogic -DartifactId=com.bea.core.descriptor.j2ee -Dversion=1.1.0.0 -Dpackaging=jar -Dfile=C:\webservers\bea\modules\com.bea.core.descriptor.j2ee_1.1.0.0.jar
  mvn install:install-file -DgroupId=weblogic -DartifactId=javax.ejb -Dversion=3.0.1 -Dpackaging=jar -Dfile=C:\webservers\bea\modules\javax.ejb_3.0.1.jar
  mvn install:install-file -DgroupId=weblogic -DartifactId=com.bea.core.xml.xmlbeans -Dversion=1.0.0.0_2-4-0 -Dpackaging=jar -Dfile=C:\webservers\bea\modules\com.bea.core.xml.xmlbeans_1.0.0.0_2-4-0.jar
  mvn install:install-file -DgroupId=weblogic -DartifactId=com.bea.core.weblogic.stax -Dversion=1.4.0.0 -Dpackaging=jar -Dfile=C:\webservers\bea\modules\com.bea.core.weblogic.stax_1.4.0.0.jar
  mvn install:install-file -DgroupId=weblogic -DartifactId=javax.xml.rpc -Dversion=1.2.1 -Dpackaging=jar -Dfile=C:\webservers\bea\modules\javax.xml.rpc_1.2.1.jar
  mvn install:install-file -DgroupId=weblogic -DartifactId=com.bea.core.xml.staxb.buildtime -Dversion=1.3.0.0 -Dpackaging=jar -Dfile=C:\webservers\bea\modules\com.bea.core.xml.staxb.buildtime_1.3.0.0.jar
  mvn install:install-file -DgroupId=weblogic -DartifactId=glassfish.jaxws.rt -Dversion=2.1.3 -Dpackaging=jar -Dfile=C:\webservers\bea\modules\glassfish.jaxws.rt_2.1.3.jar
  mvn install:install-file -DgroupId=weblogic -DartifactId=com.bea.core.descriptor.wl.binding -Dversion=1.1.0.0 -Dpackaging=jar -Dfile=C:\webservers\bea\modules\com.bea.core.descriptor.wl.binding_1.1.0.0.jar
  mvn install:install-file -DgroupId=weblogic -DartifactId=com.bea.core.descriptor.settable.binding -Dversion=1.4.0.0 -Dpackaging=jar -Dfile=C:\webservers\bea\modules\com.bea.core.descriptor.settable.binding_1.4.0.0.jar
  mvn install:install-file -DgroupId=weblogic -DartifactId=com.bea.core.weblogic.saaj -Dversion=1.3.0.0 -Dpackaging=jar -Dfile=C:\webservers\bea\modules\com.bea.core.weblogic.saaj_1.3.0.0.jar



We will add these plug-in dependencies to the pom.xml along with configuration parameters specific to weblogic:jwsc.

<project ....>
    ....
    <build>
        <plugins>
            ....
            <plugin>
                ....
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>weblogic-maven-plugin</artifactId>
                <version>2.9.2-SNAPSHOT</version>
                <configuration>
                    ....
                    <outputName>${project.artifactId}</outputName>
                    <contextPath>${project.artifactId}</contextPath>
                    <descriptor>${basedir}/src/main/webapp/WEB-INF/web.xml</descriptor>
                </configuration>
                <dependencies>
                    ....
                    <dependency>
                        <groupId>weblogic</groupId>
                        <artifactId>com.bea.core.annogen</artifactId>
                        <version>1.2.0.0</version>
                        <scope>provided</scope>
                    </dependency>
                    <dependency>
                        <groupId>weblogic</groupId>
                        <artifactId>com.bea.core.descriptor.j2ee.binding</artifactId>
                        <version>1.1.0.0</version>
                        <scope>provided</scope>
                    </dependency>
                    <dependency>
                        <groupId>weblogic</groupId>
                        <artifactId>com.bea.core.xml.staxb.runtime</artifactId>
                        <version>1.3.0.0</version>
                        <scope>provided</scope>
                    </dependency>
                    <dependency>
                        <groupId>weblogic</groupId>
                        <artifactId>com.bea.core.xml.beaxmlbeans</artifactId>
                        <version>1.0.0.0_2-4-0</version>
                        <scope>provided</scope>
                    </dependency>
                    <dependency>
                        <groupId>weblogic</groupId>
                        <artifactId>com.bea.core.descriptor.j2ee</artifactId>
                        <version>1.1.0.0</version>
                        <scope>provided</scope>
                    </dependency>
                    <dependency>
                          <groupId>com.sun</groupId>
                          <artifactId>tools</artifactId>
                          <version>1.6.0</version>
                          <scope>system</scope>
                          <systemPath>${java.home}/../lib/tools.jar</systemPath>
                    </dependency>
                    <dependency>
                        <groupId>weblogic</groupId>
                        <artifactId>javax.ejb</artifactId>
                        <version>3.0.1</version>
                        <scope>provided</scope>
                    </dependency>
                    <dependency>
                        <groupId>weblogic</groupId>
                        <artifactId>com.bea.core.xml.xmlbeans</artifactId>
                        <version>1.0.0.0_2-4-0</version>
                        <scope>provided</scope>
                    </dependency>
                    <dependency>
                        <groupId>weblogic</groupId>
                        <artifactId>com.bea.core.weblogic.stax</artifactId>
                        <version>1.4.0.0</version>
                        <scope>provided</scope>
                    </dependency>
                    <dependency>
                        <groupId>weblogic</groupId>
                        <artifactId>javax.xml.rpc</artifactId>
                        <version>1.2.1</version>
                        <scope>provided</scope>
                    </dependency>
                    <dependency>
                        <groupId>weblogic</groupId>
                        <artifactId>com.bea.core.xml.staxb.buildtime</artifactId>
                        <version>1.3.0.0</version>
                        <scope>provided</scope>
                    </dependency>
                    <dependency>
                        <groupId>weblogic</groupId>
                        <artifactId>glassfish.jaxws.rt</artifactId>
                        <version>2.1.3</version>
                        <scope>provided</scope>
                    </dependency>
                    <dependency>
                        <groupId>javax.mail</groupId>
                        <artifactId>mail</artifactId>
                        <version>1.4.1</version>
                        <scope>provided</scope>
                    </dependency>
                    <dependency>
                        <groupId>weblogic</groupId>
                        <artifactId>com.bea.core.descriptor.wl.binding</artifactId>
                        <version>1.1.0.0</version>
                        <scope>provided</scope>
                    </dependency>
                    <dependency>
                        <groupId>weblogic</groupId>
                        <artifactId>com.bea.core.descriptor.settable.binding</artifactId>
                        <version>1.4.0.0</version>
                        <scope>provided</scope>
                    </dependency>
                    <dependency>
                        <groupId>weblogic</groupId>
                        <artifactId>com.bea.core.weblogic.saaj</artifactId>
                        <version>1.3.0.0</version>
                        <scope>provided</scope>
                    </dependency>
                </dependencies>
            </plugin>
        </plugins>
        ....
    </build>
    ....
</project>



Now we can run a new Eclipse launcher that calls weblogic:jwsc in the same way that we setup launchers for weblogic:listapps. We see that the web service artifacts are correctly generated in the target directory, and the URL for the new web service is correctly merged into the target/timezra.blog.maven.weblogic/WEB-INF/web.xml. Unfortunately, if we package and deploy the application, this merging of information in the web.xml will be overwritten with the contents of src/main/webapp/WEB-INF/web.xml (Try it if you do not believe me, if you did not follow or if you would like to discover for yourself why this is the case!). Fortunately, there is a way to automate the generation of web service and the correct packaging of the artifacts and compiled sources with some extra configuration in the pom.xml.

<project ....>
    ....
    <build>
        <plugins>
            ....
            <plugin>
                <executions>
                    <execution>
                        <id>generate.web.services</id>
                        <phase>package</phase>
                        <goals>
                            <goal>jwsc</goal>
                        </goals>
                    </execution>
                    ....
                </executions>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>weblogic-maven-plugin</artifactId>
                <version>2.9.2-SNAPSHOT</version>
                ....
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <version>2.1-beta-1</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>war</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
        ....
    </build>
    ....
</project>



We can view the published WSDL in a browser at address http://localhost:7001/timezra.blog.maven.weblogic/Echo?WSDL and we can use our favorite web service client application (here, I use soapUI) to run a few tests.
Holla-ing to the Echo Web Service through soapUI.

Generate a Web Service Client


Now that we have a deployment infrastructure and a working web service, we can create a client for that service. The current version of the weblogic-maven-plugin (2.9.2-SNAPSHOT) supports two goals for generating a web service client, weblogic:clientgen and weblogic:clientgen9. Unfortunately, neither works with Weblogic 10. If we were to call weblogic:clientgen9, for example, we would see an error similar to this:


[INFO] ------------------------------------------------------------------------
[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] Internal error in the plugin manager executing goal 'org.codehaus.mojo:weblogic-maven-plugin:2.9.2-SNAPSHOT:clientgen9': Unable to find the mojo 'clientgen9' (or one of its required components) in the plugin 'org.codehaus.mojo:weblogic-maven-plugin'
(class: org/codehaus/mojo/weblogic/ClientGen9Mojo, method: execute signature: ()V) Incompatible object argument for function call
[INFO] ------------------------------------------------------------------------



The only remedy I have seen to this issue is to modify the weblogic-maven-plugin and to install it in a local repository. After importing the project into Eclipse, we can simply apply this patch to the project root.


Index: pom.xml
===================================================================
--- pom.xml (revision 10022)
+++ pom.xml (working copy)
@@ -11,7 +11,7 @@
<artifactId>weblogic-maven-plugin</artifactId>
<packaging>maven-plugin</packaging>
<name>Weblogic Maven Plugin</name>
- <version>2.9.2-SNAPSHOT</version>
+ <version>2.9.3-SNAPSHOT</version>
<inceptionYear>2005</inceptionYear>
<description>
This plugin will support various tasks within the Weblogic 8.1
@@ -95,6 +95,12 @@
<artifactId>webservices</artifactId>
<version>[9.0,11.0)</version>
</dependency>
+ <dependency>
+ <groupId>weblogic</groupId>
+ <artifactId>com.bea.core.utils.full</artifactId>
+ <version>1.4.0.0</version>
+ <scope>provided</scope>
+ </dependency>
<dependency>
<groupId>org.apache.maven.shared</groupId>
<artifactId>maven-plugin-testing-harness</artifactId>
@@ -126,4 +132,11 @@
</plugin>
</plugins>
</reporting>
+ <distributionManagement>
+ <snapshotRepository>
+ <id>localRepository</id>
+ <name>Local Repository</name>
+ <url>file://${HOMEDRIVE}/Docume~1/${USERNAME}/.m2/repository</url>
+ </snapshotRepository>
+ </distributionManagement>
</project>
\ No newline at end of file
Index: .settings/org.eclipse.jdt.core.prefs
===================================================================
--- .settings/org.eclipse.jdt.core.prefs (revision 0)
+++ .settings/org.eclipse.jdt.core.prefs (revision 0)
@@ -0,0 +1,5 @@
+#Sat Jun 20 17:00:42 PDT 2009
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.2
+org.eclipse.jdt.core.compiler.compliance=1.4
+org.eclipse.jdt.core.compiler.source=1.3
Index: .settings/org.maven.ide.eclipse.prefs
===================================================================
--- .settings/org.maven.ide.eclipse.prefs (revision 0)
+++ .settings/org.maven.ide.eclipse.prefs (revision 0)
@@ -0,0 +1,9 @@
+#Sat Jun 20 17:00:25 PDT 2009
+activeProfiles=
+eclipse.preferences.version=1
+fullBuildGoals=process-test-resources
+includeModules=false
+resolveWorkspaceProjects=true
+resourceFilterGoals=process-resources resources\:testResources
+skipCompilerPlugin=true
+version=1
Index: src/main/java/org/codehaus/mojo/weblogic/ClientGen10Mojo.java
===================================================================
--- src/main/java/org/codehaus/mojo/weblogic/ClientGen10Mojo.java (revision 0)
+++ src/main/java/org/codehaus/mojo/weblogic/ClientGen10Mojo.java (revision 0)
@@ -0,0 +1,402 @@
+package org.codehaus.mojo.weblogic;
+
+/*
+ * Copyright 2008 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.tools.ant.Project;
+import org.apache.tools.ant.types.Path;
+import org.codehaus.mojo.weblogic.util.WeblogicMojoUtilities;
+import weblogic.wsee.tools.anttasks.ClientGenTask;
+
+import java.io.File;
+
+/**
+ * Runs Client Gen on a given WSDL. This client gen uses the BEA refactored client gen tool
+ * first appearing in weblogic 9. This is the preferred client gen tool for Weblogic 9.0 and
+ * newer.
+ *
+ * @author <a href="mailto:josborn@belltracy.com">Jon Osborn</a>
+ * @version $Id: ClientGen10Mojo.java 8652 2009-01-13 01:13:28Z jonnio $
+ * @description This mojo will run client gen on a given WSDL. This client gen uses the BEA refactored client gen tool
+ * first appearing in weblogic 9. This is the preferred client gen tool for Weblogic 10.0 and newer.
+ * @goal clientgen10
+ * @requiresDependencyResolution compile
+ */
+public class ClientGen10Mojo
+ extends AbstractWeblogicMojo
+{
+
+ /**
+ * The filename of the war file to find the services. The file path is
+ * extracted from the artifact list.
+ *
+ * @parameter
+ */
+ private String warFileName;
+
+ /**
+ * The wsdl to client gen from. If warFileName is specified, this parameter
+ * is the root relative file to use when creating the URI for the wsdl.
+ *
+ * @parameter
+ */
+ private String inputWSDL;
+
+ /**
+ * The directory to output the generated code to.
+ *
+ * @parameter default-value="${basedir}/src/main/java"
+ */
+ private String outputDir;
+
+ /**
+ * The package name of the output code.
+ *
+ * @parameter default-value="com.test.webservice"
+ */
+ private String packageName;
+
+ /**
+ * The name of the service.
+ *
+ * @parameter
+ */
+ private String serviceName;
+
+ /**
+ * Output verbose messages
+ *
+ * @parameter default-value="false"
+ */
+ private boolean verbose;
+
+ /**
+ * Whether or not to use server types from the ear file in the client jar.
+ *
+ * @parameter default-value="false"
+ */
+ private boolean useServerTypes;
+
+ /**
+ * Sets whether or not to create the type conversions for a web service in
+ * the client.
+ *
+ * @parameter default-value="true"
+ */
+ private boolean autotype;
+
+ /**
+ * Sets whether or not to use the jaxRPCWrappedArrayStyle
+ *
+ * @parameter default-value="true"
+ */
+ private boolean jaxRPCWrappedArrayStyle;
+
+ /**
+ * This method will run client gen on the given WSDL.
+ *
+ * @throws MojoExecutionException Thrown if we fail to obtain the WSDL.
+ */
+ public void execute()
+ throws MojoExecutionException
+ {
+ super.execute();
+
+ if ( getLog().isInfoEnabled() )
+ {
+ getLog().info( "Weblogic client gen beginning " );
+ }
+ if ( getLog().isInfoEnabled() )
+ {
+ getLog().info( " Detailed client gen settings information " + this.toString() );
+ }
+
+ try
+ {
+ final ClientGenTask clientGen = new ClientGenTask();
+ // Set the classpath
+ final Project project = new Project();
+ project.setName( "clientgen" );
+ final Path path = new Path( project, WeblogicMojoUtilities
+ .getDependencies( this.getArtifacts(), this.getPluginArtifacts() ) );
+ clientGen.setProject( project );
+ clientGen.setClasspath( path );
+ clientGen.setVerbose( this.verbose );
+ clientGen.setDestDir( new File( this.outputDir ) );
+ clientGen.setPackageName( this.packageName );
+ clientGen.setIncludeGlobalTypes( this.useServerTypes );
+ clientGen.setJaxRPCWrappedArrayStyle( this.jaxRPCWrappedArrayStyle );
+ String wsdlUri;
+ if ( this.warFileName != null )
+ {
+ if ( getLog().isInfoEnabled() )
+ {
+ getLog().info(
+ " calculating wsdl URI from warFileName " + this.warFileName + " with wsdl " + this.inputWSDL );
+ }
+ wsdlUri = "jar:file:" + WeblogicMojoUtilities.getWarFileName( this.getArtifacts(), this.warFileName ) +
+ "!" + this.inputWSDL;
+ new File( this.inputWSDL ).toURI().toString();
+ if ( getLog().isInfoEnabled() )
+ {
+ getLog().info( " using " + wsdlUri + " for clientgen." );
+ }
+ }
+ else if ( this.inputWSDL.startsWith( "http" ) )
+ {
+ if ( getLog().isInfoEnabled() )
+ {
+ getLog().info( " using " + this.inputWSDL + " for clientgen." );
+ }
+ wsdlUri = this.inputWSDL;
+ }
+ else
+ {
+ wsdlUri = new File( this.inputWSDL ).toURI().toString();
+ if ( getLog().isInfoEnabled() )
+ {
+ getLog().info( " using " + wsdlUri + " for clientgen." );
+ }
+ }
+ clientGen.setWsdl( wsdlUri );
+ // set the service name if it is specified
+ if ( this.serviceName != null )
+ {
+ if ( getLog().isInfoEnabled() )
+ {
+ getLog().info( " generating client for service '" + this.serviceName + "'." );
+ }
+ clientGen.setServiceName( this.serviceName );
+ }
+ clientGen.execute();
+ }
+ catch ( Exception ex )
+ {
+ getLog().error( "Exception encountered during client gen", ex );
+ throw new MojoExecutionException( "Exception encountered during listapps", ex );
+ }
+ finally
+ {
+ WeblogicMojoUtilities.unsetWeblogicProtocolHandler();
+ }
+
+ if ( getLog().isInfoEnabled() )
+ {
+ getLog().info( "Weblogic client gen successful " );
+ }
+ }
+
+ /**
+ * Getter for property input WSDL.
+ *
+ * @return The value of input WSDL.
+ */
+ public String getInputWSDL()
+ {
+ return this.inputWSDL;
+ }
+
+ /**
+ * Setter for the input WSDL.
+ *
+ * @param inInputWSDL The value of input WSDL.
+ */
+ public void setInputWSDL( final String inInputWSDL )
+ {
+ this.inputWSDL = inInputWSDL;
+ }
+
+ /**
+ * Getter for property output dir.
+ *
+ * @return The value of output dir.
+ */
+ public String getOutputDir()
+ {
+ return this.outputDir;
+ }
+
+ /**
+ * Setter for the output dir.
+ *
+ * @param inOutputDir The value of output dir.
+ */
+ public void setOutputDir( final String inOutputDir )
+ {
+ this.outputDir = inOutputDir;
+ }
+
+ /**
+ * Getter for property package name.
+ *
+ * @return The value of package name.
+ */
+ public String getPackageName()
+ {
+ return this.packageName;
+ }
+
+ /**
+ * Setter for the package name.
+ *
+ * @param inPackageName The value of package name.
+ */
+ public void setPackageName( String inPackageName )
+ {
+ this.packageName = inPackageName;
+ }
+
+ /**
+ * Getter for property service name.
+ *
+ * @return The value of service name.
+ */
+ public String getServiceName()
+ {
+ return this.serviceName;
+ }
+
+ /**
+ * Setter for the service name.
+ *
+ * @param inServiceName The value of service name.
+ */
+ public void setServiceName( final String inServiceName )
+ {
+ this.serviceName = inServiceName;
+ }
+
+ /**
+ * toString method: creates a String representation of the object
+ *
+ * @return the String representation
+ */
+ public String toString()
+ {
+ StringBuffer buffer = new StringBuffer();
+ buffer.append( "ClientGen10Mojo[" );
+ buffer.append( "inputWSDL = " ).append( inputWSDL );
+ buffer.append( ", outputDir = " ).append( outputDir );
+ buffer.append( ", packageName = " ).append( packageName );
+ buffer.append( ", serviceName = " ).append( serviceName );
+ buffer.append( ", useServerTypes = " ).append( useServerTypes );
+ buffer.append( ", autotype = " ).append( autotype );
+ buffer.append( "]" );
+ return buffer.toString();
+ }
+
+ /**
+ * Getter for server types
+ *
+ * @return true if the client gen should use server type information
+ */
+ public boolean isUseServerTypes()
+ {
+ return useServerTypes;
+ }
+
+ /**
+ * Setter for server types
+ *
+ * @param useServerTypes - true if the client gen should use server types
+ */
+ public void setUseServerTypes( boolean useServerTypes )
+ {
+ this.useServerTypes = useServerTypes;
+ }
+
+ /**
+ * Getter for verbose messages
+ *
+ * @return true if the client gen should use verbose output
+ */
+ public boolean isVerbose()
+ {
+ return this.verbose;
+ }
+
+ /**
+ * Setter for verbose messages
+ *
+ * @param verbose - true of the clientgen should use verbose output
+ */
+ public void setVerbose( boolean verbose )
+ {
+ this.verbose = verbose;
+ }
+
+
+ /**
+ * Getter for autoType
+ *
+ * @return true if clientgen shoud autotype from the wsdl
+ */
+ public boolean isAutotype()
+ {
+ return this.autotype;
+ }
+
+ /**
+ * Setter for autoType
+ *
+ * @param autotype - true if the client should autotype
+ */
+ public void setAutotype( boolean autotype )
+ {
+ this.autotype = autotype;
+ }
+
+ /**
+ * Getter for warFileName
+ *
+ * @return the warFileName
+ */
+ public String getWarFileName()
+ {
+ return this.warFileName;
+ }
+
+ /**
+ * Setter for warFileName
+ *
+ * @param warFileName - the warFileName to set
+ */
+ public void setWarFileName( String warFileName )
+ {
+ this.warFileName = warFileName;
+ }
+
+ /**
+ * Getter for jaxRPCWrappedArrayStyle
+ *
+ * @return the jaxRPCWrappedArrayStyle
+ */
+ public boolean isJaxRPCWrappedArrayStyle()
+ {
+ return jaxRPCWrappedArrayStyle;
+ }
+
+ /**
+ * Setter for jaxRPCWrappedArrayStyle
+ *
+ * @param jaxRPCWrappedArrayStyle the jaxRPCWrappedArrayStyle to set
+ */
+ public void setJaxRPCWrappedArrayStyle( boolean jaxRPCWrappedArrayStyle )
+ {
+ this.jaxRPCWrappedArrayStyle = jaxRPCWrappedArrayStyle;
+ }
+}
Index: src/main/java/org/codehaus/mojo/weblogic/util/WeblogicMojoUtilities.java
===================================================================
--- src/main/java/org/codehaus/mojo/weblogic/util/WeblogicMojoUtilities.java (revision 10022)
+++ src/main/java/org/codehaus/mojo/weblogic/util/WeblogicMojoUtilities.java (working copy)
@@ -48,7 +48,7 @@
{
if ( "weblogic.utils".equals(System.getProperty("java.protocol.handler.pkgs") ) )
{
- System.setProperty( "java.protocol.handler.pkgs", null );
+ System.clearProperty( "java.protocol.handler.pkgs" );
}
}

Index: src/test/java/org/codehaus/mojo/weblogic/SimpleGoalMojoTest.java
===================================================================
--- src/test/java/org/codehaus/mojo/weblogic/SimpleGoalMojoTest.java (revision 10022)
+++ src/test/java/org/codehaus/mojo/weblogic/SimpleGoalMojoTest.java (working copy)
@@ -128,6 +128,21 @@
}

/**
+ * Test that we can find the deploy goal
+ *
+ * @throws Exception when the lookup fails
+ * @see org.codehaus.mojo.weblogic.ClientGen10Mojo
+ */
+ public void testMojoClientGen10Goal()
+ throws Exception
+ {
+
+ final ClientGen10Mojo mojo = (ClientGen10Mojo) lookupMojo( "clientgen10", this.testPom );
+
+ assertNotNull( mojo );
+ }
+
+ /**
* Test an invalid goal to be sure the valid ones are 'real'.
*
* @throws Exception - throws exception when something fails.



NB: This patch has been submitted as a bug report. Please comment or vote on this bug to get it pushed through.
We will deploy this update to the plug-in (here, with version number 2.9.3-SNAPSHOT) by simply running the goal as Maven install from Eclipse.

Now that we have a working client generation goal in our updated and installed plug-in, again, we will need to register a few more Weblogic libraries for our project.


  mvn install:install-file -DgroupId=weblogic -DartifactId=javax.jms -Dversion=1.1.1 -Dpackaging=jar -Dfile=C:\webservers\bea\modules\javax.jms_1.1.1.jar
  mvn install:install-file -DgroupId=weblogic -DartifactId=wseeclient -Dversion=10.3 -Dpackaging=jar -Dfile=C:\webservers\bea\wlserver_10.3\server\lib\wseeclient.jar



We can add these new project and plug-in dependencies, along with necessary configuration parameters to the pom.xml. Generally, I do not automate client generation, as published WSDLs infrequently change. You may have different project requirements, however.

<project ....>
    ....
    <dependencies>
        ....
        <dependency>
            <groupId>weblogic</groupId>
            <artifactId>wseeclient</artifactId>
            <version>10.3</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>weblogic</groupId>
            <artifactId>javax.xml.rpc</artifactId>
            <version>1.2.1</version>
            <scope>provided</scope>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            ....
            <plugin>
                ....
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>weblogic-maven-plugin</artifactId>
                <version>2.9.3-SNAPSHOT</version>
                <configuration>
                    ....
                    <inputWSDL>http://localhost:7001/timezra.blog.maven.weblogic/Echo?WSDL</inputWSDL>
                    <packageName>timezra.blog.maven.weblogic.ws.client</packageName>
                    <serviceName>Echo</serviceName>
                </configuration>
                <dependencies>
                    ....
                    <dependency>
                        <groupId>weblogic</groupId>
                        <artifactId>javax.jms</artifactId>
                        <version>1.1.1</version>
                        <scope>provided</scope>
                    </dependency>
                </dependencies>
            </plugin>
            ....
        </plugins>
        ....
    </build>
    ....
</project>



Our business component, src/main/java/timezra/blog/maven/weblogic/service/EchoService.java invokes the generated client.

package timezra.blog.maven.weblogic.service;

import java.rmi.RemoteException;
import javax.xml.rpc.ServiceException;
import timezra.blog.maven.weblogic.ws.client.Echo_Service;
import timezra.blog.maven.weblogic.ws.client.Echo_Service_Impl;

public class EchoService {

    public String say(final String phrase) {
        try {
            final Echo_Service echoService = new Echo_Service_Impl();
            return echoService.getEchoSoapPort().echo(phrase);
        } catch (final RemoteException e) {
            return "Putter, ka-chunk, piff.";
        } catch (final ServiceException e) {
            return "Gurgle, burble, glug.";
        }
    }
}



We will need a way to mediate the client invokation and the display of the response, so we will create a src/main/java/timezra/blog/maven/weblogic/controller/IsAnybodyThere.java controller.

package timezra.blog.maven.weblogic.controller;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import timezra.blog.maven.weblogic.service.EchoService;

public class IsAnybodyThere extends HttpServlet {

    private static final long serialVersionUID = -8205256394812150098L;

    @Override
    protected void doGet(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException {
        final String echo = new EchoService().say("Is there anybody in there?");
        req.setAttribute("echo", echo);
        req.getRequestDispatcher("echo.jsp").forward(req, resp);
    }
}



Our view, src/main/webapp/echo.jsp, will simply show the result of calling the service.

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>
        <h1>${echo}</h1>
    </body>
</html>



Finally, we will register our view in the web descriptor, web.xml.

....
<web-app ....>
    ....
    <servlet>
        <servlet-name>IsAnybodyThere</servlet-name>
        <servlet-class>timezra.blog.maven.weblogic.controller.IsAnybodyThere</servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>IsAnybodyThere</servlet-name>
        <url-pattern>/IsAnybodyThere</url-pattern>
    </servlet-mapping>
    ....
    </web-app>



Now, when we run full_deploy and open http://localhost:7001/timezra.blog.maven.weblogic/IsAnybodyThere in a browser, we will see the message "Is there anybody in there? ... there? ... there?".

Conclusion


While it certainly would have been possible to hook the Maven Ant plugin to the build script presented in a previous post for executing tasks that disguise the need to run the setDomainEnv script, this post provides a different approach through the existing weblogic-maven-plugin and thus eliminates the need for manipulating setDomainEnv entirely with a manageable amount of configuration in the pom.xml.

A Maven project that compiles a web service, generates a web service client, and deploys a WAR to Weblogic.

30 comments:

Unknown said...

Tim,
Thank you for the detailed explanation. I tried to follow it but ended up with the exception while running weblogic:jwsc. Here it is:
java.lang.RuntimeException: Unknown javadoc problem: result=1, root=null:
JAM: error - In doclet class com.bea.util.jam.internal.javadoc.JavadocRunner_150, method languageVersion must return LanguageVersion.

Any idea what could be causing it?
Thank you,
Paul

Tim Myer said...

Hi Paul,

Thank you for the feedback and the question.
From a cursory glance I would ask what version your $JAVA_HOME points to? From the error, I would guess 1.5. If this is the case, could you try using a 1.6 JDK?
I have not seen that particular error, but for the weblogic:jwsc goal, Weblogic is using some internal com.sun javadoc APIs.
I hope this helps! Let me know either way.

---Tim---

Unknown said...

I'm using 160_05. I tried both Sun and JRockit. Both fail with the same error.
Paul

Tim Myer said...

Hi Paul,
Thank you for checking that. Could you perhaps try pointing your $JAVA_HOME to 1.6.0_14? That version works for me.
---Tim---

Unknown said...

Tim,

It doesn't seem to be the weblogic plugin problem. I tried to invoke the jwsc task via antrun plugin and got the same error. However, if I just call the ant script from the antrun plugin, everything works fine.
Paul

Anonymous said...

Hi Tim,

Just fantastic, I replicated it at my end by following your post :)

Tim Myer said...

Hi Santosh,

Thanks for the feedback! I will be setting something similar up for a customer as a spike for an eventual transition from Ant to Maven. Fortunately, I have Nexus setup, so the manual installation of weblogic libraries in the local repository should be eliminated for the rest of my team. If you are setting up Maven and Weblogic for a team, you might consider using Nexus or Artifactory to make things slightly easier.

Cheers,
---Tim---

Anonymous said...

Hey guys, if you post your questions and bugs over on the jira site for the maven weblogic mojo, we'd be happy to take a look.

Jon

Tim Myer said...

Hi Jon,
Thanks for the feedback. In fact, the bug and patch (http://jira.codehaus.org/browse/MWEBLOGIC-3) were submitted to jira at the time this blog entry was originally posted.
Let me know if you need anything else,
---Tim---

Anonymous said...

We submitted a patch for 2.9.3-SNAPSHOT. there is also a perl script in the apt source you can use that will get all of the weblogic artifacts setup for you so you don't have to go through too much pain.

http://jira.codehaus.org/browse/MWEBLOGIC-9

Jassitze said...
This comment has been removed by the author.
Unknown said...

Thanks Tim. I am using Maven component in Hudson to build code checked in to SVN repository.
I was searching for a solution to this error:

[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] Failed to configure plugin parameters for: org.apache.maven.plugins:maven-deploy-plugin:2.4

check that the following section of the pom.xml is present and correct:




repo
Repository Name
scp://host/path/to/repo



repo
Repository Name
scp://host/path/to/repo




Your pom.xml file helped me resolve it. The url tag as you mentioned below fixed the issue and the build was successful again!





localRepository
Local Repository
file://${HOMEDRIVE}/Docume~1/${USERNAME}/.m2/repository


Tim Myer said...

Hi Vikram,

Thanks for the feedback, and I am happy the post was useful. If you find any improvements, please let me know!

---Tim---

shekar said...

Hello,

I have tried the same by using Nexus repository. I have downloaded the weblogic plugin and tried running JWSC task I am geting the following error.

Can you please look into this error.
BUILD FAILED
/wls_domains/CIT/cruisecontrol-bin-2.8.3/util/temp/build.xml:235: Deployment descriptor: /wls_domains/CIT/cruisecontrol-bin-2.8.3/util/temp/temp/_927vxb/web.xml does not exist.
at weblogic.wsee.tools.anttasks.JwscTask.execute(JwscTask.java:184)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:288)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:105)
at org.apache.tools.ant.Task.perform(Task.java:348)
at org.apache.tools.ant.Target.execute(Target.java:357)
at org.apache.tools.ant.Target.performTasks(Target.java:385)
at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1329)
at org.apache.tools.ant.Project.executeTarget(Project.java:1298)
at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
at org.apache.tools.ant.Project.executeTargets(Project.java:1181)
at org.apache.tools.ant.Main.runBuild(Main.java:698)
at org.apache.tools.ant.Main.startAnt(Main.java:199)
at org.apache.tools.ant.launch.Launcher.run(Launcher.java:257)
at org.apache.tools.ant.launch.Launcher.main(Launcher.java:104)
Caused by: Deployment descriptor: /wls_domains/CIT/cruisecontrol-bin-2.8.3/util/temp/temp/_927vxb/web.xml does not exist.
at org.apache.tools.ant.taskdefs.War.setWebxml(War.java:95)
at weblogic.wsee.tools.anttasks.JwscTask.jar(JwscTask.java:397)
at weblogic.wsee.tools.anttasks.JwscTask.pkg(JwscTask.java:331)
at weblogic.wsee.tools.anttasks.JwscTask.execute(JwscTask.java:166)
... 17 more
--- Nested Exception ---
Deployment descriptor: /wls_domains/CIT/cruisecontrol-bin-2.8.3/util/temp/temp/_927vxb/web.xml does not exist.
at org.apache.tools.ant.taskdefs.War.setWebxml(War.java:95)
at weblogic.wsee.tools.anttasks.JwscTask.jar(JwscTask.java:397)
at weblogic.wsee.tools.anttasks.JwscTask.pkg(JwscTask.java:331)
at weblogic.wsee.tools.anttasks.JwscTask.execute(JwscTask.java:166)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:288)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:105)
at org.apache.tools.ant.Task.perform(Task.java:348)
at org.apache.tools.ant.Target.execute(Target.java:357)
at org.apache.tools.ant.Target.performTasks(Target.java:385)
at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1329)
at org.apache.tools.ant.Project.executeTarget(Project.java:1298)
at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
at org.apache.tools.ant.Project.executeTargets(Project.java:1181)
at org.apache.tools.ant.Main.runBuild(Main.java:698)
at org.apache.tools.ant.Main.startAnt(Main.java:199)
at org.apache.tools.ant.launch.Launcher.run(Launcher.java:257)
at org.apache.tools.ant.launch.Launcher.main(Launcher.java:104)

kvkrishna said...

Hi,
I have the below exception, can any one please advice on the issue...

[BasicOperation.execute():423] : Initiating deploy operation for app, afm-tar-batch, on targets:
[BasicOperation.execute():425] : new-itac
weblogic.management.provider.EditWaitTimedOutException: Waited 0 milliseconds
at weblogic.management.provider.internal.EditLockManager.getEditLock(EditLockManager.java:255)
at weblogic.management.provider.internal.EditAccessImpl.acquireLock(EditAccessImpl.java:256)
at weblogic.management.provider.internal.EditAccessImpl.startEdit(EditAccessImpl.java:287)
at weblogic.deploy.internal.adminserver.EditAccessHelper.startEditSession(EditAccessHelper.java:72)
at weblogic.deploy.internal.adminserver.operations.AbstractOperation.execute(AbstractOperation.java:215)
at weblogic.management.deploy.internal.DeployerRuntimeImpl$2.run(DeployerRuntimeImpl.java:817)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
at weblogic.security.service.SecurityManager.runAs(Unknown Source)

wally said...

Thanks Tim!

With little modification I was able to run and deploy using maven weblogic mojo 2.9.1

-Walter

Nicola Camillo said...

Tim,
is it possible to use maven 1.x?
My problem is that my client use maven 1.x and is not planned to move to maven 2 or 3
Thanks

Tim Myer said...

Hi Nicola,

Personally, I have very limited exposure to Maven1, so I cannot answer your question directly.

I do strongly recommend, however, that, if your customer is doing any new development, you convince them to migrate at least to Maven2 since Maven1 has been in maintenance-only mode for years.
There are quite a few resources online for doing this migration.

SeBO said...

Thx - with this notes i've done my work much faster :).

BTW.
I can post my pom.xml for WLS 10.3.5 ;) here or on private mail: sebo[dot]poczta(at)wp[dot]pl

Tim Myer said...

Hi SeBO,

Thank you for the comment. Perhaps You could post your modifications to a site like github and put the link here. Just a thought.

---Tim---

SeBO said...

I uploaded file on one of my online storage: http://chomikuj.pl/sebekk23/Java/WLS1035/WebServicesMaven/pom,1115580899.xml. If anyone find error please send me email and I upadte this pom for others ;).

SeBO said...

Hi

I have a problem with WebService client generated by weblogic:clientgen. When i'm trying to invoke him i getting following error

java.rmi.RemoteException: unable to set value on the holder class; nested exception is:
java.lang.NoSuchFieldException: value
at pl.nbp.mailsms.client.Mailsmsservice_PortType_Stub.test(Mailsmsservice_PortType_Stub.java:29)
at pl.nbp.mailsms.client.TestClient.main(TestClient.java:21)
Caused by: java.lang.NoSuchFieldException: value
at java.lang.Class.getField(Class.java:1520)
at weblogic.webservice.core.rpc.StubImpl._setHolderValue(StubImpl.java:358)
at weblogic.webservice.core.rpc.StubImpl._invoke(StubImpl.java:323)
at pl.nbp.mailsms.client.Mailsmsservice_PortType_Stub.test(Mailsmsservice_PortType_Stub.java:27)
... 1 more


Client code is very simple:

public class TestClient {

/**
* @param args
*/
public static void main(String[] args) {
try
{
Mailsmsservice s = new Mailsmsservice_Impl();
Test t = new Test("dd");
TestResponse tr = new TestResponse("dd");

s.getMailsmsservice_PortType().test(t, new TestResponseHolder(tr));
}
catch(Exception e)
{
System.out.println("upps");
e.printStackTrace();
}

}
}

SeBO said...

Ok - i fix it with: weblogic:clientgen9 :)

SeBO said...

Another question:
How to force maven to include all resources (like weblogic.xml, wsdl etc.) to jar when packaging multimodule project ?
I have structure like this:
POM project
- EAR - project
- WAR - project with JSF and other stuff
- JAR (here i want to put all of WebServices)

I tried everything but no luck.

Tim Myer said...

Hi SeBO,

Did you put all the resources that you want to put in the JAR into the src/main/resources directory of the JAR project? I am not sure offhand why this approach would not work. Or am I misunderstanding your requirement?

---Tim---

SeBO said...

I found little workaround for this - i put everything into another war :). I have next question, because i can't find solution in internet i decide to ask it here :). I have simple project with WebServices and i need to enable basic authentication for those WS. I try some tutorials:
http://prowess.wordpress.com/2008/06/19/basic-authentication-for-rpc-style-web-services/
and
http://stackoverflow.com/questions/4621155/how-to-set-up-weblogic-10-3-3-security-for-jax-ws-web-services
but without luck i still get "403--Forbidden". Can you help me :)?

SeBO said...

OK - i got it :). I forgot about weblogic.xml in resources. But ... :) i notice that this plugin generates JAXRPC webservices instead JAXWS. Is there somekind of workaround for this ?

Tim Myer said...

Hi SeBO,

Good that you found a solution.

As for your JAXWS question, it looks like there is a solution that requires another modification to the JwscMojo in the weblogic-maven-plugin.

It seems that you need to specify the type of the jwsFileSet as "JAXWS". As for installing weblogic JARs to support JAXWS webservices, I am not sure off the top of my head which you would need.

Hope that helps!
---Tim---

SeBO said...

It was very helpful: plugin with JAXWS supprot is here http://chomikuj.pl/sebekk23/Java/WLS1035/Maven+plugin/weblogic-maven-plugin-2.9.2-SNAPSHOT,1416642515.jar

Tim Myer said...

You rock, SeBO! Thanks for posting the link.

---Tim---