Tag Archives: Maven

Maven – Include system scope dependency in maven-assembly-plugin

If you don’t have Maven repository server like Archiva or Nexus, you may need to include those libs which are not public on the internet in your Maven project and specifiy the dependency scope as system in the pom.xml. The following example includes the eureka-0.0.1.jar which is located in the folder called external on project root.

...
<dependency>
  <groupId>ykyuen.info</groupId>
  <artifactId>eureka</artifactId>
  <version>0.0.1</version>
  <scope>system</scope>
  <systemPath>${project.basedir}/external/eureka-0.0.1.jar</systemPath>
</dependency>
...

 

A few months ago i wrote a blog post about how to package the project jar file with all dependencies.
Maven – Package the jar file with dependencies
Continue reading Maven – Include system scope dependency in maven-assembly-plugin

Maven – Run sshexec and scp in maven-antrun-plugin

If you want to use the <sshexec> or <scp> tasks in the maven-antrun-plugin, you may find the following error.

  • [ERROR] Failed to execute goal org.apache.maven.plugins:maven-antrun-plugin:1.3:run (default-cli) on project fraudcheck: An Ant BuildException has occured…

 

Just like what we have discussed in Apache Ant – Using scp and sshexec tasks in build.xml, you need to define the <sshexec> or <scp> tasks in the Ant script. Try to configure your pom.xml as follow.

...
<!-- Deployment using Ant -->
<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-antrun-plugin</artifactId>
  <version>1.7</version>
  <dependencies>
    <!-- Include Ant-Contrib tasks -->
    <dependency>
      <groupId>ant-contrib</groupId>
      <artifactId>ant-contrib</artifactId>
      <version>20020829</version>
    </dependency>
    <!-- Include sshexec task -->
    <dependency>
      <groupId>org.apache.ant</groupId>
      <artifactId>ant-jsch</artifactId>
      <version>1.9.2</version>
    </dependency>
    <dependency>
      <groupId>com.jcraft</groupId>
      <artifactId>jsch</artifactId>
      <version>0.1.50</version>
    </dependency>
  </dependencies>
  <configuration>
    <tasks>
      <!-- Add the sshexec and scp task -->
      <taskdef name="sshexec"
        classname="org.apache.tools.ant.taskdefs.optional.ssh.SSHExec"
        classpathref="maven.plugin.classpath" />
      <taskdef name="scp"
        classname="org.apache.tools.ant.taskdefs.optional.ssh.Scp"
        classpathref="maven.plugin.classpath" />

      <!-- Rest of the Ant script -->
    </tasks>
  </configuration>
  <goals>
    <goal>run</goal>
  </goals>
</plugin>
...

 

Done =)

Reference:

Maven – Add SVN revision number to the name of your built artifact

The svn-revision-number-maven-plugin could help you adding the SVN revision number to your built artifact. Configure your pom.xml as follow.

...
<build>
  <finalName>${project.artifactId}-r${svn.revision}</finalName>
  <plugins>
    <!-- Use the svn revision number for the built artifact -->
    <plugin>
      <groupId>com.google.code.maven-svn-revision-number-plugin</groupId>
      <artifactId>svn-revision-number-maven-plugin</artifactId>
      <version>1.13</version>
      <executions>
        <execution>
          <goals>
            <goal>revision</goal>
          </goals>
        </execution>
      </executions>
      <configuration>
        <entries>
          <entry>
            <prefix>svn</prefix> <!-- create the ${svn.revision} -->
          </entry>
        </entries>
      </configuration>
    </plugin>
  </plugins>
</build>
...

Continue reading Maven – Add SVN revision number to the name of your built artifact

AspectJ – Plugin execution not covered by lifecycle configuration error in Eclipse

When you open your AspectJ project in Eclipse with the m2eclipse, the following error may appear.

  • Plugin execution not covered by lifecycle configuration: org.codehaus.mojo:aspectj-maven-plugin…

 

This is because m2e doesn’t provide lifecycle mapping for aspectj-maven-plugin. A work around is to add the following <pluginManagement> setting in the pom.xml.
Continue reading AspectJ – Plugin execution not covered by lifecycle configuration error in Eclipse

Maven – Run maven-antrun-plugin without attaching to a lifecycle phase

Long time ago, i had a post about running Ant in Maven using the maven-antrun-plugin but the Ant script would be attached to the Maven lifecycle phase.

 

Sometimes you may just want to run a standalone Ant task in Maven without being involved in any lifecycle phase. In that case, you can try configure the maven-antrun-plugin as follow.

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-antrun-plugin</artifactId>
  <version>1.7</version>
  <configuration>
    <tasks>
      <echo message="Hello world"/>
    </tasks>
  </configuration>
  <goals>
    <goal>run</goal>
  </goals>
</plugin>

 

You can run it directly by

  • mvn antrun:run

 

Done =)

Reference: StackOverflow – How to call maven-antrun-plugin target without attach execution to a maven phase ?

Maven – Add Java classpath to manifest for runtime

Previously we have talked about how to package a .jar artifact with dependencies included.

 

An alternative solution is to put your dependencies in the src/main/resources folder and they will be copied to the target folder together with the packaged .jar file. Then we can add the class paths to these dependencies in the Manifest with the help of the maven-jar-plugin.

The following project is a real life example which i use it to test the connection between the JBoss server and the MSSQL server.
Continue reading Maven – Add Java classpath to manifest for runtime

Maven – Package the jar file with dependencies

Sometimes we want to build a executable jar which contains all the dependencies. In this case we could make use of the maven-assembly-plugin which help us to package a jar-with-dependencies artifact during the Maven package phase. Let’s refer to the simple Maven project we did before.

 

1. First let’s introduce a dependency to our project. Say, we want to make use of the Apache Commons – Commons Lang to check the empty string. Edit the src/main/java/info/ykyuen/eureka/Addition.java as follow.
Continue reading Maven – Package the jar file with dependencies

Apache Ivy – Integrate with Artifactory

Like Maven, we could setup a repository server for better dependency management. So instead of connecting to the public repository, we want our Apache Ivy project links to our repository server, i have already setup the Artifactory repository server in my local machine. Let’s continue with the project we created yesterday.

 

1. Add the ivysettings.xml location in the build.xml.
Continue reading Apache Ivy – Integrate with Artifactory