Pages

Monday, July 5, 2010

Maven With Weblogic

Share it Please
 
In my previous articles, we have seen how to create a sample web application and deploy them in Tomcat container. In this article we will see how to create a sample web application and deploy the application in Weblogic 10.3. We will also see what are the things necessary in order to deploy the application to Weblogic 10.3.

Creating the Sample web Application – we will be using the same sample web application that we have created in the previous article [View Here]. Follow the instructions in the article for creating the sample web application in maven.

So now the application is created, servlets are added and web.xml file is updated.

Deploying the Application in Weblogic 10.3: for deploying the war file in Weblogic 10.3, we will use the maven plug-in from Maven 2 Weblogic Plugin.

We will add the plugin to the POM file generated like,

<plugins>
   <plugin>
       <groupId>org.codehaus.mojo</groupId>
       <artifactId>weblogic-maven-plugin</artifactId>
       <version>2.9.1</version>
    </plugin>
  </plugins>

So once the plugin is added to the PIM file, we need to add the Weblogic specific information like,

Admin server Host Name – localhost.
server name – the name of the server to deploy.
port number – 80.
protocol = t3.
username , password.
upload – true for upload the code to server.
noExit – tells weblogic not to exit if there is a deployment failure.
targetNames- A comma seperated list of names of servers or clusters to deploy the artifact onto.

The sample configurations that I used in this application is

<configuration>
          <adminServerHostName>localhost</adminServerHostName>
          <adminServerPort>80</adminServerPort>
          <adminServerProtocol>t3</adminServerProtocol>
          <userId>userName</userId>
          <password>password</password>
          <upload>true</upload>
          <remote>true</remote>
          <verbose>false</verbose>
          <debug>false</debug>
          <targetNames>admin</targetNames>
          <noExit>true</noExit>
</configuration>

So now the complete plugin in POM file looks like

<plugin>
          <groupId>org.codehaus.mojo</groupId>
          <artifactId>weblogic-maven-plugin</artifactId>
          <version>2.9.1</version>
          <configuration>
          <adminServerHostName>localhost</adminServerHostName>
          <adminServerPort>80</adminServerPort>
          <adminServerProtocol>t3</adminServerProtocol>
          <userId>system</userId>
          <password>weblogic1</password>
          <upload>true</upload>
          <remote>true</remote>
          <verbose>false</verbose>
          <debug>false</debug>
          <targetNames>desktop_server</targetNames>
           <noExit>true</noExit>
        </configuration>
        </plugin>
  </plugins>

And now from the plugin documentation, we need to make sure that there is a repository access for the sandbox plugins.These sand box plugins are not deployed to the maven central repository and such are not available out of the box. So we need to make some changes to the POM file and setting.xml file in order to access the sandbox plugins

In POM file, make sure to add repositories and pluginRepositories elements as below.

<repositories>
    <repository>
      <id>Codehaus Snapshots</id>
      <url>http://snapshots.repository.codehaus.org/</url>
      <snapshots>
        <enabled>true</enabled>
      </snapshots>
      <releases>
        <enabled>false</enabled>
      </releases>
    </repository>
  </repositories>
 
 
  <pluginRepositories>
    <pluginRepository>
      <id>Codehaus Snapshots</id>
      <url>http://snapshots.repository.codehaus.org/</url>
      <snapshots>
        <enabled>true</enabled>
      </snapshots>
      <releases>
        <enabled>true</enabled>  <!-- Workaround for MNG-2974, see note below -->
      </releases>
    </pluginRepository>
  </pluginRepositories>

And once this is done we need to make some modifications in setting.xml file which is located in conf directory. We will be adding a profile in the setting.xml file like,

<profile>
      <id>Snapshots</id>
      <repositories>
        <repository>
          <id>Codehaus Snapshots</id>
          <url>http://snapshots.repository.codehaus.org/</url>
          <snapshots>
            <enabled>true</enabled>
          </snapshots>
          <releases>
            <enabled>false</enabled>
          </releases>
        </repository>
      </repositories>
      <pluginRepositories>
        <pluginRepository>
          <id>Codehaus Snapshots</id>
          <url>http://snapshots.repository.codehaus.org/</url>
          <snapshots>
            <enabled>true</enabled>
          </snapshots>
          <releases>
            <enabled>true</enabled>  <!-- Workaround for MNG-2974, see note below -->
          </releases>
        </pluginRepository>
      </pluginRepositories>
    </profile>
  </profiles>
 
  <activeProfiles>
    <activeProfile>Snapshots</activeProfile>
  </activeProfiles>

And once these modifications are done, we are ready with the POM file.

When we install the plug-in and try to deploy the war file to Weblogic, we will see a lot of artifact not available errors since maven needs some jars for the Weblogic in order to support deployment.

Creating Weblogic full client jar file – when we write applications involving jms/jmx/ejb we need the client applications to invoke them .but the client applications require some jars from Weblogic in order to invoke them. Rather than adding all the necessary jars on the client side we will create a Weblogic full client jar and give it to client.This jar file is of 60MB and supports all types of protocols. So how can we create this?  

cd WL_HOME/server/lib and execute the command
java -jar wljarbuilder.jar.
wlfullclient.jar is generated in the lib directory.

So now we have the wlfullclient jar file which will be set in our repository for allowing maven to perform operations on Weblogic.

Installing the wlfullclient.jar – in order to install the wlfullclient.jar file into our local repository and make the jar available to maven while performing operations on Weblogic, we need to manually install the jar file into local repository. We are doing this since Weblogic jars are third party jars and are not hosted on maven repositories.

mvn install:install-file -DgroupId=weblogic -DartifactId=weblogic -Dversion=10.3  -Dpackaging=jar -Dfile=C:\software\bea\weblogic\10.3\sp0\server\lib\wlfullclient.jar

You can also use the manual install if you don’t have the jars available in repositories. Once you execute the command you can check in your local repository for this jar file.

We will now execute the install command
mvn –e install “ installs all the plugins necessary for the deployment”

Once install is done, you can check for the war file in the target folder.

now execute the command
mvn –e Weblogic:deploy

This deploys the war file into the Weblogic. Make sure the Weblogic is started.
Some exceptions that I faced ,

Caused by: java.lang.IllegalArgumentException: Failed to contact t3://localhost:7001, javax.naming.CommunicationException [ is java.net.ConnectException: t3://localhost:7001:
Destination unreachable; nested exception is: ….]

 in this case you need to make sure that the listen port is 7001 or some other .for this just go to the server and check the config file in server for <listen-port> value and modify in the adminServerPort value in POM file.

weblogic.rmi.extensions.RemoteRuntimeException: Unexpected Exception - with nested exception: [weblogic.rjvm.PeerGoneException: ; nested exception is:
java.rmi.UnmarshalException: Incoming message header or abbreviation processing failed ; nested exception is: java.io.InvalidClassException: javax.management.ObjectName; local class incompatible: stream classdesc serialVersionUID = -546779
5090068647408, local class serialVersionUID = 1081892073854801359]

In this case you need to make sure the compiler for the both the cases are similar. The serial versions for the both classes are different.

There are many articles coming , so Happy Coding.....

9 comments :

  1. Good day! I could have sworn I've been to this site before but after
    reading through some of the post I realized it's
    new to me. Anyhow, I'm definitely glad I found
    it and I'll be book-marking and checking back frequently!



    my web blog :: Agen Judi Bola Terbesar Di Indonesia

    ReplyDelete
  2. Fantastic goods from you, man. I have understand your stuff previous to and you are just extremely magnificent.
    I actually like what you've acquired here, really like
    what you are saying and the way in which you say it. You make it enjoyable and you still care
    for to keep it smart. I cant wait to read
    much more from you. This is actually a wonderful site.

    ReplyDelete
  3. This piece of writing will assist the internet people for building up new website
    or even a weblog from start to end.

    ReplyDelete
  4. For most recent information you have to pay a quick visit web
    and on world-wide-web I found this website as a finest web page for most recent updates.

    ReplyDelete
  5. My family always say that I am killing my time here at web, except I know
    I am getting know-how every day by reading such good articles.

    ReplyDelete
  6. Hey! This is my 1st comment here so I just wanted to give a quick shout out and tell you I
    truly enjoy reading your articles. Can you suggest any other blogs/websites/forums that cover
    the same topics? Thanks for your time!

    ReplyDelete
  7. Hi there! This article could not be written much better!
    Looking at this post reminds me of my previous roommate!
    He always kept preaching about this. I am going to send this article
    to him. Pretty sure he will have a very good read. Thanks
    for sharing!

    ReplyDelete
  8. Wohh precisely what I was searching for, regards for posting.

    ReplyDelete
  9. This piece of writing is genuinely a pleasant one it assists new net people,
    who are wishing in favor of blogging.

    ReplyDelete