Search This Blog

Showing posts with label maven. Show all posts
Showing posts with label maven. Show all posts

Maven: conditionally execute plugins using profiles

<project>
<properties>...</properties>
<repositories>...</repositories>
<dependencies>...</dependencies>
<build>
  <plugins>...</plugins>
</build>
<profiles>
  <profile>
    <id>windows</id>
    <activation>
      <os>
        <name>Windows XP</name>
        <family>Windows</family>
        <arch>x86</arch>
        <version>5.1.2600</version>
      </os>
    </activation>
    <properties>...</properties>
    <repositories>...</repositories>
    <dependencies>...</dependencies>
    <build>
      <plugins>...</plugins>
    </build>
  </profile>
</profiles>
</project>
To activate the profile manually:
mvn package -p PROFILE_ID





see also

Pass javac compiler arguments to Maven

Maven: Pass compiler arguments

Check the Jave version maven is using

Simply run mvn -version


mvn -version
Apache Maven 3.6.2 (40f52333136460af0dc0d7232c0dc0bcf0d9e117; 2019-08-28T01:06:16+10:00)
Maven home: /opt/maven
Java version: 13.0.1, vendor: Oracle Corporation, runtime: /Library/Java/JavaVirtualMachines/jdk-13.0.1.jdk/Contents/Home
Default locale: en_AU, platform encoding: UTF-8
OS name: "mac os x", version: "10.15.1", arch: "x86_64", family: "mac"

Wrap Java as Mac App bundle

See https://github.com/federkasten/appbundle-maven-plugin

NOTE:

  • dictionaryFile and iconFile must be in src/main/resources directory, their values in configuration must be only the file names (without path).
  • jrePath must be absolute path.

Maven: skip unit tests

<properties>
    <maven.test.skip>true</maven.test.skip>
</properties>

Configure gwt-maven-plugin to start classic DevMode instead of SuperDevMode in GWT 2.7.0

In the pom.xml, pluginManagement -> plugins:
<pluginManagement>
    
    <plugins>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>gwt-maven-plugin</artifactId>
            <goals>
               <goal>run</goal>
            </goals>
            <configuration>
                <extraJvmArgs>-Xmx1024m</extraJvmArgs>
                <superDevMode>false</superDevMode>
                <noServer>true</noServer>
            </configuration>
        </plugin>
    </plugins>
</pluginManagement>
Note:noServer is set true which will not start the embedded jetty web server.
For more details about the configuration options for gwt:run goal, run the following command:
mvn help:describe -Dplugin=org.codehaus.mojo:gwt-maven-plugin -Dgoal=run -Ddetail

Maven: no POM for for org.eclipse.m2e:lifecycle-mapping:jar:1.0.0 is missing, no dependency information available

Solution:
cd /tmp
mvn archetype:generate -DgroupId=org.eclipse.m2e -DartifactId=lifecycle-mapping -Dversion=1.0.0 -DarchetypeArtifactId=maven-archetype-mojo
cd lifecycle-mapping
mvn clean install
mvn install:install-file -Dfile=target/lifecycle-mapping-1.0.0.jar -DpomFile=pom.xml -DcreateChecksum -DlocalRepositoryPath=/path/to/localMavenRepo

Maven Eclipse set compiler JDK compliance level

The maven project/module created in Eclipse set JAVA 1.5 as the default. You cannot change it via Eclipse project settings (as it will be reverted back to 1.5) when you run Maven -> Update Project. To solve this, you can add the following to the pom.xml:
<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.3</version>
            <configuration>
                <source>1.6</source>
                <target>1.6</target>
            </configuration>
        </plugin>
    </plugins>
</build>
Or, if you have hierarchical project with modules, you can put it into pluginManagement of the parent project's pom.xml:
<build>
    <pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.3</version>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                </configuration>
            </plugin>
        </plugins>
    </pluginManagement>
</build>
All the descendant modules will inherit the compiler settings from the parent.

NOTE:

In Eclipse, if the project packaging is pom the compiler settings will not get updated using the above. You will need to change packaging to jar then Update the Maven projects. You can revert back to pom after the compiler settings has been changed.

Install pixelmed jar files into local maven repository

  • The script to install the pixelmed jar files to local maven repository:
    #!/bin/bash
    
    repo=/path/to/mvn-repo
    dir=/path/to/pixelmed
    
    name=pixelmed-codec
    version=20141206
    mvn install:install-file \
        -Dfile=${dir}/pixelmed_codec.jar \
        -DgroupId=com.pixelmed \
        -DartifactId=pixelmed-codec \
        -Dname=pixelmed_codec.jar \
        -Dversion=${version} \
        -Dpackaging=jar \
        -DperformRelease=true \
        -DcreateChecksum=true \
        -DgeneratePom=true \
        -DlocalRepositoryPath=${repo}
    
    name=pixelmed-aiviewer
    version=20150512
    mvn install:install-file \
        -Dfile=${dir}/aiviewer.jar \
        -DgroupId=com.pixelmed \
        -DartifactId=pixelmed-aiviewer \
        -Dname=aiviewer.jar \
        -Dversion=${version} \
        -Dpackaging=jar \
        -DperformRelease=true \
        -DcreateChecksum=true \
        -DgeneratePom=true \
        -DlocalRepositoryPath=${repo}
    
    name=pixelmed
    version=20150512
    mvn install:install-file \
        -Dfile=${dir}/pixelmed.jar \
        -DgroupId=com.pixelmed \
        -DartifactId=pixelmed \
        -Dname=pixelmed.jar \
        -Dversion=${version} \
        -Dversion=${version} \
        -Dpackaging=jar \
        -DperformRelease=true \
        -DcreateChecksum=true \
        -DpomFile=/path/to/pixelmed.pom.xml \
        -DlocalRepositoryPath=${repo}
    
  • The pom.xml for pixelmed.jar
    <?xml version="1.0" encoding="UTF-8"?>
    <project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
      <modelVersion>4.0.0</modelVersion>
      <groupId>com.pixelmed</groupId>
      <artifactId>pixelmed</artifactId>
      <version>20150512</version>
      <description>PixelMed Java DICOM library.</description>
      <dependencies>
        <dependency>
          <groupId>javax.jmdns</groupId>
          <artifactId>jmdns</artifactId>
          <version>3.4.1</version>
        </dependency>
        <dependency>
          <groupId>org.hsqldb</groupId>
          <artifactId>hsqldb</artifactId>
          <version>2.3.2</version>
        </dependency>
        <dependency>
          <groupId>java3d</groupId>
          <artifactId>vecmath</artifactId>
          <version>1.3.1</version>
        </dependency>
        <dependency>
          <groupId>commons-net</groupId>
          <artifactId>commons-net</artifactId>
          <version>3.3</version>
        </dependency>
        <dependency>
          <groupId>commons-codec</groupId>
          <artifactId>commons-codec</artifactId>
          <version>1.10</version>
        </dependency>
        <dependency>
          <groupId>org.apache.commons</groupId>
          <artifactId>commons-compress</artifactId>
          <version>1.9</version>
        </dependency>
      </dependencies>
    </project>
    

Distribute Mediaflux libraries to maven using Mediaflux web server

  1. Install the libraries as artifacts to your local maven repository. And it will generate and save the artifacts to $HOME/.m2/repository/com/arcitecta directory
  2. Copy the artifacts from the local repsitory to ${MFLUX_HOME}/www/
    mkdir -p $MFLUX_HOME/www/maven-repository/com/arcitecta
    cp -r $HOME/.m2/repository/com/arcitecta/* $MFLUX_HOME/www/maven-repository/com/arcitecta/
  3. In aterm, run the following command to create a http processor (to link the web directory):
    http.processor.create :app maven-repository :type file :authentication < :domain www-public :user www-public > :url maven-repository :translate maven-repository
    if your mediaflux is configured use https on a non-standard port, you need to specify :encryption-required "true" :encryption-port "8443" e.g. 8443 is the https server port.
  4. You can now include the repository in your maven project's pom.xml or $HOME/.m2/settings.xml:
        <repositories>
    <repository>
    <id>mediaflux-libs</id>
    <name>mediaflux-libs</name>
    <url>https://mediaflux.your-domain.org:8443/maven-repository</url>
    <layout>default</layout>
    </repository>
    </repositories>
  5. Also in your maven project's pom.xml, add the mediaflux libraries/artifacts in dependencies:
        <dependencies>
    <dependency>
    <groupId>com.arcitecta</groupId>
    <artifactId>aplugin</artifactId>
    <version>3.9.011</version>
    </dependency>
    </dependencies>


see also

Include Mediaflux libraries into local maven repository


#!/bin/bash
export MFLUX_HOME=/opt/mflux
export MFLUX_VERSION=3.9.011

mvn install:install-file -Dfile=${MFLUX_HOME}/dev/plugin/lib/aplugin.jar -DgroupId=com.arcitecta -DartifactId=aplugin -Dname=aplugin -Dversion=${MFLUX_VERSION} -Dpackaging=jar -DperformRelease=true -DcreateChecksum=true

mvn install:install-file -Dfile=${MFLUX_HOME}/dev/client/java/mfclient.jar -DgroupId=com.arcitecta -DartifactId=mfclient -Dname=mfclient -Dversion=${MFLUX_VERSION} -Dpackaging=jar -DperformRelease=true -DcreateChecksum=true

mvn install:install-file -Dfile=${MFLUX_HOME}/dev/client/gwt/mfclientgwt.jar -DgroupId=com.arcitecta -DartifactId=mfclientgwt -Dname=mfclientgwt -Dversion=${MFLUX_VERSION} -Dpackaging=jar -DperformRelease=true -DcreateChecksum=true

mvn install:install-file -Dfile=${MFLUX_HOME}/dev/client/gwt/mfclientguigwt.jar -DgroupId=com.arcitecta -DartifactId=mfclientguigwt -Dname=mfclientguigwt -Dversion=${MFLUX_VERSION} -Dpackaging=jar -DperformRelease=true -DcreateChecksum=true


see also

maven: include libraries into you local repository

#!/bin/bash
export MFLUX_HOME=/opt/mflux

export MFLUX_VERSION=3.9.011

mvn install:install-file -Dfile=${MFLUX_HOME}/dev/plugin/lib/aplugin.jar -DgroupId=com.arcitecta -DartifactId=aplugin -Dname=aplugin -Dversion=${MFLUX_VERSION} -Dpackaging=jar -DperformRelease=true -DcreateChecksum=true

mvn install:install-file -Dfile=${MFLUX_HOME}/dev/client/java/mfclient.jar -DgroupId=com.arcitecta -DartifactId=mfclient -Dname=mfclient -Dversion=${MFLUX_VERSION} -Dpackaging=jar -DperformRelease=true -DcreateChecksum=true

mvn install:install-file -Dfile=${MFLUX_HOME}/dev/client/gwt/mfclientgwt.jar -DgroupId=com.arcitecta -DartifactId=mfclientgwt -Dname=mfclientgwt -Dversion=${MFLUX_VERSION} -Dpackaging=jar -DperformRelease=true -DcreateChecksum=true

mvn install:install-file -Dfile=${MFLUX_HOME}/dev/client/gwt/mfclientguigwt.jar -DgroupId=com.arcitecta -DartifactId=mfclientguigwt -Dname=mfclientguigwt -Dversion=${MFLUX_VERSION} -Dpackaging=jar -DperformRelease=true -DcreateChecksum=true
After the above step, you can add dependency to your maven project's pom.xml:
    <dependencies>
        <dependency>
            <groupId>com.arcitecta</groupId>
            <artifactId>aplugin</artifactId>
            <version>3.9.011</version>
        </dependency>
    </dependencies>


see also

Configure http proxy for maven

Edit $HOME/.m2/settings.xml file:
vi ~/.m2/settings.xml
<settings>
  <proxies>
   <proxy>
      <active>true</active>
      <protocol>http</protocol>
      <host>proxy.somewhere.com</host>
      <port>8080</port>
      <username>proxyuser</username>
      <password>somepassword</password>
      <nonProxyHosts>www.google.com|*.somewhere.com</nonProxyHosts>
    </proxy>
  </proxies>
</settings>

m2eclipse: use java 1.6 instead of 1.5

m2eclipse uses java 1.5 by default. To make your project use java 1.6. you need to edit your pom.xml file:
<project>

        ... ...

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.1</version>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

then right click your project in eclipse, select Maven -> Update Maven Project.