Showing posts with label Maven. Show all posts
Showing posts with label Maven. Show all posts

Wednesday, 17 August 2016

Adding multiple jars to dependency


<dependency>
   <groupId>foo</groupId>
   <artifactId>foo</artifactId>
   <version>1.0</version>
   <scope>system</scope>
   <systemPath>${basedir}/lib/*.jar</systemPath>
  </dependency>


<plugin>
     <groupId>com.googlecode.addjars-maven-plugin</groupId>
     <artifactId>addjars-maven-plugin</artifactId>
     <version>1.0.2</version>
     <executions>
      <execution>
       <goals>
        <goal>add-jars</goal>
       </goals>
       <configuration>
        <resources>
         <resource>
          <directory>${basedir}/../buildtools/lib</directory>
         </resource>
        </resources>
       </configuration>
      </execution>
     </executions>
    </plugin>

Wednesday, 10 August 2016

Listing of the elements directly under the POM's project element

    <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/xsd/maven-4.0.0.xsd">
      <modelVersion>4.0.0</modelVersion>
    
      <!-- The Basics -->
      <groupId>...</groupId>
      <artifactId>...</artifactId>
      <version>...</version>
      <packaging>...</packaging>
      <dependencies>...</dependencies>
      <parent>...</parent>
      <dependencyManagement>...</dependencyManagement>
      <modules>...</modules>
      <properties>...</properties>
    
      <!-- Build Settings -->
      <build>...</build>
      <reporting>...</reporting>
    
      <!-- More Project Information -->
      <name>...</name>
      <description>...</description>
      <url>...</url>
      <inceptionYear>...</inceptionYear>
      <licenses>...</licenses>
      <organization>...</organization>
      <developers>...</developers>
      <contributors>...</contributors>
    
      <!-- Environment Settings -->
      <issueManagement>...</issueManagement>
      <ciManagement>...</ciManagement>
      <mailingLists>...</mailingLists>
      <scm>...</scm>
      <prerequisites>...</prerequisites>
      <repositories>...</repositories>
      <pluginRepositories>...</pluginRepositories>
      <distributionManagement>...</distributionManagement>
      <profiles>...</profiles>
    </project>

Monday, 25 July 2016

maven-eclipse-plugin


<!-- download source code in Eclipse, best practice -->

<plugin>
 <groupId>org.apache.maven.plugins</groupId>
 <artifactId>maven-eclipse-plugin</artifactId>
 <version>2.9</version>
 <configuration>
  <downloadSources>true</downloadSources>
  <downloadJavadocs>false</downloadJavadocs>
 </configuration>
</plugin>

Tuesday, 19 July 2016

The static in-project repository solution

The static in-project repository solution:

<repository>
    <id>repo</id>
    <releases>
        <enabled>true</enabled>
        <checksumPolicy>ignore</checksumPolicy>
    </releases>
    <snapshots>
        <enabled>false</enabled>
    </snapshots>
    <url>file://${project.basedir}/repo</url>
</repository>



Use Maven to install to project repo:

mvn install:install-file -DlocalRepositoryPath=repo -DcreateChecksum=true -Dpackaging=jar -Dfile=[your-jar] -DgroupId=[...] -DartifactId=[...] -Dversion=[...]

<repository>
    <id>repo</id>
    <url>file://${project.basedir}/repo</url>
</repository>


<dependency>
    <groupId>org.swinglabs</groupId>
    <artifactId>swingx</artifactId>
    <version>0.9.2</version>
    <scope>system</scope>
    <systemPath>${project.basedir}/lib/swingx-0.9.3.jar</systemPath>
</dependency>



Registering your repository in pom.xml:

    <repository>
      <id>ProjectRepo</id>
      <name>ProjectRepo</name>
      <url>file://${project.basedir}/libs</url>

    </repository>

Monday, 28 March 2016

JBoss Settings

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/xsd/settings-1.0.0.xsd">
    <localRepository/>
    <profiles>
        <profile>
            <id>jboss-ga</id>
            <repositories>
                <repository>
                    <id>jboss-ga-repository</id>
                    <name>JBoss GA Tech Preview Maven Repository</name>
                    <url>http://maven.repository.redhat.com/techpreview/all</url>
                    <layout>default</layout>
                    <releases>
                        <enabled>true</enabled>
                        <updatePolicy>never</updatePolicy>
                    </releases>
                    <snapshots>
                        <enabled>false</enabled>
                        <updatePolicy>never</updatePolicy>
                    </snapshots>
                </repository>
            </repositories>
            <pluginRepositories>
                <pluginRepository>
                    <id>jboss-ga-plugin-repository</id>
                    <name>JBoss 6 Maven Plugin Repository</name>
                    <url>http://maven.repository.redhat.com/techpreview/all</url>
                    <layout>default</layout>
                    <releases>
                        <enabled>true</enabled>
                        <updatePolicy>never</updatePolicy>
                    </releases>
                    <snapshots>
                        <enabled>false</enabled>
                        <updatePolicy>never</updatePolicy>
                    </snapshots>
                </pluginRepository>
            </pluginRepositories>
        </profile>
    </profiles>
    <activeProfiles>
        <activeProfile>jboss-ga</activeProfile>
    </activeProfiles>
</settings>

Thursday, 4 February 2016

Maven Introduction



There are basically four types of repositories involved
  1. Local Repositories
  2. Global Repositories
  3. Project Repositories
  4. Custom Repositories

A snapshot version in Maven is one that has not been released. The idea is that before a 1.0 release (or any other release) is done, there exists a 1.0-SNAPSHOT . That version is what might become 1.0 . It's basically " 1.0 under development".

Downloading in Maven is triggered by a project declaring a dependency that is not present in the local repository (or for a SNAPSHOT, when the remote repository contains one that is newer). By default, Maven will download from the central repository.

Maven central repository : http://repo.maven.apache.org/maven2/
Maven central repository : http://central.maven.org/maven2
Maven central repository : http://uk.maven.org/maven2/

Maven Plug-In repository : http://repo1.maven.org/maven2/org/codehaus/mojo/


Maven reads both global settings as well as user setting file when you trigger install

C:\Users\vnemalik\Documents\001096043\b2b\code_base\newCodeHub\RB-2016.08.x>mvn clean install -X

Picked up JAVA_TOOL_OPTIONS: -Djava.vendor="Sun Microsystems Inc."
Apache Maven 3.2.5 (12a6b3acb947671f09b81f49094c53f426d8cea1; 2014-12-14T22:59:23+05:30)
Maven home: C:\Users\vnemalik\Documents\001096043\soft\apache-maven-3.2.5\bin\..
Java version: 1.8.0_60, vendor: Sun Microsystems Inc.
Java home: C:\Users\vnemalik\Documents\001096043\soft\jdk1.8.0_45\jre
Default locale: en_US, platform encoding: Cp1252
OS name: "windows 7", version: "6.1", arch: "x86", family: "dos"
[INFO] Error stacktraces are turned on.
[DEBUG] Reading global settings from C:\Users\vnemalik\Documents\001096043\soft\apache-maven-3.2.5\bin\..\conf\settings.xml
[DEBUG] Reading user settings from C:\Users\vnemalik\.m2\settings.xml


Sunday, 31 January 2016

Maven Deploy Plug-in

<plugin>
      <!-- explicitly define maven-deploy-plugin after other to force exec order -->
      <artifactId>maven-deploy-plugin</artifactId>
      <executions>
        <execution>
          <id>deploy</id>
          <phase>deploy</phase>
          <goals><goal>deploy</goal></goals>
        </execution>
      </executions>
    </plugin>
  </plugins>
</build>

Thursday, 27 August 2015

Maven Failsafe plugin

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-failsafe-plugin</artifactId>
    <version>2.17</version>
    <executions>
        <execution>
            <id>integration-test</id>
            <goals>
                <goal>integration-test</goal>
            </goals>
            <configuration>
                <includes>
                    <include>**/it/SIPTResourceTestSuite.java,**/it/SIPTResourceTest.java</include>
                </includes>
            </configuration>
        </execution>
        <execution>
            <id>verify</id>
            <goals>
                <goal>verify</goal>
            </goals>
        </execution>
    </executions>
</plugin>

Maven Surefire plugin

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>2.17</version>
    <configuration>
        <includes>
            <include>**/ut/ProvTestSuite.java, **/ut/*Test.java</include>
                </includes>
    </configuration>
</plugin>

Cargo Maven2 plugin

<plugin>
    <groupId>org.codehaus.cargo</groupId>
    <artifactId>cargo-maven2-plugin</artifactId>
    <version>1.4.10</version>
    <configuration>
        <container>
<containerId>jetty9x</containerId>
<type>remote</type>
        </container>
        <configuration>
<type>runtime</type>
<properties>
<cargo.runtime.args>force=true</cargo.runtime.args>
                <cargo.hostname>localhost</cargo.hostname>
                <cargo.servlet.port>${servlet.port}</cargo.servlet.port>
                <cargo.remote.username>admin</cargo.remote.username>
                <cargo.remote.password>admin</cargo.remote.password>                      
            </properties>
        </configuration>
        <deployables>
            <deployable>
                <groupId>${project.groupId}</groupId>
                <artifactId>${project.artifactId}</artifactId>
                <properties>
                    <context>/sipt-rs</context>
                    </properties>
                        <pingTimeout>300000</pingTimeout>
            </deployable>
        </deployables>
    </configuration>
    <executions>
        <execution>
            <id>redeploy-war-with-cargo</id>
            <phase>pre-integration-test</phase>
            <goals>
                <goal>deployer-redeploy</goal>
            </goals>
        </execution>
    </executions>
</plugin>



The above plug-in look for the cargo-jetty-7-and-onwards-deployer-1.4.11.war in side jetty/web-apps  folder and before that it identifies the jetty running on the specified host and port , later the binding with plug in and jetty happens via cargo war.

Once the binding is over, plug in will deploy the application war into the identified jetty. Later you can run the web/rest test cases from your java module.

Maven war plugin


<plugin>

         <artifactId>maven-war-plugin</artifactId>
          <version>2.5</version>

         <configuration>
                <warName>sipt-rest</warName>
          </configuration>

 </plugin>

Friday, 21 August 2015

Maven jar plugin

<plugin>
<!-- Build an executable JAR -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<configuration>
<archive>
<manifest>
<!-- <addClasspath>true</addClasspath> -->
<!-- <classpathPrefix>lib/</classpathPrefix> -->
<mainClass>com.bt.noas.sipt.exportprofiles.ProfileExporter</mainClass>
</manifest>
</archive>
</configuration>
</plugin>

Monday, 3 August 2015

Maven - archetype:generate

Basic Maven project:

mvn archetype:generate -DgroupId=com.mycompany.app
 -DartifactId=my-app 
 -DarchetypeArtifactId=maven-archetype-quickstart
 -DinteractiveMode=false

Maven Web project:

mvn archetype:generate -DgroupId=com.mycompany.app 
 -DartifactId=RESTfulExample
 -DarchetypeArtifactId=maven-archetype-webapp
 -DinteractiveMode=false

mvn archetype:generate -DgroupId={project-packaging}
 -DartifactId={project-name}
 -DarchetypeArtifactId=maven-archetype-webapp
 -DinteractiveMode=false 

mvn archetype:generate -DgroupId=com.deegeu.dockerapp
 -DartifactId=dockerapp
 -DarchetypeArtifactId=maven-archetype-quickstart
 -DinteractiveMode=false 


Friday, 17 July 2015

Maven - Javadoc plugin

<plugin>
         <inherited>true</inherited>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-javadoc-plugin</artifactId>

          <executions>
             <execution>
                <id>attach-javadocs</id>
                <goals>
                  <goal>jar</goal>
                </goals>
             </execution>
          </executions>
</plugin>

Maven-Source plugin

<plugin>
    <inherited>true</inherited>
       <groupId>org.apache.maven.plugins</groupId>
         <artifactId>maven-source-plugin</artifactId>
           <executions>
             <execution>
              <id>attach-sources</id>
                <goals>
                  <goal>jar</goal>
                </goals>
              </execution>
           </executions>

</plugin>

<plugin>
      <artifactId>maven-source-plugin</artifactId>
      <executions>
        <execution>
          <id>attach-sources</id>
          <phase>deploy</phase>
          <goals><goal>jar-no-fork</goal></goals>
        </execution>
      </executions>
</plugin>
   

Maven - Dependency plugin

<plugin>
    <artifactId>maven-dependency-plugin</artifactId>
        <executions>
            <execution>
                <phase>process-sources</phase>
                   <goals>
                                <goal>copy-dependencies</goal>
                        </goals>
                        <configuration>
                       <outputDirectory>lib</outputDirectory>
                        </configuration>
                 </execution>
             </executions>
</plugin>


<plugin>

<groupId>org.apache.maven.plugins</groupId>

<artifactId>maven-dependency-plugin</artifactId>

<executions>

<execution>

<id>copy-dependencies</id>

<phase>package</phase>

<goals>

<goal>copy-dependencies</goal>

</goals>

<configuration>

<outputDirectory>${project.build.directory}/alternateLocation</outputDirectory>

<overWriteReleases>false</overWriteReleases>

<overWriteSnapshots>false</overWriteSnapshots>

<overWriteIfNewer>true</overWriteIfNewer>

</configuration>

</execution>

</executions>

</plugin>

Maven-execute plugin

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>exec-maven-plugin</artifactId>
    <version>1.1.1</version>
    <executions>
    <execution>
      <phase>test</phase>
      <goals>
      <goal>java</goal>
      </goals>
      <configuration>
      <mainClass>com.bt.noas.sipt.release.ReleaseProfiles</mainClass>
      <arguments>
        <argument></argument>
      </arguments>
      </configuration>
    </execution>
    </executions>
</plugin>

Maven - Dependencies

<dependency>
            <groupId>com.timesten</groupId>
            <artifactId>ttjdbc6</artifactId>
            <version>11.2.x</version>
            <systemPath>${env.TIMESTEN_HOME}/lib/ttjdbc6.jar</systemPath>
            <scope>system</scope>
 </dependency>

Maven-Properties plugin

<plugin>
    <groupId>org.codehaus.mojo</groupId>
      <artifactId>properties-maven-plugin</artifactId>
                <version>1.0-alpha-2</version>
                <executions>
                    <execution>
                        <phase>validate</phase>
                        <goals>
                            <goal>write-project-properties</goal>
                        </goals>
                        <configuration>
                            <outputFile>
                                ${project.build.directory}/test-classes/mvn.properties
                            </outputFile>
                        </configuration>
                    </execution>
             </executions>
</plugin>

Maven-Groovy plugin

<plugin>
     <groupId>org.codehaus.gmaven</groupId>
     <artifactId>gmaven-plugin</artifactId>
           <version>1.5</version>
           <configuration>
                     <providerSelection>1.8</providerSelection>
           </configuration>
            <executions>
                   <execution>
                        <goals>
                            <goal>generateStubs</goal>
                            <goal>compile</goal>
                            <goal>generateTestStubs</goal>
                            <goal>testCompile</goal>
                        </goals>
              </execution>
 </executions>
</plugin>