Aug 1st, 2017
When you run a command such as mvn [phase]
, Maven will execute all phases from validate
to the specified [phase]
-D
option is to send parameter value to the pom, or to override the values in ~/.m2/settings.xml
.
$ mvn exec:exec -DcustomerId=1234 -Doutcome=REJECTED -DserviceUrl=http://localhost:8080/services/soap
$ mvn clean install -DskipTests -Dgpg.skip -Dmaven.javadoc.skip=true
Open pom.xml and go to the Graph tab to see dependency graph.
cd into the project directory (or, in the case of a multi-module project, cd into the parent/aggregator project) and run the following command:
$ mvn archetype:create-from-project
$ mvn clean
This will generate a bulk of files and folders under the target/generated-sources/archetype directory: From the folder structure you can discard the target directory sub-tree, just mvn clean it.
$ cd target/generated-sources/archetype
$ tree -d
.
└── src
├── main
│ └── resources
│ ├── META-INF
│ │ └── maven
│ └── archetype-resources
│ └── src
│ └── main
│ ├── java
│ └── webapp
│ └── WEB-INF
└── test
└── resources
└── projects
└── basic
${rootArtifactId}
to rename variables, methods, comments, etc that depends on the supplied project name.__rootArtifactId__
to rename files/folders.Netbeans will issue the following mvn command behind the scenes
mvn -DartifactId={artifact id} -DgroupId={group id} -Dversion={version} -Dpackaging=jar -Dfile={path to jar} -DgeneratePom=false install:install- file
http://ovaraksin.blogspot.com.tr/2012/02/inject-maven-project-informations-into.html
http://www.baeldung.com/install-local-jar-with-maven/
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
<configuration>
<groupId>net.sf.barcode4j</groupId>
<artifactId>barcode4j-light</artifactId>
<version>2.1</version>
<packaging>jar</packaging>
<file>${basedir}/dependencies/barcode4j-light.jar</file>
<generatePom>true</generatePom>
</configuration>
<executions>
<execution>
<id>install-jar-lib</id>
<goals>
<goal>install-file</goal>
</goals>
<phase>validate</phase>
</execution>
</executions>
</plugin>
</plugins>
</build>
Add gpg plugin in a profile as below and then when you need to do a release, add the property to your mvn command:
mvn -DperformRelease=true ...
<profiles>
<profile>
<id>release-sign-artifacts</id>
<activation>
<property>
<name>performRelease</name>
<value>true</value>
</property>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>1.6</version>
<executions>
<execution>
<id>sign-artifacts</id>
<phase>verify</phase>
<goals>
<goal>sign</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
Maven always uses either one or two settings files. The global settings defined in ${M2_HOME}/conf/settings.xml
is always required. The user settings file defined in ${user.home}/.m2/settings.xml
is optional. Any settings defined in the user settings take precedence over the corresponding global settings.
# settings.xml
<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.1.0 http://maven.apache.org/xsd/settings-1.1.0.xsd">
<servers>
<server>
<id>gpg.passphrase</id>
<passphrase>P@assphrase123</passphrase>
</server>
</servers>
</settings>
# pom.xml
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>1.6</version>
<executions>
<execution>
<id>sign-artifacts</id>
<phase>verify</phase>
<goals>
<goal>sign</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
First if you do not have one, you need to create a key. To generate a key pair
gpg --gen-key
List all available keys
gpg --list-keys
and send key to pool.sks-keyservers.net
server
gpg --keyserver hkp://pool.sks-keyservers.net --send-keys [key]
To check the configuration
mvn clean verify
Possible errors you will get are
Add below line to ~/.bash_profile
or ~/.zshrc
GPG_TTY=$(tty)
export GPG_TTY
and reload your .zshrc
source ~/.zshrc
or
. ~/.zshrc
List all available gpg servers
gpg-connect-agent --dirmngr 'keyserver --hosttable'
and select and use an active server in order to send or receive key
gpg --keyserver hkp://keys.openpgp.org --send-keys [key]
gpg --keyserver hkp://keys.openpgp.org --recv-keys [key]
To deploy your application using Maven, create the settings.xml file under the .m2 folder, providing the glassfish profile credentials: they will automatically imported in the pom.xml file.
in your pom.xml file add
<build>
<plugins>
<plugin>
<groupId>org.glassfish.maven.plugin</groupId>
<artifactId>maven-glassfish-plugin</artifactId>
<version>2.1</version>
<configuration>
<glassfishDirectory>${glassfish.home}</glassfishDirectory>
<user>admin</user>
<!--<adminPassword>${glassfish.adminPassword}</adminPassword>-->
<passwordFile>${glassfish.passfile}</passwordFile>
<domain>
<name>domain1</name>
<httpPort>8080</httpPort>
<adminPort>4848</adminPort>
</domain>
<components>
<component>
<name>${project.artifactId}</name>
<artifact>target/${project.build.finalName}.war</artifact>
</component>
</components>
<debug>true</debug>
<terse>false</terse>
<echo>true</echo>
</configuration>
</plugin>
</plugins>
</build>
and then run
$ mvn clean package glassfish:deploy
in your pom.xml file add
<build>
<plugins>
<plugin>
<groupId>org.wildfly.plugins</groupId>
<artifactId>wildfly-maven-plugin</artifactId>
<version>2.0.0.Final</version>
</plugin>
</plugins>
</build>
and then run
$ mvn clean wildfly:deploy
to backup mysql database for example, add below lines in your pom.xml
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<executions>
<execution>
<id>default-cli</id>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
<configuration>
<executable>/usr/bin/mysqldump</executable>
<workingDirectory>/tmp/${database.schema}</workingDirectory>
<commandlineArgs>${database.schema} --host ${database.host} --user=${database.username} --password=${database.password} --result-file=${env.name}_${database.schema}_backup.sql</commandlineArgs>
</configuration>
</plugin>
</plugins>
</build>
and then run
$ mvn exec:exec -Pproduction
mvn dependency:tree