How to add build ear file containing only dependency jars in pom - java

I would like to create an ear containing only dependency jar files using maven.
<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">
<dependencies>
<dependency>
<groupId>groupId</groupId>
<artifactId>artifactId</artifactId>
</dependency>
......
......
......
</dependencies>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-ear-plugin</artifactId>
<configuration>
<modules>
<jarModule>
<groupId>groupId</groupId>
<artifactId>artifcatId</artifactId>
<includeInApplicationXml>true</includeInApplicationXml>
</jarModule>
</modules>
...............
...............
</configuration>
</plugin>
</plugins>
</project>
Maven created application.xml automatically which has entries for these jars but still, when deploying, I am getting message in console - "No modules found in ear."
Could you help me out what am I missing here.

An EAR file should contain WARs, RARs, SARs, and EJB JARs. Anything else, including basic library JARs, are unimportant as far as the EAR is concerned and and EAR with just those kind of files is useless as far as a Java EE Application Server is concerned.

Related

Is it possible to have Maven "WAR" pom.xml package up my classes up in a JAR and put the JAR in the /WEB-INF/lib folder?

I have a simple Java Spring MVC web app. I build the WAR file using a Maven pom.xml file.
When I do a "maven install", it produces a WAR file with my compiled Java classes in the /WEB-INFO/classes folder.
My maven pom.xml looks like this (dependencies commented out) ...
<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>mycompany.com</groupId>
<artifactId>myapp</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>My Application</name>
<url>http://maven.apache.org</url>
<dependencies>
<!-- .... -->
</dependencies>
<build>
<finalName>myapp</finalName>
</build>
</project>
Next I want to obfuscate my Java classes (I'll be using Allatori obfuscater), so I'm thinking the easiest thing would be if my Java classes were all put into their own JAR file and stored in the /WEB-INF/lib folder with the rest of the JARs.
Is there a way to modify my Maven pom.xml file so it will package of my classes up in a JAR and put the JAR in the /WEB-INF/lib folder?
UPDATE:
Adding this to the 'build' section (as suggested by "JF Meier" worked) ...
<build>
<finalName>myapp</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>3.3.0</version>
<configuration>
<archiveClasses>true</archiveClasses>
</configuration>
</plugin>
</plugins>
</build>
You can use the <archiveClasses> configuration (set it to true) to generate an additional jar with the classes.
Also see:
https://maven.apache.org/plugins/maven-war-plugin/war-mojo.html
Move your Java classes in a separate Maven module and add that as a dependency to your WAR project. Then you can do whatever is necessary creating the jar in that module.

Deploy maven project ear in websphere

I am using eclipse JUNO integrated with websphere 8.5.My problem is that,my project is in MAVEN module so each time i have to clean and install the MAVEN Project to generate the EAR.
After EAR generation, I have to remove the ibm related xml's inside the META-INF folder and WEB-INF folder and then I have to open the administrative console in websphere to deploy the EAR.This alone is taking huge amount of time.
Could any one please suggest a script to deploy and run the MAVEN project in websphere.
<?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.sample.app</groupId>
<artifactId>SAMPLE_APP</artifactId>
<version>1.0</version>
<packaging>pom</packaging>
<name>SAMPLE APP</name>
<modules>
<module>SAMPLE_APP_Props</module>
<!-- Changes to UI Framework -->
<module>SAMPLE_APP_UIFile</module>
<module>SAMPLE_APP_Web</module>
<module>SAMPLE_APP_EAR</module>
<module>SAMPLE_APP_Forms</module>
<module>SAMPLE_APP_Filters</module>
<module>SAMPLE_APP_Logging</module>
<module>SAMPLE_APP_Security</module>
</modules>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.5</source>
<target>1.5</target>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
The below 2Files i have to remove before i deploy the generated ear in websphere.
ibm-application-bnd.xmi
ibm-application-ext.xmi

Maven generate jar dependencies then war

I'm using m2e Maven Plugin for Eclipse. I'm having 5 eclipse projects. A web application project and then 4 projects as jars dependencies for my web application.
I would like to know how can I package jars before including them in the WAR using "mvn clean install" on war project.
Here's my pom.xml:
<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>dispatcher</groupId>
<artifactId>dispatcher</artifactId>
<version>4.0</version>
<packaging>war</packaging>
<build>
<plugins>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.3</version>
<configuration>
<warSourceDirectory>WebContent</warSourceDirectory>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>referentiel</groupId>
<artifactId>referentiel</artifactId>
<version>4.7</version>
</dependency>
<dependency>
<groupId>mailTemplates</groupId>
<artifactId>mailTemplates</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>qualityTool</groupId>
<artifactId>qualityTool</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>tools</groupId>
<artifactId>tools</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
...
..
.
</dependencies>
</project>
Thank you in advance.
The answer of #Jigar Joshi is good but i thing you need a view of structure which can help you to understand quickly what we mean.
I. Create a top level maven module (parent of war and jars)
You habe already the 5 moduls that you need. Now create a new Maven project as parent which must contain only a pom.xml file.
parent project pom
<project...>
<groupId>groupId</groupId>
<artifactId>parent-pom</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<name>Define parent pom </name>
<!-- modul -->
<project>
II. Put your jar projects first as modul and at the end the war project. If you have another dependencies in the jar projects you may also try to order them consequently.
parent project pom
<modules>
<module>referentiel</module> <!-- jar -->
<module>mailTemplates</module> <!-- jar -->
<module>qualityTool</module> <!-- jar -->
<module>tools</module> <!-- jar -->
<module>dispatcher</module> <!-- war-->
</modules>
III. in all other project put the parent reference into the poms
<parent>
<groupId>groupId</groupId>
<artifactId>parent-pom</artifactId>
<version>1.0-SNAPSHOT</version>
<parent>
IV. Now you can go to inside the new created parent project and run from there
mvn clean install
Either create a top level maven module (parent of war and jars) and execute mvn clean install
---pom.xml
|
|dispatcher---pom.xml (war)
|qualityTool----pom.xml (jar)
|mailTemplates----pom.xml (jar)
|referentiel----pom.xml (jar)
|tools----pom.xml (jar)
or use --also-make command line option to make dependencies as well

communicate between wars and jar inside ear

I'm new to creating ear and communicaton between wars and jar...
I was having two wars having completely independent functionality.
Now I've to create a Ear, where two application have to work on same functionality,
which is enclosed in a jar.But requirement is I must not include the jar in Pom.xml of both but make use of that jar, where all 3 are under single ear.is this is possible?
I've tested Ear with 2 independent wars and it's working fine now how to achieve above I'm not getting this.
I'm using Maven with Jboss7.1.1.
I went through links like MessageHandler in JAR/WAR/EAR , https://stackoverflow.com/questions/1796255/tell-me-a-clear-differnece-between-ear-war-and-jar but got no idea about above problem.
You can put multiple wars and jars into a ear and they can share the same classloader. This means that all the classes are accessible from all the jars/wars. i.e. it is as if all the classes / resouces are in one archive without the sub-packaging.
I am assuming this is what you mean by "communication between wars and jars".
EDIT: check Making an EAR with Maven for an example of the pom.xml for building an ear. In the example, there is one jar and one war but you could have any number of wars / jars.
Hi got the solution >> here it is.. this is a pom.xml of ear project
<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</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>ear</packaging>
<dependencies>
<!--Dependency for jar-->
<dependency>
<groupId>com.jar</groupId>
<artifactId>com.jar</artifactId>
<version>1.0</version>
<type>war</type>
</dependency>
<!--Dependency for war1-->
<dependency>
<groupId>com.war2</groupId>
<artifactId>com.war2</artifactId>
<version>0.0.1-SNAPSHOT</version>
<type>war</type>
</dependency>
<!--Dependency for war2-->
<dependency>
<groupId>com.war1</groupId>
<artifactId>com.war1</artifactId>
<version>0.0.1-SNAPSHOT</version>
<type>war</type>
</dependency>
</dependencies>
<build>
<finalName>Project</finalName>
<plugins>
<plugin>
<artifactId>maven-ear-plugin</artifactId>
<version>2.8</version>
<configuration>
<finalName>MyEarFile</finalName>
<version>5</version>
<modules>
<!--Webmodule for war1-->
<webModule>
<groupId>com.war1</groupId>
<artifactId>com.war1</artifactId>
<uri>war1.war</uri>
<bundleFileName>war1.war</bundleFileName>
</webModule>
<!--Webmodule for war2-->
<webModule>
<groupId>com.war2</groupId>
<artifactId>com.war2</artifactId>
<uri>war2.war</uri>
<bundleFileName>war2.war</bundleFileName>
</webModule>
</modules>
</configuration>
</plugin>
</plugins>
</build>
</project>
Note:: groupId and artifactId metioned here must match with groupId and artifactId mentioned in the project's pom.xml.
Also dependency of jar must be present in this i.e. ear's pom.xml and not in both app's pom.xml.
At time of maven install it automatically refers to jar's contents..

Datanucleus JDO in maven assembly jar

I used the maven assembly package to create a single monolithic jar. Included is the datanucleus package, but I am getting errors because I did not maintain the OSGI structure (plugins.xml & META-INF/META-INF.MD). The answers on stackoverflow([question]: Datanucleus, JDO and executable jar - how to do it?) do not provide answers on how to create the single deployable jar.
Does anyone know what maven directives I can use to ensure OSGI structure?
So, the problem is that packing everything into a monolithic jar is that the OSGI structures get overritten by the OSGI structure of other jars. The benefit of the monolithic jar was to have a single file to push to the server but not necessary (since I was using capistrano to push to the server)
Instead, it's easier to just copy the jars into the final build directory. Heroku's Java setup has a perfect example of this:
https://devcenter.heroku.com/articles/java
<?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.example</groupId>
<version>1.0-SNAPSHOT</version>
<artifactId>helloworld</artifactId>
<dependencies>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-servlet</artifactId>
<version>7.6.0.v20120127</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals><goal>copy-dependencies</goal></goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

Categories