Packaging using Maven - maven

I have a Java web application deployed using Tomcat. I want to package the Tomcat ROOT into .WAR file using Maven. Can someone guide me through the process?
Thank you

Create a pom.xml file in the ROOT directory with the following code.
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>package</groupId>
<artifactId>artifactid</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>project</name>
<packaging>war</packaging>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<webXml>WEB-INF/web.xml</webXml>
</configuration>
</plugin>
</plugins>
</build>
</project>
Then execute the following command in the command line mvn:clean install.
The war file will be generated to the target directory.

Related

Is it possible to filter a generated Maven EAR plugin application.xml with a file filter?

I'm trying to filter an application.xml file generated by the maven-ear-plugin using file filters. My project structure is the standard for Maven.
Here is my POM file:
<?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>
<groupId>test</groupId>
<artifactId>test-filter</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>ear</packaging>
<properties>
<prop1>xyz</prop1>
</properties>
<build>
<plugins>
<plugin>
<artifactId>maven-ear-plugin</artifactId>
<version>2.10.1</version>
<configuration>
<version>6</version>
<env-entries>
<env-entry>
<env-entry-name>env1</env-entry-name>
<env-entry-type>java.lang.String</env-entry-type>
<env-entry-value>${prop1}</env-entry-value>
</env-entry>
</env-entries>
</configuration>
</plugin>
</plugins>
</build>
</project>
Up to here everything works fine. The plugin generates an application.xml file containing the env1 entry with the interpolated value xyz.
The problem is when I move the Maven property prop1 to a properties file and configure a filter:
<?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>
<groupId>test</groupId>
<artifactId>test-filter</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>ear</packaging>
<build>
<filters>
<filter>src/main/filters/filter.properties</filter>
</filters>
<plugins>
<plugin>
<artifactId>maven-ear-plugin</artifactId>
<version>2.10.1</version>
<configuration>
<version>6</version>
<env-entries>
<env-entry>
<env-entry-name>env1</env-entry-name>
<env-entry-type>java.lang.String</env-entry-type>
<env-entry-value>${prop1}</env-entry-value>
</env-entry>
</env-entries>
</configuration>
</plugin>
</plugins>
</build>
</project>
For my understanding of the filters feature, it is equivalent as the properties but using a separate file. Nonetheless, the generated application.xml contains the entry env1 without interpolating ${prop1}.
Of course the file src/main/filters/filter.properties exists and contains:
prop1=abc
Is there something I am missing?
My guess is that the order in which the plugins run does not work in your favor.
The ear plugin creates the application.xml quite early on: http://maven.apache.org/plugins/maven-ear-plugin/generate-application-xml-mojo.html in process during "generate-resources".
The resources plugin that does the filtering runs in the next phase: http://maven.apache.org/ref/3.3.9/maven-core/default-bindings.html#Plugin_bindings_for_ear_packaging
So the properties are probably not read at the time the application.xml is generated.
An option would be to use the properties plugin: http://www.mojohaus.org/properties-maven-plugin/usage.html and bind it to an early phase to have them available for filtering in the ear plugin.

service bus maven error - unknown packaging sbar

I am new to maven / pom.xml and am following the below link to create an oracle service bus project and package it into custom packaging type "sbar".
https://docs.oracle.com/middleware/1213/core/MAVEN/osb_maven_project.htm#MAVEN8971
The Project gets generated properly (from the command --> mvn archetype:generate ... ) but when I execute the below command I get an error
mvn package -DoracleHome=/path/to/osbhome
[ERROR] Unknown packaging: sbar # line 16, column 16
project pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_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>
<parent>
<groupId>com.oracle.servicebus.plugin</groupId>
<artifactId>oracle-servicebus-plugin</artifactId>
<version>12.1.3-0-0</version>
</parent>
<groupId>my-servicebus-application</groupId>
<artifactId>my-project</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>sbar</packaging> <!--getting error on this line-->
<build>
<plugins>
<plugin>
<groupId>com.oracle.servicebus.plugin</groupId>
<artifactId>oracle-servicebus-plugin</artifactId>
<version>12.1.3-0-0</version>
<executions>
<execution>
<id>package</id>
<phase>package</phase>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
application pom.xml
<project>
...
<modelVersion>4.0.0</modelVersion>
<groupId>my-servicebus-application</groupId>
<artifactId>my-servicebus-application</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<modules>
<module>System</module>
<module>my-project</module>
</modules>
...
</project>
system pom.xml
<project>
...
<modelVersion>4.0.0</modelVersion>
<groupId>org.mycompany</groupId>
<artifactId>System</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>sbar</packaging>
<parent>
<groupId>com.oracle.servicebus</groupId>
<artifactId>sbar-system-common</artifactId>
<version>12.1.3-0-0</version>
<relativePath></relativePath>
</parent>
...
</project>
I am using JDeveloper 12.1.3.0.0 and Maven 3.0.5.
(I get the same error if I run it either from JDeveloper or from command promt)
Please help me solve this error.
Thanks in Advance !
I haven't really sat down to work with any of the Maven POM's for OSB, SOA, etc., but I do know that your maven plugin probably isn't on the default M2 repository. It probably can't find your packaging type of sbar because it's not included in your repository. I'm assuming you're using their supplied maven and maven repo following this guide: https://docs.oracle.com/middleware/1213/core/MAVEN/config_maven.htm#MAVEN8853

Autowiring of Spring Data Repo fails with Maven Skinny war option

My question is similar to this one posted a while ago
The autowiring of Spring Data Repos fail when the external libraries are in EAR's lib folder.
The wiring works fine when all jars are included in WEB-INF/lib.
I tried setting the 'skinnyWar' to false but this is duplicating the jars in both EAR and WAR.
The application uses Spring Batch Admin 1.2.2 and Spring Data 1.1 with Spring 3.2.2 based.
Maven Version used is 3.3. The runtime is Websphere 7.x
I have another application that works perfectly fine with skinnywar set to true - this uses spring-ws, spring-data 4.0.x version.
The WAR POM
<?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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>batchadmin-web</artifactId>
<parent>
<groupId>com.xyz.interfaces</groupId>
<artifactId>batch-parent</artifactId>
<version>1.0.BUILD-SNAPSHOT</version>
<relativePath>../batch-parent/pom.xml</relativePath>
</parent>
<packaging>war</packaging>
<name>Batch Admin Interface Web</name>
<dependencies>
<!-- Application specific jars/modules Not included for brevity-->
</dependencies>
<build>
<finalName>springbatch-admin</finalName>
<outputDirectory>${project.basedir}\src\main\webapp\WEB-INF\classes</outputDirectory>
<testOutputDirectory>${project.basedir}\src\main\webapp\WEB-INF\classes</testOutputDirectory>
<plugins>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.4</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
</manifest>
</archive>
<packagingExcludes>WEB-INF/lib/spring-beans*.jar</packagingExcludes>
</configuration>
</plugin>
</plugins>
</build>
</project>
The EAR POM content:
<?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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>batchadmin-ear</artifactId>
<parent>
<groupId>com.xyz.interfaces</groupId>
<artifactId>batch-parent</artifactId>
<version>1.0.BUILD-SNAPSHOT</version>
<relativePath>../batch-parent/pom.xml</relativePath>
</parent>
<packaging>ear</packaging>
<name>Batch Admin Interface</name>
<dependencies>
<dependency>
<groupId>com.xyz.interfaces</groupId>
<artifactId>batchadmin-web</artifactId>
<type>war</type>
<version>${project.version}</version>
</dependency>
</dependencies>
<build>
<finalName>SpringBatchEAR</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-ear-plugin</artifactId>
<version>2.9.1</version>
<configuration>
<skinnyWars>true</skinnyWars>
<defaultLibBundleDir>lib/</defaultLibBundleDir>
<modules>
<webModule>
<groupId>com.xyz.interfaces</groupId>
<artifactId>batchadmin-web</artifactId>
<contextRoot>/springbatch-admin</contextRoot>
<bundleFileName>springbatch-admin.war</bundleFileName>
</webModule>
</modules>
</configuration>
</plugin>
</plugins>
</build>
Update: Since the EAR has only one Web module, used 'Single class loader for application' for 'WAR class loader policy' in the Websphere. This way, I am able to make this work.
I would like to know how to make this work without changing the classloader option as this might not be preferred when multiple web modules are present.

How to Build Xcode build with Maven plugin

I'm trying to build Xcode app with maven plugin, i worte pom.xml as shown in below
<?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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.yqlabsEnterprise.SampleMaven</groupId>
<artifactId>SampleMaven</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>xcode-lib</packaging>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.4</version>
</plugin>
<plugin>
<groupId>com.sap.prd.mobile.ios.mios</groupId>
<artifactId>xcode-maven-plugin</artifactId>
<version>1.14.0</version>
<extensions>true</extensions>
</plugin>
</plugins>
</build>
</project>
i installed maven, and run with maven using terminal, but my app not build successfully, i got error
"Failed to execute goal com.sap.prd.mobile.ios.mios:xcode-maven-plugin:1.14.0:prepare-xcode-build (default-prepare-xcode-build) on project SampleMaven: Execution default-prepare-xcode-build of goal com.sap.prd.mobile.ios.mios:xcode-maven-plugin:1.14.0:prepare-xcode-build failed: A required class was missing while executing com.sap.prd.mobile.ios.mios:xcode-maven-plugin:1.14.0:prepare-xcode-build: Lorg/sonatype/aether/RepositorySystem"
will you please help me to solve this issue.
You'll need to downgrade to Maven 3.0.x since the plugin is not compatible with later versions of Maven. The reason is that the Java package org.sonatype.aether.* has been renamed to org.eclipse.aether.*.

Create multi-module project in maven

I'd like to create multimodule standalone application with maven.
In my case I'd like to make 'Loader' project (.jar) contains all other projects. But now I have just set of .jar files (loader.jar, crawler1.jar ... etc)
loader's .pom:
<?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>
<groupId>com.javanix.jmetalcrawler</groupId>
<artifactId>loader</artifactId>
<version>1.0</version>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
subproject's .pom:
<?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>
<groupId>com.javanix.jmetalcrawler</groupId>
<artifactId>Crawler-1</artifactId>
<version>1.0</version>
<dependencies>
<dependency>
<groupId>com.javanix.jmetalcrawler</groupId>
<artifactId>loader</artifactId>
<version>1.0</version>
</dependency>
</dependencies>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
parent's .pom:
<?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>
<groupId>com.javanix.jmetalcrawler</groupId>
<artifactId>parent</artifactId>
<version>1.0</version>
<packaging>pom</packaging>
<name>jMetalCrawler</name>
<modules>
<module>Crawler-1</module>
<module>Loader</module>
</modules>
</project>
Lifecycle:
compile 'Loader' (has interfaces/abstract classes)
compile/package 'crawler1' (as it depends on 'Loader' project)
compile/package 'crawler2' (as it depends on 'Loader' project)
package loader with compiled 'crawler' projects
P.S.:
Thanks to Adrian Shum , he gave an idea to make my project clearer
After restructure my project in 'Launcher' project we can add
dependencies via maven-assembly-plugin (#see http://rombertw.wordpress.com/2010/05/14/maven-recipe-building-an-aggregate-jar/)
I'd suggest project structure like this:
loader (POM, multi-module)
+ loader-api (JAR)
+ crawler1 (JAR, depends on loader-api)
+ crawler2 (JAR, depends on loader-api)
+ loader-app (JAR, depends on loader-api, crawler1, crawler2.
The standalone app is built here)
By splitting the API that crawlers depends and the app itself, the whole project structure is much easier to manage. And, it is more modularized too, as we are no longer mixing the API with the app
If you by "multimodule standalone application with maven" mean a self-contained, executable jar that contains all its dependencies then onejar-maven-plugin may be what you are looking for. See the documentation for usage examples.

Resources