Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@florianthiery
Last active August 16, 2017 14:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save florianthiery/0f8c0c015555939c96eb13428bbf1cd4 to your computer and use it in GitHub Desktop.
Save florianthiery/0f8c0c015555939c96eb13428bbf1cd4 to your computer and use it in GitHub Desktop.
Configurations for JAVA projects using MAVEN

Configurations for JAVA projects using Maven

License: CC BY 4.0

Florian Thiery M.Sc.

Römisch-Germanisches Zentralmuseum (RGZM)

i3mainz - Institut für Raumbezogene Informations- und Messtechnik

example files

pom.xml

  • artifactId: one word in small letters

  • groupId: topLevelDomain.githubUserName.artifactId z.B. de.rgzm.barlib

  • version: 1.0-SNAPSHOT until a release for 1.0 is available

  • name: short human readable name

  • description: short human readable description

  • url: link to git repo

  • licenses: link to license in git repo

  • organization: real organization

  • scm: link to git repo

  • developers: all developers

  • finalName: same as artifactId without version

  • repositories:

    • add jitpack.io for JAR including
  • plugins:

    • buildnumber-maven-plugin: get build number from git
    • maven-surefire-report-plugin: write tests as html
    • maven-javadoc-plugin: write tests and javadoc as html
    • exec-maven-plugin: possibility to run main class in maven

load JAR via jitpack.io

<repositories>
 <repository>
   <id>jitpack.io</id>
   <url>https://jitpack.io</url>
 </repository>
</repositories>

<dependencies>
 <dependency>
  <groupId>com.github.rgzm</groupId>
   <artifactId>bar-lib</artifactId>
   <!-- set version to "master-SNAPSHOT" OR "commitID" OR "releaseNo" -->
   <version>1b53fcf0225dc8e06477a6c4ece485ae64cb0ce8</version>
 </dependency>
</dependencies>

package names

  • src: topLevelDomain.githubUserName.artifactId.{topic}
  • tests: topLevelDomain.githubUserName.artifactId.{topic}

nbactions.xml

in general:

  • Clean and Build -> goals: clean install site
<actions>
  <action>
    <actionName>rebuild</actionName>
    <packagings>
      <packaging>*</packaging>
    </packagings>
    <goals>
      <goal>clean</goal>
      <goal>install</goal>
      <goal>site</goal>
    </goals>
  </action>
</actions>

if project produces JAR:

  • Run -> run main file and write content to a file output
<actions>
  <action>
    <actionName>run</actionName>
    <packagings>
      <packaging>jar</packaging>
    </packagings>
    <goals>
      <goal>process-classes</goal>
      <goal>org.codehaus.mojo:exec-maven-plugin:1.2.1:exec</goal>
    </goals>
    <properties>
      <exec.args>-classpath %classpath topLevelDomain.githubUserName.artifactId.packageName.ClassName</exec.args>
      <exec.executable>java</exec.executable>
    </properties>
  </action>
  <action>
    <actionName>debug</actionName>
    <packagings>
      <packaging>jar</packaging>
    </packagings>
    <goals>
      <goal>process-classes</goal>
      <goal>org.codehaus.mojo:exec-maven-plugin:1.2.1:exec</goal>
    </goals>
    <properties>
      <exec.args>-Xdebug -Xrunjdwp:transport=dt_socket,server=n,address=${jpda.address} -classpath %classpath topLevelDomain.githubUserName.artifactId.packageName.ClassName</exec.args>
      <exec.executable>java</exec.executable>
      <jpda.listen>true</jpda.listen>
    </properties>
  </action>
  <action>
    <actionName>profile</actionName>
    <packagings>
      <packaging>jar</packaging>
    </packagings>
    <goals>
      <goal>process-classes</goal>
      <goal>org.codehaus.mojo:exec-maven-plugin:1.2.1:exec</goal>
    </goals>
    <properties>
      <exec.args>-classpath %classpath topLevelDomain.githubUserName.artifactId.packageName.ClassName</exec.args>
      <exec.executable>java</exec.executable>
    </properties>
  </action>
</actions>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment