SYS-CON MEDIA Authors: Carmen Gonzalez, Sean Houghton, Glenn Rossman, Ignacio M. Llorente, Xenia von Wedel

Blog Feed Post

UPDATED Setting up a JEE 6 Web Profile Maven Project in Eclipse using TomEE

This is an update to the blog post of just a few days ago. Never to leave well enough alone I have continued examining how to use Maven effectively in Eclipse. As such I have discovered some unneeded steps and some new details.

Without the excess wording this time here are the instructions.

Step 1:

Download and install (unzip into the folder of your choice) the Eclipse IDE for Java EE Developers from http://eclipse.org . The version, as of this writing, is 4.3.1. Since the introduction of version 4.3, also known as Kepler, the m2eclipse plugin for Maven is part of the distribution.

You must choose between a 32 and 64 bit version of this download. Here is a recent article on this subject: http://www.javacodegeeks.com/2012/12/should-i-use-a-32-or-a-64-bit-jvm.html . I use the 64 bit JVM.

Step 2:

Download and install (unzip into the folder of your choice) TomEE from http://tomee.apache.org/downloads.html . There are three versions but it does not matter which one you choose. I use the web profile version.

Step 3:

Run Eclipse and create a new workspace. Eclipse stores its settings inside of the workspace. This is why you need to reconfigure Eclipse whenever you create a new workspace. Since we must create a specialized configuration we need to create a new workspace. We will then be able to create as many web profile projects as we want in this workspace.

Step 4:

Inform Eclipse of the existence of TomEE. You do this by selecting Window -> Preferences -> Server -> Runtime Environment.

image1

Select Add and in the list box select Apache Tomcat v7.0 and click on Next.

image2

Browse to the directory into which you install TomEE. I also change the name of the server to Apache TomEE 1.6.0.  Click on Finish and then OK.

image3

Step 5:

The server we just defined now must be added to the workspace. Look for the Servers view usually found on a tab in a panel below the editor window. There is a link that reads “No servers are available. Click this link to create a new server…” Click on this link.

In the dialog that appears select the Apache Tomcat v7.0 Server. The server name and runtime should refer to the TomEE server you defined in the previous step. Click on Finish.

Step 6:

Now you are ready to create a Maven Web Project

Use File -> New -> Maven Project. If you don’t see Maven Project then select Other and you will find the Maven choices. Eclipse will eventually place Maven Project on the New listing.

At the first dialog make sure you check “Create a simple project (skip archetype selection)” and click on Next.

image4

Now you come to the Configure project dialog. This defines the basic information in the pom.xml file and the directory structure of the project.

Group Id: This is typically the root package name. I require that you use com.yourname such as com.kenfogel. I need you to do this so I know whose project I am looking at when I am grading. If you are reading this and not a student use whatever you feel is appropriate.

Artifact Id: This becomes the project name. When using Maven to package your code into the repository it will use the Group Id and Artifact Id as the location of your jar file. In this example I am using WebProfileExample so the full package style name will be com.kenfogel.WebProfileExample.

The package names you use for your classes does not have to be the same as the Groups Id and Artifact Id but most programmers choose to do so.

You can ignore Version.

Packaging cannot be ignored. The packaging you choose determines the directory structure of the project. If it says jar then pull down the combo box and change it to war.

Name and Description are field added to the pom.xml for informative purposes.

Click on Finish.

image5

Here is what the Project Explorer should look like:

image6

Step 7 – UPDATE:

The default Maven pom.xml file is minimal. It must have additional elements to allow you to successfully create code for the web profile of Java EE 6.

Currently it looks like:

<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>
 <groupId>com.kenfogel</groupId>
 <artifactId>WebProfileExample</artifactId>
 <version>0.0.1-SNAPSHOT</version>
 <packaging>war</packaging>
 <name>Web Profile Example</name>
 <description>Tutorial Eclipse and TomEE project</description>
</project>

Minimally it should look like this assuming you want to use Java 1.7 and JUnit 4:

<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>
   <groupId>com.kenfogel</groupId>
   <artifactId>WebProfileExample</artifactId>
   <version>0.0.1-SNAPSHOT</version>
   <packaging>war</packaging>
   <name>Web Profile Example</name>
   <description>Tutorial Eclipse and TomEE project</description>
   <dependencies>
      <dependency>
         <groupId>junit</groupId>
         <artifactId>junit</artifactId>
         <version>4.11</version>
         <scope>test</scope>
      </dependency>
      <dependency>
         <groupId>org.apache.openejb.maven</groupId>
         <artifactId>tomee-maven-plugin</artifactId>
         <version>1.6.0</version>
      </dependency>
   </dependencies>
   <build>
      <plugins>
         <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.1</version>
            <configuration>
               <source>1.7</source>
               <target>1.7</target>
            </configuration>
         </plugin>
         <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-war-plugin</artifactId>
            <version>2.4</version>
            <configuration>
               <failOnMissingWebXml>false</failOnMissingWebXml>
            </configuration>
         </plugin>
      </plugins>
   </build>
</project>

After updating the pom.xml file you must update the project. Save the updated pom.xml file. Right mouse click on the project and select Maven -> Update Project. Your project should appear with a check next to it in the dialog so all you need to do is click OK.

I am also working with NetBeans for the same purpose. Since NetBeans interacts with the server differently from Eclipse its pom.xml file requires additional lines that allows NetBeans to deploy the application. I will test to determine if the same Maven pom.xml can be used in both IDEs.

The old step 8 is no required. So there is now one less step.

Step 8:

There are more steps necessary for coding Java Server Faces and Servlets but this is the starting point. A quick test is to create a simple HTML file in the src/main/webapp folder.

image8

Right mouse click on the file and select Run As… -> Run on Server.

image9

Click on Finish and you should see:

image10

Now you are ready for the good stuff!

WebContent becomes src/main/webapp

When using Eclipse without Maven you use the Dynamic Web Project to create a web profile application. Such a project has a WebContent folder that contains WEB-INF, META-INF and other items found in this part of a site. A Maven war project requires that such parts of the application are placed in src/main/webapp. This folder will be created but it will be empty. You will need to create the WEB-INF and META-INF folders in this directory. If you right mouse click on Deployment Descriptor in the project and choose Generate Deployment Descriptor Stub it will create the WEB-INF and a web.xml file for you.

Maven Goal

This is still an area that I am fuzzy on. In Eclipse the Run As command does not invoke a Maven build. This means that it is necessary to first do a Maven Build and then a Run As. When doing this you are asked for the Goals. I came across the following that seems to do the trick:

compile war:war

Now I perform a Maven Build and then Run As and the project executes.

Read the original blog entry...

More Stories By Ken Fogel

In 1980 I bought for myself the most wonderful toy of the day, the Apple ][+. Obsession followed quickly and by 1983 I was writing software for small and medium sized businesses in Montreal for both the Apple and the IBM PC under the company name Omnibus Systems. In the evenings I taught continuing education courses that demystified the computer to the first generation of workers who found themselves with their typewriter on the scrap heap and a PC with WordStar taking its place. In 1990 I was invited to join the faculty at Dawson College in the Computer Science Technology program. When I joined the program the primary language was COBOL and my responsibility was to teach small systems languages such as BASIC and C/C++. Today I am now the chairperson and program coordinator of the Computer Science Technology program at Dawson. The program's primary language is Java and the focus is on enterprise programming. I like to write about the every day problems my students and I face in using various languages and platforms to get the job done. And from time to time I stray from the path and write about what I plan to do, what I actually get around to doing, and what I imagine I am doing.

Latest Stories
What do a firewall and a fortress have in common? They are no longer strong enough to protect the valuables housed inside. Like the walls of an old fortress, the cracks in the firewall are allowing the bad guys to slip in - unannounced and unnoticed. By the time these thieves get in, the damage is already done and the network is already compromised. Intellectual property is easily slipped out the back door leaving no trace of forced entry. If we want to reign in on these cybercriminals, it's hig...
We are reaching the end of the beginning with WebRTC, and real systems using this technology have begun to appear. One challenge that faces every WebRTC deployment (in some form or another) is identity management. For example, if you have an existing service – possibly built on a variety of different PaaS/SaaS offerings – and you want to add real-time communications you are faced with a challenge relating to user management, authentication, authorization, and validation. Service providers will w...
"ElasticBox is an enterprise company that makes it very easy for developers and IT ops to collaborate to develop, build and deploy applications on any cloud - private, public or hybrid," stated Monish Sharma, VP of Customer Success at ElasticBox, in this SYS-CON.tv interview at DevOps Summit, held Nov 4–6, 2014, at the Santa Clara Convention Center in Santa Clara, CA.
The term culture has had a polarizing effect among DevOps supporters. Some propose that culture change is critical for success with DevOps, but are remiss to define culture. Some talk about a DevOps culture but then reference activities that could lead to culture change and there are those that talk about culture change as a set of behaviors that need to be adopted by those in IT. There is no question that businesses successful in adopting a DevOps mindset have seen departmental culture change, ...
Explosive growth in connected devices. Enormous amounts of data for collection and analysis. Critical use of data for split-second decision making and actionable information. All three are factors in making the Internet of Things a reality. Yet, any one factor would have an IT organization pondering its infrastructure strategy. How should your organization enhance its IT framework to enable an Internet of Things implementation? In his session at Internet of @ThingsExpo, James Kirkland, Chief Ar...
WebRTC defines no default signaling protocol, causing fragmentation between WebRTC silos. SIP and XMPP provide possibilities, but come with considerable complexity and are not designed for use in a web environment. In his session at @ThingsExpo, Matthew Hodgson, technical co-founder of the Matrix.org, discussed how Matrix is a new non-profit Open Source Project that defines both a new HTTP-based standard for VoIP & IM signaling and provides reference implementations.
The 4th International DevOps Summit, co-located with16th International Cloud Expo – being held June 9-11, 2015, at the Javits Center in New York City, NY – announces that its Call for Papers is now open. Born out of proven success in agile development, cloud computing, and process automation, DevOps is a macro trend you cannot afford to miss. From showcase success stories from early adopters and web-scale businesses, DevOps is expanding to organizations of all sizes, including the world's large...
DevOps Summit 2015 New York, co-located with the 16th International Cloud Expo - to be held June 9-11, 2015, at the Javits Center in New York City, NY - announces that it is now accepting Keynote Proposals. The widespread success of cloud computing is driving the DevOps revolution in enterprise IT. Now as never before, development teams must communicate and collaborate in a dynamic, 24/7/365 environment. There is no time to wait for long development cycles that produce software that is obsolete...
The definition of IoT is not new, in fact it’s been around for over a decade. What has changed is the public's awareness that the technology we use on a daily basis has caught up on the vision of an always on, always connected world. If you look into the details of what comprises the IoT, you’ll see that it includes everything from cloud computing, Big Data analytics, “Things,” Web communication, applications, network, storage, etc. It is essentially including everything connected online from ha...
The security devil is always in the details of the attack: the ones you've endured, the ones you prepare yourself to fend off, and the ones that, you fear, will catch you completely unaware and defenseless. The Internet of Things (IoT) is nothing if not an endless proliferation of details. It's the vision of a world in which continuous Internet connectivity and addressability is embedded into a growing range of human artifacts, into the natural world, and even into our smartphones, appliances, a...
"SAP had made a big transition into the cloud as we believe it has significant value for our customers, drives innovation and is easy to consume. When you look at the SAP portfolio, SAP HANA is the underlying platform and it powers all of our platforms and all of our analytics," explained Thorsten Leiduck, VP ISVs & Digital Commerce at SAP, in this SYS-CON.tv interview at 15th Cloud Expo, held Nov 4-6, 2014, at the Santa Clara Convention Center in Santa Clara, CA.
The 3rd International Internet of @ThingsExpo, co-located with the 16th International Cloud Expo - to be held June 9-11, 2015, at the Javits Center in New York City, NY - announces that its Call for Papers is now open. The Internet of Things (IoT) is the biggest idea since the creation of the Worldwide Web more than 20 years ago.
SAP is delivering break-through innovation combined with fantastic user experience powered by the market-leading in-memory technology, SAP HANA. In his General Session at 15th Cloud Expo, Thorsten Leiduck, VP ISVs & Digital Commerce, SAP, discussed how SAP and partners provide cloud and hybrid cloud solutions as well as real-time Big Data offerings that help companies of all sizes and industries run better. SAP launched an application challenge to award the most innovative SAP HANA and SAP HANA...
Connected devices and the Internet of Things are getting significant momentum in 2014. In his session at Internet of @ThingsExpo, Jim Hunter, Chief Scientist & Technology Evangelist at Greenwave Systems, examined three key elements that together will drive mass adoption of the IoT before the end of 2015. The first element is the recent advent of robust open source protocols (like AllJoyn and WebRTC) that facilitate M2M communication. The second is broad availability of flexible, cost-effective ...
Scott Jenson leads a project called The Physical Web within the Chrome team at Google. Project members are working to take the scalability and openness of the web and use it to talk to the exponentially exploding range of smart devices. Nearly every company today working on the IoT comes up with the same basic solution: use my server and you'll be fine. But if we really believe there will be trillions of these devices, that just can't scale. We need a system that is open a scalable and by using ...