Download latest Maven unzip it and add it to your path:
# go to the place you want to install Maven to cd ~/Library # download latest Maven version curl -O http://apache.autinity.de/maven/binaries/apache-maven-2.2.1-bin.zip # unzip the archive unzip apache-maven-2.2.1-bin.zip # add a symlink for convenience ln -s apache-maven-2.2.1 maven # add Maven executables to the PATH echo export PATH="~/Library/maven/bin":\$PATH >> ~/.profile # open a new bash and check Maven is running mvn --version
Now that Maven is running on your system, you can use it to create a standard webapp:
# go to the workspace cd ~/Documents/workspace/ # let Maven create a webapp mvn archetype:generate -DgroupId=de.nofail -DartifactId=tmp -Dversion=1.0.0-SNAPSHOT -DarchetypeArtifactId=maven-archetype-webapp # go to the webapp cd tomcat-logging/ # let Maven create a distributable war mvn clean package
Maven is a stupid fuck, so it will create your application with Java 1.4 compatibility by default. You need to fix this in the pom.xml by changing the compiler plugin:
... <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>2.0.2</version> <configuration> <source>1.6</source> <target>1.6</target> </configuration> </plugin> ...
You can run the example directly from the command line through Maven:
mvn jetty:run & open http://localhost:8080/tomcat-logging/
The Maven Jetty plugin is configured (no, this is no default!) to pick up changes to the sources every 10 seconds. The plugin does not do hot code replacement but instead restarts the whole servlet context, which is very slow. So if you play around with the code, you should consider doing it within Eclipse.
Maven has an embedded task to build up an Eclipse .classpath and .project file from an existing pom.xml :
# configure your workspace (do not use ~ to point to your home!) mvn eclipse:configure-workspace -Declipse.workspace=../ # create Eclipse files mvn eclipse:eclipse
The resulting Eclipse configuration sets the Java compiler to Java 1.4 and sets a bad JRE System Library which you should reset to the default.
If you want a better solution, you need to install some Eclipse plugins that enable you to run the example form within Eclipse.
Install m2eclipse and run jetty run from their update sites.
Restart Eclipse and import existing Project tomcat-logging into Workspace.
Go to Debug Configurations and use the tomcat-logging launcher.
You should be able to open the servlet in your browser.
Run the servlet and change something in the tomcat-logging-log4j.xml configuration file. The behavior of log4j should change while the servlet is running.
Have a look at the Mavenrepository if you are looking for any libs.