Wednesday, April 3, 2013

Maven Deploy to Oracle Weblogic. Step By Step. The Basics. Part 4/4

This is a series of  four (4) articles that will describe how to use Maven and deploy a sample application to Weblogic.

Contents of each part:

There are no assumptions here and we are going to do everything from scratch.

There is always a person out there that will have to use those technologies together without knowing any of them.

So Far
Up to this point, we spent some time trying to get acquainted with various stuff.. We learned about Maven.. we learned about Weblogic, we learned a bit about Netbeans and we have created two maven projects.

Aaand.. at this final part of this series.. we are going to deploy our maven applications to our weblogic server.

Everything is setup and all we have to do is a few more steps.

Remember when we talked about Maven is using plugins?
Well, this is what we have to do, use a plugin that will help us deploy our maven application.
But which plugin?

Oracle provides a way in doing things

  • wls-maven-plugin—Delivered in WebLogic Server 12c, provides enhanced functionality to install, start and stop servers, create domains, execute WLST scripts, and compile and deploy applications. In addition to its shortened, easier to specify name, the extended functionality in the wls-maven-plugin requires a local WebLogic Server installation, in contrast to the weblogic-maven-plugin, which is generated as a standalone, self-contained JAR file. However, with the wls-maven-plugin, you can install WebLogic Server from within your Maven environment to fulfill the local WebLogic Server requirement. For more information about this plug-in, see Configuring the WebLogic Development Maven Plug-In..

So we understand that Weblogic 12c already provides the maven plugin for us.

All we have to do is to install  that plugin to our repository.
Locate the plugin and the pom.xml 
According to the documentation

The wls-maven-plugin is located in the MW_HOME/wlserver_12.1/server/lib directory, where MW_HOME represents the top-level installation directory for all Fusion Middleware products installed on one machine; for example, c:\Oracle\Middleware. The plug-in is provided as a pre-built JAR file and accompanying pom.xml file:
  • MW_HOME/wlserver_12.1/server/lib/wls-maven-plugin.jar
  • MW_HOME/wlserver_12.1/server/lib/pom.xml

In our case (for this example):


Now that we have located them. Lets install it.
Open a command prompt and navigate to  C:\Oracle\Middleware\wls1211\wlserver_12.1\server\lib\ (or your middleware home\wlserver_12.1\server\lib)

Next, execute the following command

mvn install -Dfile=wls-maven-plugin.jar -DpomFile=pom.xml

Normally you will see a BUILD SUCCESS at the end.

In case you dont remember what mvn install  is and what it does, check out this link

According to the official documentation:
is used to automatically install the project's main artifact (the JAR, WAR or EAR), its POM and any attached artifacts (sources, javadoc, etc) produced by a particular project.

Next, you have to call the install-file goal in order to place the files in the proper place in the local repository (
as the documentation says here:

mvn install:install-file -Dfile=wls-maven-plugin.jar -DpomFile=pom.xml
 Normally you will see a BUILD SUCCESS at the end. 
The above goal, will set up everything properly for us. So what we have done so far is:

We installed the project's main artifact, which is the wls-maven-plugin, and we then setup everything properly to our local repository.

How do we know that? How do we know that we have done everything ok?
First of all, we have just added a new plugin into our local repository. How do we call it?
Where is it installed?

It is easy to find, if you paid attention to the install:install-file

ok so we know where is the plugin, under But how do we call the plugin's goals?

with the following command:


Now, that is a bit long, isnt it? It would be great if we could do something like the following:
mvn wls:help ? right? It certainly looks better and easier to remember.
In order to do that we have to do   two things:

1) Assign a prefix to our plugin. But wait! this is already done by Oracle. As you remember there is a pom.xml in the lib folder

So this means that we can skip the wls-maven-plugin part and type simply wls.
More on the plugin prefixes:

2) Map the prefix to a pluginGroup for wls. In order to have it working, we have to map the new prefix to a pluginGroup. In our case, it is  We create the pluginGroup in the settings.xml of our m2 folder. In my case, it is

As you can see, we have now added a pluginGroup that will help us work with our prefix.

Lets try now the following:

mvn wls:help
 Nice isnt it?? If everything went well, it will print you the list of goals of this plugin followed by a BUILD SUCCESS.

How to Use it.
We have done the learning..
We have done the setup
We have done the configuration

Let us now make it all work together!

First things first. We have to include our new plugin (wls) in our maven application.
In order to do that, we have to edit the pom.xml file in each of our applications.

In both cases we have to add the following:

CmdMvnApp pom.xml (no IDE app): 

Then go to cmd line and navigate to the location of the pom.xml of the project and type

mvn package

NetbeansMvnApp pom.xml (Netbeans app):

Build the Project:

Next step is to deploy! right?
wrong.. Why? simply because,  we have to answer some logical questions..

-Where are we going to deploy the application?
hmm... you didnt see that coming right?
Wait wait wait... according to the official documentation:

The wls-maven-plugin follows the Maven theme and uses a convention-over-configuration approach. Thus, for a set of commonly used configuration elements, the plug-in supplies an appropriate, consistent set of default values that you can use across all of the goals. This reduces the degree of configuration required for you to use the plug-in and helps you to achieve uniform goal executions, even in different environments. The common configuration elements and their default values are:
  • middlewareHome: ${basedir}/Oracle/Software, where ${basedir} is the standard Maven project property which represents the directory containing the current Maven project.
  • weblogicHome: wlserver or wlserver_12.1 depending on the install type.
  • domainHome: ${basedir}/Oracle/Domains
  • source: ${}/${project.artifactId}.${project.packaging}
  • adminurl: t3://localhost:7001
Now, according to this, we should be able to deploy just like that. Right? Wrong..
-=Why do you keep saying wrong all the time!!!!
ok. just try it then.

I will!
mvn wls:deploy

Hmmm.. something went wrong...
No kidding..
A few questions first..
Why did we use the wls:deploy ?
Founded it here:

Deploys WebLogic Server applications and modules. Supports all deployment formats; for example, WAR, JAR, and such
Oh ok.

So based on that, lets start the server then..

mvn wls:start-server
hmmmm... still the same error..
Ofcourse it is the same error!!
Read carefully:
middlewareHome: ${basedir}/Oracle/Software, where ${basedir} is the standard Maven project property which represents the directory containing the current Maven project.

Is there any chance (in this series of articles) to have your Middlware home inside the Maven project?

Right. So. we have to set the proper middlware home value and probably more values prior to deploying.

Lets focus on starting the Weblogic Server 12c with Maven.
For the sace of this example, we are going to use some parameters of the start-server goal as described in the official documentation. 

Ok, so we see in the above link that we have to configure several parameters prior to starting the weblogic server. In order to do that, we have to configure our Maven weblogic plugin with the appropriate values.

Configuring the Maven plugin is fairly easy. Here is a refresher

So in this example, the following configuration will be enough to start the server:

Now, go ahead and type mvn wls:start-server (remember that you are executing a command from within the Maven project folder where the pom.xml resides.)

After a few seconds you will the following message:

Server started successful
Now, go and test your console. Go to a browser and type localhost:7001/console (or whatever your ip and port)

Nice isnt it??
Hang on!
What if I do it again?
What do you mean?
What if I type the same command again! Will I crash it???

See?? All good. I am sure you can change the maven plugin configuration in order to be able to stop the weblogic server.

Gonfiguration for deployment.
We will update the current configuration in order to be able to deploy our application onto Weblogic (expecially now that we have it up and running!!). Hopefully by now, you will not need to read further and you will be able to make the adjustments on your own.
However, here is the configuration.

On the Command Line type mvn wls:deploy
 and thats it!

So here we are! we managed to deploy our application from the command line using Maven!!!

Now, in order to finalize this series, we are going to do the same with Netbeans.
First we update the pom.xml of the NetbeansMvnApp as the previous one (CmdMvnApp)
Next, we have to create a goal in NetBeans for this project:

And thas it!
This will deploy the application onto Weblogic!

It wasnt that hard! was it??

Of course there are many other goals to configure such as re-deploy, stop-server etc. But I am pretty sure that it will be straightforward from now on!
Still confused?
Start Over!

1 comment:

  1. Excellent post and easy to follow instructions. Thanks for your help.



Related Posts Plugin for WordPress, Blogger...