Using Eclipse for multi-module Maven2 projects (part 2)

December 23, 2008 at 3:51 pm Leave a comment

In the first post we installed Eclipse and some plugins. Now we will start using the m2eclipse plugin to open and create Maven projects. This post will show how to create a Maven webapplication in Eclipse. The next post will digg deeper into multi-module projects.

Checkout project from SVN

If someone else already created a Maven project and you just want to check the code out you can right click on the project in the SVN Repositories view and select Checkout as Maven Project

Create a new Maven Web Project

Now we’ll create a new project from scratch. Select File>New>Maven Project and click next. We will be creating a web application so select the maven-archetype-webapp artifact. This ensures the correct directory structure for a web application, and the application will also be compatible with the Web Tools Platform in Eclipse. 

To run the project using WTP, you can just right click it and select Run As > Run On Server > Finish. WTP will create the server configuration and run the webapp on the server. You should see the (automatically created) “Hello World!” on the index.jsp page. 

The standard Maven convention is to create java sources inside the src/main/java folder. Create this folder by drilling down to src/main then right click and select new folder. You can also create the src/main/test folder if you plan to include unit tests in the project. After creating the folders right click the project and select Maven > Update Project Configuration so the Maven plugin recognizes the new folder. 

Many web applications have dependencies on javax.servlet:servlet-api and javax.servlet:jsp-api. These are required at compile time, but should not be packaged with the web application, because they are provided by the application server (e.g. see the tomcat/lib folder). The provided scope is used to handle such dependencies. Add the following lines to your pom.xml:

<dependency>
  <groupId>javax.servlet</groupId>
  <artifactId>servlet-api</artifactId>
  <version>2.4</version>
  <scope>provided</scope>
</dependency>
<dependency>
  <groupId>javax.servlet</groupId>
  <artifactId>jsp-api</artifactId>
  <version>2.0</version>
  <scope>provided</scope>
</dependency>

Because we want to compile with Java 1.6 we’ll set the compiler version to 1.6 in the pom file. Open the pom file, right click inside it and select add plugin, type in compiler and add the plugin. Add

<source>1.6</source>
<target>1.6</target>

inside the configuration tag. 

That’s it for our web project. In the next post I’ll show how to create a multi-module Maven2 project.

[part 1]
[part 3]

Advertisements

Entry filed under: java, Uncategorized. Tags: , , , , , , .

Serial com-port communication with autoIt Using Eclipse for multi-module Maven2 projects (part 3)

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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

Trackback this post  |  Subscribe to the comments via RSS Feed


Feeds

Articles to be written…

Twitter – kr3l

my del.icio.us

RSS Google Reader Shared Stuff

  • An error has occurred; the feed is probably down. Try again later.

RSS Listening to..

  • An error has occurred; the feed is probably down. Try again later.

%d bloggers like this: