Monday, January 18, 2016

Using Maven based Application with WebSphere Application Server in eclipse

Using Maven based Application with WebSphere Application Server in eclipse

Today, I would like to share my thoughts about using maven based application with WebSphere in eclipse. As we know maven directory structure is little different than normal dynamic web project.  Let us understand how to deploy an Enterprise Application project in Maven structure on WebSphere to debug it on eclipse.

This is not so straight forward because Eclipse needs to know the new directory structure of source code to take you to the debug point.

To make this simpler to understand I would like to demo it using an example of Enterprise Maven Project. You can read about Best way to create an EAR maven project at my BLOG.
I would take my example of EAR project from my github project.


  1. I would suggest to use latest Eclipse . I would take example of Luna Eclipse.
You can download Luna Eclipse from here.

          

2. Maven plugin is required for this. If it is not present in your eclipse you can add it from Maven update site.


3. You eclipse should have IBM Webshpere Application Server  Developer tools, so that we can have webshpere maven integration setup available.
You can get IBM Webshpere Application Server  Developer tools from here.




4. To confirm you have got the Maven setting. Check in following location.



5. Set you required project to use Maven value. For example if you are going to use you dynamic projects to use maven structure with IBM Webshpere to debug it, you should set it to Maven value.

Once you are done with the above mentioned setup, I think you are good enough to get started. Restart the eclipse and start playing around with maven and WAS Integration projects.

Please share you view and feedbacks, Thanks,

CHEERS!!!

Monday, November 9, 2015

Maven Project Structure for Java Enterprise Application.

Maven Project Structure for Java Enterprise Application.
Today, I thought of sharing  the practice I follow for Java Enterprise Application maven projects.
Developers get confused what could be the best practice for organising the maven projects to that every project is streamlined. In case of EAR project, it’s a combination of WARs, EJBs, Jars. So Structure would look something like this:



So, For achieving this, Let us put the top EAR in a POM project which will be parent of all the projects, so that when we build the parent POM it should build all the child projects and the EAR should be ready to be deployed.
Let us understand this by creating a sample example which includes all the above mentioned EAR artifacts.

1   1.     First create a Parent POM Project. If you are using eclipse with maven plugins to create maven project:




This will create a maven Project whose packaging type would be pom type.

<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/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <parent>
    <groupId>com.integration</groupId>
    <artifactId>ApplicationParent</artifactId>
    <version>1.0-SNAPSHOT</version>
  </parent>
  <artifactId>ApplicationEAR</artifactId>
  <packaging>ear</packaging>
  <name>Application EAR</name>
  <dependencies>
       <dependency>
              <groupId>com.integration</groupId>
              <artifactId>ApplicationWAR</artifactId>
              <version>1.0-SNAPSHOT</version>
              <type>war</type>
       </dependency>
       <dependency>
              <groupId>com.integration</groupId>
              <artifactId>ApplicationJAR</artifactId>
              <version>1.0-SNAPSHOT</version>
       </dependency>
       <dependency>
              <groupId>com.integration</groupId>
              <artifactId>ApplicationEJB</artifactId>
              <version>1.0-SNAPSHOT</version>
              <type>ejb</type>
       </dependency>
  </dependencies>
  <build>
        <plugins>
            <plugin>
                <artifactId>maven-ear-plugin</artifactId>
                <configuration>
                    <modules>
                        <webModule>
                            <groupId>com.integration</groupId>
                            <artifactId>ApplicationWAR</artifactId>
                        </webModule>
                        <ejbModule>
                           <groupId>com.integration</groupId>
                            <artifactId>ApplicationEJB</artifactId>
                        </ejbModule>
                        <jarModule>
                           <groupId>com.integration</groupId>
                            <artifactId>ApplicationJAR</artifactId>
                        </jarModule>
                    </modules>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

2     2.   Now create the War Project.



Its Packaging type would be WAR.           
<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/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <parent>
    <groupId>com.integration</groupId>
    <artifactId>ApplicationParent</artifactId>
    <version>1.0-SNAPSHOT</version>
  </parent>
  <artifactId>ApplicationWAR</artifactId>
  <packaging>war</packaging>
  <name>Application WAR</name>
  <dependencies>
       <dependency>
              <groupId>com.integration</groupId>
              <artifactId>ApplicationJAR</artifactId>
              <version>1.0-SNAPSHOT</version>
       </dependency>
       <dependency>
              <groupId>com.integration</groupId>
              <artifactId>ApplicationEJB</artifactId>
              <version>1.0-SNAPSHOT</version>
              <type>ejb</type>
       </dependency>
  </dependencies>
</project>

           3. Create an EJB Project.



Its Packaging type would be EJB.
<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/xsd/maven-4.0.0.xsd">
       <modelVersion>4.0.0</modelVersion>
       <parent>
              <groupId>com.integration</groupId>
              <artifactId>ApplicationParent</artifactId>
              <version>1.0-SNAPSHOT</version>
       </parent>
       <artifactId>ApplicationEJB</artifactId>
       <packaging>ejb</packaging>
       <name>Application EJB</name>
       <dependencies>
              <dependency>
                     <groupId>javax</groupId>
                     <artifactId>javaee-api</artifactId>
                     <version>7.0</version>
              </dependency>
              <dependency>
                     <groupId>com.integration</groupId>
                     <artifactId>ApplicationJAR</artifactId>
                     <version>1.0-SNAPSHOT</version>
              </dependency>
       </dependencies>
       <build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-ejb-plugin</artifactId>
            <configuration>
                <ejbVersion>3.0</ejbVersion>
            </configuration>
        </plugin>
    </plugins>
</build>
</project>

4. Create an JAR Project.



Its Packaging type would be JAR.
<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/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <parent>
    <groupId>com.integration</groupId>
    <artifactId>ApplicationParent</artifactId>
    <version>1.0-SNAPSHOT</version>
  </parent>
  <artifactId>ApplicationJAR</artifactId>
  <name>Application JAR</name>
</project>
From Eclipse UI, You can go to overview tab of ApplicationParent pom.xml file and add the modules which needs to be built.



The overall Project Structure would look like this:






Step to run the maven install command. Open command prompt, go to ApplicationParent project locatrion and run ‘mvn clean install’



This should give beautiful build status on the command prompt screen.




You can have the sample example in my github repo:


Suggestions and feedbacks most welcome!!!!

CHEERS!!!!