Practical Java Tips

Maximilian Berger


Project Management

Maven

Important Conventions

  • Project is described in pom.xml

  • Java source is in src/main/java

  • Java tests are in src/test/java

  • Webpage is in src/site

  • Artifacts go to target/

Example 1. Example pom.xml
<?xml version="1.0"?>
<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/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>at.uibk.ac.at.dps</groupId>
  <artifactId>sample</artifactId>
  <name>Sample Project</name>
  <version>0.1.0-SNAPSHOT</version>
  <inceptionYear>2009</inceptionYear>
  <licenses>
    <license>
      <name>GNU General Public License, Version 3.0</name>
      <url>http://www.gnu.org/licenses/gpl-3.0-standalone.html</url>
      <distribution>manual</distribution>
    </license>
  </licenses>
  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>2.0.2</version>
        <configuration>
          <source>1.5</source>
          <target>1.5</target>
          <debug>false</debug>
          <optimize>true</optimize>
        </configuration>
      </plugin>
    </plugins>
  </build>
  <dependencies>
    <dependency>
      <groupId>org.testng</groupId>
      <artifactId>testng</artifactId>
      <version>5.8</version>
      <type>jar</type>
      <classifier>jdk15</classifier>
      <scope>test</scope>
    </dependency>
    <dependency>
       <groupId>commons-logging</groupId>
       <artifactId>commons-logging</artifactId>
       <version>1.1.1</version>
    </dependency>
  </dependencies>
</project>

Important Maven commands

mvn test

Compile and run tests

mvn package

Compile, run tests, and package

mvn install

Compile, run tests, package, and install locally

mvn site

Run reports and generate website

For a list of available plugins use http://www.mvnrepository.com/ .

Other items that can be configured are

  • description

  • developers

  • contributors

  • scm