Maven: Development and Release versions for Libraries - java

I have a project consisting of 3 libraries - let's call them 1) BABY, 2) CHILD and 3) ADULT. Lib "CHILD" depends on "BABY" and "ADULT" depends on "CHILD".
What I want to do is produce:
a dev version that has all the (transitive) dependencies
a production version that creates a standalone JAR for each library (embedding the dependencies)
I have a profile dev and a profile release already, and I know how to use ProGuard to generate the JAR.
The question is how to tell Maven to keep all dependencies in dev and ignore them (optional/provided) in production?

To have different dependencies when you develop to deployment you could use maven profiles.
http://maven.apache.org/guides/introduction/introduction-to-profiles.html
So when developing you would use something like mvn -Pdev compile
When you say "standalone jar" it sounds like you mean a jar with all dependencies merged into it.
How can I create an executable JAR with dependencies using Maven?
or http://maven.apache.org/plugins/maven-assembly-plugin/

Here is what I used eventually:
The parent POM defines a profile release that configurates the proguard plugin (crates one big JAR) and the install plugin (places the release artifact in the repo).
The lib-baby POM simply calls the 2 plugins in the <build> section.
The lib-child POM additionally specifies a dev profile where the dependency to lib-baby is defined. Within the release profile this dependency has an optional tag and is included in the big JAR.
In the end when run by default, the libs com.company.dev:lib-baby and com.company.dev:lib-child are created (included their dependencies).
When run with -Prelease the libs com.company:lib-baby and com.company:lib-child are created (standalone libs [WITHOUT any dependencies]) - only side effect is that the default artifacts (.*dev) are overwritten :(
parent:
<project>
<groupId>com.company</groupId>
<artifactId>lib-parent</artifactId>
<packaging>pom</packaging>
<modules>
<module>lib-baby</module>
<module>lib-child</module>
<module>lib-adult</module>
</modules>
<profiles>
<profile>
<id>release</id>
<activation>
<property>
<name>release</name>
</property>
</activation>
<build>
<pluginManagement>
<plugins>
<!-- aggregate to one big jar -->
<plugin>
<groupId>com.pyx4me</groupId>
<artifactId>proguard-maven-plugin</artifactId>
<executions>
...
</executions>
<configuration>
<injar>${project.build.finalName}.jar</injar>
<outjar>${project.build.finalName}-release.jar</outjar>
....
</configuration>
</plugin>
<!-- install release version of artifact separately (under com.company) -->
<plugin>
<inherited>true</inherited>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<executions>
<execution>
<id>install-release</id>
<goals>
<goal>install-file</goal>
</goals>
<configuration>
<file>
target/${project.build.finalName}-release.jar
</file>
<groupId>com.company</groupId>
...
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
</build>
</profile>
</profiles>
</project>
lib-baby:
<project>
<groupId>com.company.dev</groupId>
<artifactId>lib-baby</artifactId>
<packaging>jar</packaging>
<parent>
<groupId>com.company</groupId>
<artifactId>lib-parent</artifactId>
</parent>
<profiles>
<profile>
<id>release</id>
<build>
<plugins>
<!-- produces 'lib-baby-release.jar -->
<plugin>
<groupId>com.pyx4me</groupId>
<artifactId>proguard-maven-plugin</artifactId>
</plugin>
<!-- installs 'lib-baby-release.jar -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<executions>
<execution>
<id>install-release</id>
<phase>install</phase>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
lib-child:
<project>
<groupId>com.company.dev</groupId>
<artifactId>lib-child</artifactId>
<packaging>jar</packaging>
<parent>
<groupId>com.company</groupId>
<artifactId>lib-parent</artifactId>
</parent>
<profiles>
<profile>
<id>dev</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<dependencies>
<dependency>
<groupId>com.company.dev</groupId>
<artifactId>lib-baby</artifactId>
</dependency>
</dependencies>
</profile>
<profile>
<id>release</id>
<dependencies>
<dependency>
<groupId>com.company.dev</groupId>
<artifactId>lib-baby</artifactId>
<version>1.0</version>
<!-- made optional because will be embedded in standalone jar -->
<optional>true</optional>
</dependency>
</dependencies>
<build>
<plugins>
<!-- produces 'lib-child-release.jar -->
<plugin>
<groupId>com.pyx4me</groupId>
<artifactId>proguard-maven-plugin</artifactId>
<configuration>
<assembly>
<inclusions>
<inclusion>
<groupId>com.company.dev</groupId>
<artifactId>lib-baby</artifactId>
</inclusion>
</inclusions>
</assembly>
</configuration>
</plugin>
<!-- installs 'lib-child-release.jar -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<executions>
<execution>
<id>install-release</id>
<phase>install</phase>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>

Related

Do you always need to run separately the pom.xml of each projects in Maven before deploying to Tomcat?

I have a main application called MainApp. This app contains a dashboard project and store project. Whenever I make change to either dashboard or store project, I had to run the maven clean install via IntelliJ for the project where I make the change. Then I go to my maven configuration for the MainApp pom.xml then run the pom.xml via clean install tomcat7:run -Pfront-end-build -U to deploy the project.
Is this the right way of doing it? I know this is a bit subjective,but I was thinking won't it be possible to just compile, build and run everything from MainApp? I noticed when I run the pom.xml in MainApp, it just gets the dependency wars ( store and dashboard ) from our Nexus repo (so I guess that war don't contain my latest changes).
MainApp
pom.xml
-----dashboard
-------pom.xml
-----store
-------pom.xml
MainApp pom.xml
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.3.RELEASE</version>
<relativePath/>
</parent>
<groupId>com.pab</groupId>
<artifactId>MainApp</artifactId>
<version>0.0.2-SNAPSHOT</version>
<packaging>pom</packaging>
<modules>
<module>store</module>
<module>dashboard</module>
</modules>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
dependency....
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<webapps>
<webapp>
<contextPath>/store</contextPath>
<groupId>com.pab</groupId>
<artifactId>store</artifactId>
<version>${project.version}</version>
<type>war</type>
<asWebapp>true</asWebapp>
</webapp>
<webapp>
<contextPath>/</contextPath>
<groupId>com.pab</groupId>
<artifactId>dashboard</artifactId>
<version>${project.version}</version>
<type>war</type>
<asWebapp>true</asWebapp>
</webapp>
</webapps>
</configuration>
</plugin>
</plugins>
</build>
<distributionManagement>
<repository>
<id>releases</id>
<name>Releases</name>
<uniqueVersion>true</uniqueVersion>
<url>${release.repo.url}</url>
<layout>default</layout>
</repository>
<snapshotRepository>
<id>snapshots</id>
<name>Snapshots</name>
<uniqueVersion>false</uniqueVersion>
<url>${snapshot.repo.url}</url>
<layout>default</layout>
</snapshotRepository>
</distributionManagement>
dashboard pom.xml
<modelVersion>4.0.0</modelVersion>
<artifactId>dashboard</artifactId>
<packaging>war</packaging>
<name>dashboard</name>
<parent>
<groupId>com.pab</groupId>
<artifactId>MainApp</artifactId>
<version>0.0.2-SNAPSHOT</version>
<relativePath>../</relativePath>
</parent>
<properties>
<webpack.cmd>webpack</webpack.cmd>
</properties>
<profiles>
<profile>
<id>front-end-build</id>
<build>
<plugins>
<plugin>
<artifactId>exec-maven-plugin</artifactId>
<groupId>org.codehaus.mojo</groupId>
</plugin>
</plugins>
</build>
</profile>
</profiles>
<build>
<finalName>dashboard</finalName>
<plugins>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<warFile>${project.build.directory}/${project.build.finalName}.war</warFile>
</configuration>
</plugin>
</plugins>
<pluginManagement>
<plugins>
</plugins>
</pluginManagement>
</build>
</project>
store pom.xml
<modelVersion>4.0.0</modelVersion>
<artifactId>store</artifactId>
<packaging>war</packaging>
<name>store</name>
<parent>
<groupId>com.pab</groupId>
<artifactId>MainApp</artifactId>
<version>0.0.2-SNAPSHOT</version>
<relativePath>../</relativePath>
</parent>
<profiles>
<profile>
<id>front-end-build</id>
<build>
<plugins>
<plugin>
<artifactId>exec-maven-plugin</artifactId>
<groupId>org.codehaus.mojo</groupId>
</plugin>
</plugins>
</build>
</profile>
</profiles>
<build>
<finalName>store</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<systemProperties>
<org.apache.jasper.compiler.Parser.STRICT_QUOTE_ESCAPING>false
</org.apache.jasper.compiler.Parser.STRICT_QUOTE_ESCAPING>
</systemProperties>
<warFile>${project.build.directory}/${project.build.finalName}.war</warFile>
</configuration>
</plugin>
</plugins>
<pluginManagement>
<plugins>
<plugin>
<artifactId>exec-maven-plugin</artifactId>
<groupId>org.codehaus.mojo</groupId>
<version>1.4.0</version>
<configuration>
<workingDirectory>src/main/client</workingDirectory>
</configuration>
<executions>
<execution>
<id>npm</id>
<phase>generate-resources</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>npm</executable>
<arguments>
<argument>install</argument>
</arguments>
</configuration>
</execution>
<execution>
<id>webpack</id>
<phase>generate-resources</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>npm</executable>
<arguments>
<argument>run</argument>
<argument>build</argument>
</arguments>
<environmentVariables>
<NODE_ENV>
production
</NODE_ENV>
</environmentVariables>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
Now, after struggling with this for quite some time. I did some more testing.
I run mvn clean install -Pfront-end-build -U via git bash in the MainApp folder, essentially this executed the pom.xml in that folder which is the parent pom.xml of the inner modules. It successfully built the inner modules store and dashboard. However what I noticed is, when i execute this command in IntelliJ: clean install -Pfront-end-build -U tomcat7:run . The inner modules are not being built. It seemed that the tomcat plugin is trying to deploy the modules immediately thus it is trying to get the war files from the repository. This is where the problem lies now. For now, what I'm doing is i build the whole project (together with the inner modules) outside intelli J then go back to intelli J and run the tomcat maven plugin (tomcat7:run) so I'll have the option to debug through the code using intelli J.
Your main pom xml has store and dashboard defined as modules so if you mvn clean install at main pom xml it should build both the projects and your changes should be reflected in new war.
<modules>
<module>store</module>
<module>dashboard</module>
</modules>
If you are running tomcat in ide like eclipse then once you build your project then it should show synchronized or needs synchronized besides tomcat server. If later then right click on tomcat server and restart tomcat server and it should synchronize i.e. redeploy wars on tomcat server.

Is it possible to exclude (or include) classes or resources on a per profile basis in Maven?

I have two maven profiles P1 and P2 and what I want to do is that depending on the profile I use to build my project, certain resources should be excluded.
For example
<profiles>
<profile>
<id>P1</id>
<properties>
<app.home>Path to project home</app.home>
<exclude>src/main/java/foo/*.*</exclude> <!-- need to exclude all files in src/main/java/foo in this profile -->
</properties>
</profile>
<profile>
<id>P2</id>
<properties>
<app.home>Path to project home</app.home>
<exclude>src/main/java/bar/*.*</exclude> <!-- need to exclude all files in src/main/java/bar in this profile-->
</properties>
</profile>
</profiles>
So, here what I want to do is to exclude all files in src/main/java/foo/ when I build using the P1 profile and exclude all files in src/main/java/bar when I build using the P2 profile.
Is this possible and if not is there any alternative?
You can add a build with the Maven Compiler Plugin to your profile and add a exclude in there
E.g.
<profile>
<id>P1</id>
<properties>
<app.home>Path to project home</app.home>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<excludes>
<exclude>**src/main/java/foo/*.*</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
</profile>
See for additional information Maven: excluding java files in compilation
If you are using spring boot maven plugin, use should do it like this:
<profiles>
<profile>
<id>sample-profile</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<excludes>
<exclude>com/example/foo/ToSkip.java</exclude>
</excludes>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</profile>
</profiles>
This would do below. For more details, see: https://maven.apache.org/plugins/maven-resources-plugin/examples/include-exclude.html
<project>
...
<name>My Resources Plugin Practice Project</name>
...
<build>
...
<resources>
<resource>
<directory>src/my-resources</directory>
<excludes>
<exclude>**/*.bmp</exclude>
<exclude>**/*.jpg</exclude>
<exclude>**/*.jpeg</exclude>
<exclude>**/*.gif</exclude>
</excludes>
</resource>
...
</resources>
...
</build>
...
</project>

Failed to execute goal org.codehaus.cargo:cargo-maven2-plugin:1.4.4:redeploy (deploy) on project duke tutoring

Failed to execute goal org.codehaus.cargo:cargo-maven2-plugin:1.4.4:redeploy (deploy) on project dukes-tutoring-war: Execution deploy of goal org.codehaus.cargo:cargo-maven2-plugin:1.4.4:redeploy failed: Failed to create deployer with implementation class org.codehaus.cargo.container.glassfish.GlassFish4xInstalledLocalDeployer for the parameters (container [id = [glassfish4x]], deployer type [installed]). InvocationTargetException: The container configuration directory "/home/yogesh/Downloads/glassfish4/glassfish4/glassfish/domains" does not exist. Please configure the container before attempting to perform any local deployment. Read more on: http://cargo.codehaus.org/Local+Configuration -> [Help 1]
To see the full stack trace of the errors, re-run Maven with the -e switch.
Re-run Maven using the -X switch to enable full debug logging.
For more information about the errors and possible solutions, please read the following articles:
[Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginExecutionException
After correcting the problems, you can resume the build with the command
mvn <goals> -rf :dukes-tutoring-war
my pom.xml fromdukes-tutoring-war ---------
<?xml version="1.0" encoding="UTF-8"?>
<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>
<parent>
<artifactId>dukes-tutoring</artifactId>
<groupId>org.glassfish.javaeetutorial</groupId>
<version>7.0.5</version>
</parent>
<groupId>org.glassfish.javaeetutorial</groupId>
<artifactId>dukes-tutoring-war</artifactId>
<packaging>war</packaging>
<name>dukes-tutoring-war</name>
<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>dukes-tutoring-common</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>${maven.exec.plugin.version}</version>
<executions>
<execution>
<id>create-tutoring-realm</id>
<phase>compile</phase>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
<configuration>
<skip>false</skip>
<executable>/home/yogesh/Downloads/glassfish4/glassfish/bin/asadmin${glassfish.executables.suffix}</executable>
<arguments>
<argument>create-auth-realm</argument>
<argument>--classname</argument>
<argument>com.sun.enterprise.security.auth.realm.jdbc.JDBCRealm</argument>
<argument>--property</argument>
<argument>jaas-context=jdbcRealm:datasource-jndi='java:global/TutoringDataSource':user-table=tutoring.PERSON:user-name-column=email:password-column=password:group-table=tutoring.PERSON:group-name-column=DTYPE:digest-algorithm=none</argument>
<argument>tutoringRealm</argument>
</arguments>
<successCodes>
<successCode>0</successCode>
<successCode>1</successCode>
</successCodes>
</configuration>
</plugin>
</plugins>
</build>
</project>
The pom in examples folder for <glassfish.home.prefix> settings
<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>
<groupId>org.glassfish.javaeetutorial</groupId>
<artifactId>javaeetutorial</artifactId>
<version>7.0.5</version>
<packaging>pom</packaging>
<name>javaeetutorial</name>
<scm>
<connection>scm:svn:https://svn.java.net/svn/javaeetutorial~svn/tags/javaeetutorial-7.0.0</connection>
<developerConnection>scm:svn:https://svn.java.net/svn/javaeetutorial~svn/tags/javaeetutorial-7.0.0</developerConnection>
</scm>
<issueManagement>
<system>IssueTracker</system>
<url>http://java.net/jira/browse/JAVAEETUTORIAL</url>
</issueManagement>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<javaee.api.version>7.0</javaee.api.version>
<maven.compiler.plugin.version>3.1</maven.compiler.plugin.version>
<maven.source.plugin.version>2.2.1</maven.source.plugin.version>
<maven.clean.plugin.version>2.5</maven.clean.plugin.version>
<maven.war.plugin.version>2.3</maven.war.plugin.version>
<maven.acr.plugin.version>1.0</maven.acr.plugin.version>
<maven.ear.plugin.version>2.8</maven.ear.plugin.version>
<maven.ejb.plugin.version>2.3</maven.ejb.plugin.version>
<maven.jar.plugin.version>2.4</maven.jar.plugin.version>
<maven.rar.plugin.version>2.3</maven.rar.plugin.version>
<maven.license.plugin.version>1.10.b1</maven.license.plugin.version>
<maven.release.plugin.version>2.4.1</maven.release.plugin.version>
<maven.exec.plugin.version>1.2.1</maven.exec.plugin.version>
<junit.version>4.11</junit.version>
<eclipselink.version>2.5.0</eclipselink.version>
<glassfish.embedded.version>4.0</glassfish.embedded.version>
<cargo.plugin.version>1.4.4</cargo.plugin.version>
<glassfish.domain.name>domain1</glassfish.domain.name>
<glassfish.home>${glassfish.home.prefix}/glassfish4</glassfish.home>
<integration.container.id>glassfish4x</integration.container.id>
</properties>
<profiles>
<profile>
<id>windows</id>
<activation>
<os>
<family>windows</family>
</os>
</activation>
<properties>
<glassfish.home.prefix>c:/</glassfish.home.prefix>
<glassfish.executables.suffix>.bat</glassfish.executables.suffix>
</properties>
</profile>
<profile>
<id>unix</id>
<activation>
<os>
<family>unix</family>
</os>
</activation>
<properties>
<glassfish.home.prefix>/home/yogesh/Downloads/glassfish4</glassfish.home.prefix>
<glassfish.executables.suffix />
</properties>
</profile>
<profile>
<id>sdk</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<glassfish.home>${basedir}/../../../</glassfish.home>
</properties>
</profile>
<profile>
<id>development</id>
<activation>
<file>
<exists>${basedir}/../bundle</exists>
</file>
</activation>
<properties>
<glassfish.home>${glassfish.home.prefix}/glassfish4</glassfish.home>
</properties>
</profile>
<profile>
<id>standalone</id>
<properties>
<glassfish.home>${basedir}/target/cargo/installs/glassfish</glassfish.home>
<cargo.maven.containerUrl>http://dlc.sun.com.edgesuite.net/glassfish/4.0/promoted/latest-glassfish.zip</cargo.maven.containerUrl>
</properties>
</profile>
</profiles>
<modules>
<module>archetypes</module>
<module>batch</module>
<module>case-studies</module>
<module>cdi</module>
<module>concurrency</module>
<module>connectors</module>
<module>ejb</module>
<module>jaxrs</module>
<module>jaxws</module>
<module>jms</module>
<module>persistence</module>
<module>security</module>
<module>web</module>
</modules>
<repositories>
<repository>
<id>snapshot-repository.java.net</id>
<name>Java.net Snapshot Repository for Maven</name>
<url>https://maven.java.net/content/repositories/staging/</url>
<layout>default</layout>
</repository>
<repository>
<id>releases-repository.java.net</id>
<name>Java.net releases Repository for Maven</name>
<url>https://maven.java.net/content/repositories/releases/</url>
<layout>default</layout>
</repository>
</repositories>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven.compiler.plugin.version}</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>${maven.source.plugin.version}</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-clean-plugin</artifactId>
<version>${maven.clean.plugin.version}</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>${maven.war.plugin.version}</version>
</plugin>
<plugin>
<groupId>org.codehaus.cargo</groupId>
<artifactId>cargo-maven2-plugin</artifactId>
<version>${cargo.plugin.version}</version>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.codehaus.cargo</groupId>
<artifactId>cargo-maven2-plugin</artifactId>
<inherited>true</inherited>
<executions>
<execution>
<id>deploy</id>
<phase>integration-test</phase>
<goals>
<goal>redeploy</goal>
</goals>
</execution>
</executions>
<configuration>
<container>
<containerId>${integration.container.id}</containerId>
<type>installed</type>
<home>${glassfish.home}</home>
</container>
<configuration>
<type>existing</type>
<home>${glassfish.home}/glassfish/domains</home>
<properties>
<cargo.glassfish.domain.name>${glassfish.domain.name}</cargo.glassfish.domain.name>
<!--cargo.remote.username></cargo.remote.username-->
<cargo.remote.password />
</properties>
</configuration>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven.compiler.plugin.version}</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<groupId>com.mycila.maven-license-plugin</groupId>
<artifactId>maven-license-plugin</artifactId>
<version>${maven.license.plugin.version}</version>
<configuration>
<header>common/license.txt</header>
<excludes>
<exclude>common/**</exclude>
<exclude>**/META-INF/**</exclude>
<exclude>**/WEB-INF/**</exclude>
<exclude>**/nbactions.xml</exclude>
<exclude>**/nb-configuration.xml</exclude>
<exclude>**/glassfish-resources.xml</exclude>
<exclude>**/simple-flow-flow.xml</exclude>
</excludes>
</configuration>
</plugin>
<plugin>
<artifactId>maven-release-plugin</artifactId>
<version>${maven.release.plugin.version}</version>
<configuration>
<!--
During release:perform, enable the "sdk" profile
-->
<releaseProfiles>sdk</releaseProfiles>
<autoVersionSubmodules>true</autoVersionSubmodules>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>${javaee.api.version}</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>
my glassfish4 location: /home/yogesh/Downloads/glassfish4
apache maven location: /opt/apache-maven-3.3.9
I had a similar issue when I tried to build the hello1 project, and this was mainly due to the fact that I installed Netbeans with glassfish: I suppose you did the same thing.
I'm not too sure, but it appears installing Netbeans with glassfish causes some path problems when attempting to build projects.
This is what I did to resolve it on my openSUSE Leap computer:
Stop the glassfish server if it's running and close your Netbeans IDE
Open a terminal and uninstall glassfish
cd /path/to/glassfish/installation/directory (e.g: cd ~/glassfish-4.1.1)
./uninstall.sh
Download Java EE 7 SDK Update 2 (or the latest update) from http://www.oracle.com/technetwork/java/javaee/downloads/index.html
Unzip the downloaded file (this creates the glassfish4 directory)
cd /path/to/downloaded/file/directory
unzip java_ee_sdk-7u2.zip
At this stage, the glassfish server is already installed, but it's not yet integrated in the Netbeans IDE (You will find out that it is not listed as a server in the Netbeans IDE). Instructions on how to add glassfish server as a server in Netbeans IDE can be found here: https://docs.oracle.com/cd/E19798-01/821-1770/gioew/
You can now open Netbeans IDE and try to build your project again; you should have BUILD SUCCESS as I did.
I really hope this helps.
This might also relate to the version of you glassfish server, I solved the same problem by switching to glassfish4.1.
this line in the exception message:
(container [id = [glassfish4x]], deployer type [installed])
is probably searching for the glassfish4 version,
I had this issue with guessnumber-jsf example, but it was fixed by starting my glassfish server.

Conditionally adding build extension [duplicate]

My question had been addressed in this thread, but the explanation is not clear.
I have this build definition in one of my pom.xml files:
<build>
<finalName>${my.project}</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.0</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
<extensions>
<extension>
<groupId>org.kuali.maven.wagons</groupId>
<artifactId>maven-s3-wagon</artifactId>
<version>1.1.19</version>
</extension>
</extensions>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
<includes>
<include>**/settings.properties</include>
</includes>
</resource>
</resources>
</build>
Notice that I'm using the maven-s3-wagon extension.
Next, I would like to have 2 different profiles, each with it's own settings, plugins and extensions but maven does not allow the extensions tag under a profile.
When I try using a profile:
<profiles>
<profile>
<id>local-build</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<build>
<finalName>${my.project}</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.0</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
<extensions>
<extension>
<groupId>org.kuali.maven.wagons</groupId>
<artifactId>maven-s3-wagon</artifactId>
<version>1.1.19</version>
</extension>
</extensions>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
<includes>
<include>**/settings.properties</include>
</includes>
</resource>
</resources>
</build>
</profile>
</profiles>
I get a an error in my pom:
cvc-complex-type.2.4.a: Invalid content was found starting with element 'extensions'. One of '{"http://maven.apache.org/POM/4.0.0":defaultGoal, "http://maven.apache.org/POM/
4.0.0":resources, "http://maven.apache.org/POM/4.0.0":testResources, "http://maven.apache.org/POM/4.0.0":directory, "http://maven.apache.org/POM/4.0.0":filters, "http://
maven.apache.org/POM/4.0.0":pluginManagement}' is expected.
Question So using the extension tag means I can't use profiles? How can I use or change build extensions via profile?
Indeed, the official Maven POM reference is not clear about the possible usage of extensions as part of a Maven profile, since it states you can have a build element within it, but not what of the build section.
However, the official Maven model effectively filters and provides what of the build section you can actually use within a profile section. And indeed extensions is not there.
However, what are Maven extensions? Build/Lifecycle enhancement, but also (and essentially): a library added to the runtime classpath of the Maven build, which participates to the build, but it is not packaged with the final artifact.
Hence, in such a scenario (if you need to have extensions in profile or have a profile to change/add an extension) you could use the following trick:
Have an harmless extension as default extension of your build (where harmless means whatever library which could be part of your build classpath and essentially not affect it at all)
Have properties defining the GAV coordinates (GroupId, ArtifactId, Version) of this extension
Have a profile which overrides these properties with the desired (useful) extension
As an example, given the following sample POM:
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>com.sample</groupId>
<artifactId>project</artifactId>
<version>0.0.1-SNAPSHOT</version>
<properties>
<extension.groupId>junit</extension.groupId>
<extension.artifactId>junit</extension.artifactId>
<extension.version>4.11</extension.version>
</properties>
<build>
<extensions>
<extension>
<groupId>${extension.groupId}</groupId>
<artifactId>${extension.artifactId}</artifactId>
<version>${extension.version}</version>
</extension>
</extensions>
</build>
<profiles>
<profile>
<id>customize-extension</id>
<properties>
<extension.groupId>junit</extension.groupId>
<extension.artifactId>junit</extension.artifactId>
<extension.version>4.12</extension.version>
</properties>
</profile>
</profiles>
</project>
The default build (without the customize-extension profile activated), would use the default defined properties and as such add junit as build extension: this is harmless (although it may create conflicts with another junit version of your build, so make sure you use the same version of use an even more harmless library for that).
You can check Maven will pick it up by running a really first build phase, just to check information in our case, and enable the debug flag:
mvn initialize -X
And checking as part of the build log:
[DEBUG] Populating class realm extension>junit:junit:4.11
[DEBUG] Included: junit:junit:jar:4.11
Now let's use our trick: let's add (change) a build extension via profile:
mvn initialize -X -Pcustomize-extension
And as part of our build log we would have:
[DEBUG] Populating class realm extension>junit:junit:4.12
[DEBUG] Included: junit:junit:jar:4.12
Bingo. Maven picked up a different extension (in this case, a different version, the 4.12) and we succeeded on changing (or actually adding a meaningful) build extension via profile.
Just a crazy idea: use modules
Define a parent pom like this:
<groupId>org.example</groupId>
<artifactId>my-parent</artifactId>
<version>1.0</version>
<packaging>pom</packaging>
<profiles>
<profile>
<id>use-pom1</id>
<modules>
<module>pom1</module>
</modules>
</profile>
<profile>
<id>use-pom2</id>
<modules>
<module>pom2</module>
</modules>
</profile>
</profiles>
Define the desired extensions on pom1 and pom2.
I think the solution is here http://maven.apache.org/guides/mini/guide-using-extensions.html
Define a build section where extensions are defined and then into the profile set the attribute true ( like in the second profile shown below )
<build>
<extensions>
<extension>
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-ssh</artifactId>
<version>2.9</version>
</extension>
</extensions>
</build>
<profiles>
<profile>
<id>create-default</id>
<activation>
<activeByDefault>true</activeByDefault>
<property>
<name>build</name>
<value>full</value>
</property>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>create-core</id>
<activation>
<property>
<name>build</name>
<value>full</value>
</property>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<extensions>true</extensions>
<version>2.6</version>
<configuration>
<finalName>import-station-core-${project.version}</finalName>
</configuration>
<executions>
<execution>
<id>make-jar</id>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>

Maven: add dependecy also with a specific profile

I have 3 projects:
myLibProject: has 2 profiles, "profileOne" and "profileTwo": each profile compile a different jar.
myFirstProject: has the jar compiled by myLibProject with "profileOne" as dependecy
mySecondProject: has the jar compiled by myLibProject with "profileTwo" as dependecy.
It's possible to add myLibProject with a custom profile as depedency?
myLibProject fragment profile: (it's just a sample)
<profiles>
<profile>
<id>profileOne</id>
<build>
<plugins>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<excludes>
<exclude>**/*prop*</exclude>
</excludes>
<finalName>jarFromProfileOne-${project.version}</finalName>
</configuration>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>compimpl</id>
<build>
<plugins>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<excludes>
<exclude>**/*.sql</exclude>
</excludes>
<finalName>jarFromProfileTwo-${project.version}</finalName>
</configuration>
</plugin>
</plugins>
</build>
</profile>
myFirstProject has as depency
<dependency>
<groupId>com.mywebsite</groupId>
<artifactId>myLibProject</artifactId>
<version>1.0.0</version>
<type>pom</type>
<with-profile>profileOne</with-profile>
</dependency>
mySecondProject has as depency
<dependency>
<groupId>com.mywebsite</groupId>
<artifactId>myLibProject</artifactId>
<version>1.0.0</version>
<type>pom</type>
<with-profile>profileTwo</with-profile>
</dependency>
how can I achieve this result? Of course i know "with-profile" does not exists as option.
I need 2 different jars because Documentum's requirment, I know Maven it's created to make a single jar... so I can't use envirnment vars or scope.
Maven 3.0.1

Categories

Resources