Create EAR file from the command line.


JayShenSharma has a nice blog at where he outlines some nice tutorials about getting Weblogic up and running.

In the tutorial on EJB3 Local Lookup sample he provides all of the code necessary to get things up and running.

Here are a couple of steps to make the tutorial a little easier.

Tutorial 39 layout

Directory layout for the tutorial.

  • Create a root folder and three sub-folders. There are some setup steps that need to be run – as detailed below.
  • sfsb3 – is where we can place the two java source files, and into whcih the Test.jar file will be compiled.
sfsb3 folder contents

sfsb3 folder contents

  • mwm39webapp – is where the jsp files will go. Underneath that, the WEB-INF is the location of the web.xml.
emm39webapp contents

emm39webapp contents

  •  mwm39ear will contain a “META-INF” folder inside of which will be an application.xml file.



Initial Setup:

This is outlined in the comments of the tutorial, however when you open up a command window at the root folder, you have to run a command to setup the appropriate environment.

For my setup (WebLogic 10.3.2) installed under windows, the command can be run as follows:

Running the setWLSEnv.cmd

Running the setWLSEnv.cmd

Following the tutorial

Creating the EJB jar file

* Change to the sfsb3 folder

Run the commands:

* compile the code:

<pre>javac -d .</pre>


<pre>javac -d .</pre>

These compile the source code into java class files. Note the fact that there is a “dot” in the midst of the commands. This will create a folder named sfsb3 – and place the class files into it.

<pre>jar -cvf Test.jar sfsb3 *.java</pre>

This creates a jar file – which will include all of the files in the sfsb3 folder, as well as all of the java files that are in the current directory.
The specifics of the command line are:

-c – create a new archive
– v – generate verbose output
-f – specify archive file name

The files name is “test.jar”. The files to include are

  1. Contenst of the sfsb3 folder
  2. All java files in the current folder.The jar command will also, within the jar file, create a META-INF folder – which contains a MANIFEST.MF file.

Creating the Web App

Change to the folder  mwm39webapp.
It will have the 2 jsp files in the root directory, and the web.xml in the WEB-INF folder.

The command to run is   jar -cvf mwm39webapp.war .
Please note the “dot” at the end.

This will create the Web Archive (WAR) file for the Web App. Note that it will include the WEB-INF folder and contents. This is because the file “dot” that was specified on the command line, is a directory – and the helpjar help specifies that “If any file is a directory then it is processed recursively.”

Summary Status

What we have at this point – is:

  • Test.jar – an EJB Jar file in the sfsb3 directory
  • mwm39webapp.war in the mwm39webapp directory
  • a folder mwm39ear that has a META-INF folder with an application.xml

First thing is to correct the application.xml. The tutorial uses a


however – we have compiled the war file to be mwm39webapp.war.
From the older Oracle documentation

Defines a Web application module in the application file. The web element contains a web-uri element and a context-root element.

Defines the location of a Web module in the application file. This is the name of the .war file.

Required. Specifies a context root for the Web application.



This means that we should use the war file name in the web-uri element.
The final version of application.xml is.


Creating the EAR file

To simplify the concepts of creating the EAR file – create a new folder (e.g. genear). Place the Test.jar, WAR file (mwm39webapp.war) and the META-INF containing the application.xml into that folder.



From the command line, run the command:

<code>jav -cvf mwm39EAR.ear .<code>

Note again that this command ends in a “dot”.

This will create an EAR file that will contain the jar and war files in the root, and also contain the META-INF file.

This can be deployed directly to a WLS that is installed on the localhost.


The console for WLS is located at: http://localhost:7001/console

The URL for the initial page is at: http://localhost:7001/mwm39webapp

This is the equivalent of: http://localhost:7001/mwm39webapp/index.jsp

The output of the page is:

Sample output of tutorial

Output of the local lookup EJB3 sample.

This entry was posted in java and tagged , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s