Introduction
Recently I started working with Maven for new Lucee-based web applications. I'd like to share what I've learned so far. I will be using Eclipse WTP for this series, as it provides everything I need to run the app from one spot.
My setup:
* Eclipse 4.1 Mars
* Eclipse WTP tools, including the necessary servlet container connector run Tomcat
* Tomcat 8
* Java 8
* Eclipse J2EE tools
* M2E
* EGit
* CFEclipse
For this series, I will assume that you have a Tomcat server instance registered in your Eclipse IDE.
Part 1: Basic Dynamic Web App
Create the project:
For this post, I am starting off by creating a new Dynamic Web Project:
mvn package to generate your war file. Hope this proves helpful to someone.
I chose this instead of starting from a maven archetype, because the sample webapp archetype is set on servlet api version 2.5, and I want to be able to configure it myself. I've selected 3.1 for this example:
However, because I chose to do this, I have to make some changes to the default source folders to make it maven-friendly:
Now that I have a basic project created, I can add Maven support:
At this point, I now have a project that I can begin adding content. You can add index.html to your src/main/webapp directory, then right-click the project folder and select Run As > Run on Server.
Now to set up Lucee. I will be working with the most recent release candidate for this example. It is available on maven central. However, if you want to work with the latest snapshot, those are available (at least at the time of writing this) on Sonatype's snapshots repo:
<repositories>
<repository>
<id>sonatype-snapshots</id>
<url>https://oss.sonatype.org/content/repositories/snapshots/</url>
</repository>
</repositories>
Now to add the dependencies:
<dependencies>
<dependency>
<groupId>org.lucee</groupId>
<artifactId>lucee</artifactId>
<version>5.0.0.213-RC</version>
<!-- all the runtime dependencies are embedded or will be downloaded on demand by lucee -->
<exclusions>
<exclusion>
<artifactId>*</artifactId>
<groupId>*</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
First I add the lucee dependency. It has several transitive dependencies that are not necessary, so I excluded all of them. It does have one dependency that is necessary - that being felix. Right now, the required version is 4.2.1. There is talk of bundling the felix runtime into the lucee jar, so in the future, this dependency could be eliminated also. Finally, for Eclipse to work properly, you either need to add a runtime library to the project, or add the servlet-api. It is not necessary to include this into the final war, so set the scope to provided.
The last thing to do is to add the servlets/mappings to src/main/webapp/WEB-INF/web.xml (you can see an example here), and then you can add your application files to src/main/webapp.
Now you can run your application from within Eclipse, or use






No comments:
Post a Comment