I am trying to create ear with multiple wars. Let's say i have 3 web projects with the name web1, web2, web3. These 3 web projects repositories are placed in SVN. So now i wants to create a pom.xml file which creates ear with 3 wars by accessing 3 repositories in one ear file.
I tried it by placing all modules locally using below configuration.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-ear-plugin</artifactId>
<version>2.8</version>
<configuration>
<defaultJavaBundleDir>lib</defaultJavaBundleDir>
<skinnyWars>true</skinnyWars>
<archive>
<manifestEntries>
<Implementation-Description>${project.description}</Implementation-Description>
<Implementation-Vendor>Demo</Implementation-Vendor>
<Implementation-Version>${project.version}</Implementation-Version>
</manifestEntries>
</archive>
<modules>
<webModule>
<groupId>com.demo.ps</groupId>
<artifactId>web1</artifactId>
<bundleFileName>web1.war</bundleFileName>
<contextRoot>/web1</contextRoot>
</webModule>
<webModule>
<groupId>com.demo.ps</groupId>
<artifactId>web1</artifactId>
<bundleFileName>web2.war</bundleFileName>
<contextRoot>/web2</contextRoot>
</webModule>
</modules>
<defaultLibBundleDir>lib</defaultLibBundleDir>
</configuration>
</plugin>
and under dependencies
<dependency>
<groupId>com.demo.ps</groupId>
<artifactId>web1</artifactId>
<version>0.0.1-SNAPSHOT</version>
<type>war</type>
</dependency>
<dependency>
<groupId>com.demo.ps</groupId>
<artifactId>web1</artifactId>
<version>0.0.1-SNAPSHOT</version>
<type>pom</type>
</dependency>
<dependency>
<groupId>com.demo.ps</groupId>
<artifactId>web2</artifactId>
<version>0.0.1-SNAPSHOT</version>
<type>war</type>
</dependency>
<dependency>
<groupId>com.demo.ps</groupId>
<artifactId>web2</artifactId>
<version>0.0.1-SNAPSHOT</version>
<type>pom</type>
</dependency>
by using above configuration it is creating 2 individual wars inside ear file, but i want some guidance to build same by accessing both repositories remotely.
Thanks in advance !!!!
Related
Netbeans 8.2, glassfish 5
In my maven EAR proyect, when I clean+build, it generates an EAR file. If I add this file manually to my glassfish (via glassfish console) it deploys OK and run the application.
Added glassfish to netbeans, but when click run on glassfish service, server starts, but doesnt deploy nothing. EAR file generates OK but glassfish doesnt deploy it.
My POM file in the EAR project (REMOVED SOME DEPENDENCIES AND MODULES TO SHORT IT):
<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>
<artifactId>b2btravel.ear.deploy</artifactId>
<packaging>ear</packaging>
<name>B2B ear deploy</name>
<description>B2B Travel WEB-EAR deply</description>
<parent>
<groupId>b2btravel</groupId>
<artifactId>b2btravel</artifactId>
<version>1.4.11</version>
</parent>
<dependencies>
<!-- INTERNAL BUSINESS -->
<dependency>
<groupId>b2btravel</groupId>
<artifactId>b2btravel.business</artifactId>
<version>${project.version}</version>
<type>ejb</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>b2btravel</groupId>
<artifactId>b2btravel.web.bck</artifactId>
<version>${project.version}</version>
<type>war</type>
<scope>compile</scope>
</dependency>
<!-- EXTERNAL -->
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-ear-plugin</artifactId>
<version>${maven.ear.plugin}</version>
<goals>
<goal>generate-application-xml</goal>
<goal>ear</goal>
</goals>
<configuration>
<version>7</version>
<applicationId>${application.web.id}</applicationId>
<applicationName>${application.web.name}</applicationName>
<displayName>${application.web.display.name}</displayName>
<defaultLibBundleDir>lib/</defaultLibBundleDir>
<tempFolder>${project.build.directory}/${ear.web.file.name}</tempFolder>
<workDirectory>${project.build.directory}/${ear.web.file.name}/work</workDirectory>
<skinnyWars>true</skinnyWars>
<!-- If I want maven to generate the application.xml, set this to
true -->
<generateApplicationXml>true</generateApplicationXml>
<modules>
<!-- WEB MODULES -->
<jarModule>
<groupId>b2btravel</groupId>
<artifactId>b2btravel.web</artifactId>
<bundleDir>/</bundleDir>
<bundleFileName>b2btravel.web.jar</bundleFileName>
<includeInApplicationXml>false</includeInApplicationXml>
</jarModule>
<webModule>
<groupId>b2btravel</groupId>
<artifactId>b2btravel.web.bck</artifactId>
<bundleFileName>b2btravel.web.bck.war</bundleFileName>
<contextRoot>/bck</contextRoot>
</webModule>
<ejbModule>
<groupId>b2btravel</groupId>
<artifactId>b2btravel.business</artifactId>
<bundleFileName>b2btravel.business.jar</bundleFileName>
</ejbModule>
</modules>
<archive>
<manifest>
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
<addDefaultSpecificationEntries>true</addDefaultSpecificationEntries>
</manifest>
</archive>
<finalName>${ear.web.file.name}</finalName>
</configuration>
</plugin>
</plugins>
</build>
</project>
I have a maven project where i am package to EAR file and including all dependencies in /lib folder. But while deploying EAR file i am getting below 2 errors in jboss.
1)java.lang.ClassFormatError: Absent Code attribute in method that is not native or abstract in class file javax/jms/JMSException
For above error i learnt that i need to remove j2ee related jar files going inside the /lib folder.
2)java.lang.ClassCastException: com.xx.sms.ejb.ws.xxx.CoordinatorServiceBean cannot be cast to javax.servlet.Servlet
And this error i believe i should remove javax.servlet related jar files from /lib folder. Because this may be already provided by jboss servletContainer and you should exclude from your /lib folder.
I am new to maven world and somehow i managed to create a EAR.
Let me know how to exclude j2ee related and servlet related jar files during packing EAR.
Below is my pom.xml
<dependencies>
<dependency>
<groupId>com.xxx.sms</groupId>
<artifactId>CoordinatorBeans</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.xxx</groupId>
<artifactId>CoordinatorWeb</artifactId>
<version>1.0-SNAPSHOT</version>
<type>war</type>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-ear-plugin</artifactId>
<configuration>
<defaultLibBundleDir>lib</defaultLibBundleDir>
<earSourceDirectory>${basedir}</earSourceDirectory>
<earSourceIncludes>META-INF/*</earSourceIncludes>
<archive>
<manifest>
<addClasspath>true</addClasspath>
</manifest>
</archive>
<generateApplicationXml>false</generateApplicationXml>
<applicationXML>${basedir}/META-INF/application.xml</applicationXML>
<modules>
<jarModule>
<groupId>com.xxx.sms</groupId>
<artifactId>CoordinatorBeans</artifactId>
<bundleDir>/</bundleDir>
<bundleFileName>CoordinatorBeans.jar</bundleFileName>
</jarModule>
<webModule>
<groupId>com.xxx</groupId>
<artifactId>CoordinatorWeb</artifactId>
<bundleDir>/</bundleDir>
<bundleFileName>CoordinatorWeb.war</bundleFileName>
</webModule>
</modules>
</configuration>
</plugin>
</plugins>
<finalName>CoordinatorApp</finalName>
</build>
After adding exclusions for below dependency it worked.
<dependency>
<groupId>com.sun.xml.ws</groupId>
<artifactId>jaxws-rt</artifactId>
<version>2.2</version>
<exclusions>
<exclusion>
<groupId>*</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>
I started using the maven ear plugin about 12 months ago and want to find out if there are any alternatives. One of the benefits of Maven is the dependency management however you seem to almost completely lost this with the ear plugin. It builds all the dependant jar's into the ear but won't actually put any of them on the classpath with out adding the configuration below:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-ear-plugin</artifactId>
<version>2.4</version>
<configuration>
<version>6</version>
<modules>
<ejbModule>
<groupId>com.mycompany.app</groupId>
<artifactId>MyApplication-ejb</artifactId>
</ejbModule>
<jarModule>
<groupId>axis</groupId>
<artifactId>axis</artifactId>
<bundleDir>lib</bundleDir>
</jarModule>
<jarModule>
<groupId>commons-discovery</groupId>
<artifactId>commons-discovery</artifactId>
<bundleDir>lib</bundleDir>
</jarModule>
<jarModule>
<groupId>axis</groupId>
<artifactId>axis-wsdl4j</artifactId>
<bundleDir>lib</bundleDir>
</jarModule>
</modules>
</configuration>
</plugin>
Am I missing something does a more recent version of the plugin eliminate the need for this, is there an alternative that manages this for you? I can't believe each time I add a dependency to a module I need to add it to the ear pom configuration. The most frustrating thing is even if I remember to add a dependant library to the above configuration, if that is in turn dependent on something else (as was the case with axis) I am only finding out when I deploy the ear.
First you should have a separate module for the ear (and of course ear ) which looks like the following:
root
+-- client
! +--- pom.xml
+-- service
! +--- pom.xml
+-- ear
+--- pom.xml
Second you should update the version of the ear plugin, cause the current version is 2.6. Furthermore define your parts as dependencies
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-ear-plugin</artifactId>
<version>2.5</version>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>webgui</artifactId>
<version>${project.version}</version>
<type>war</type>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>service</artifactId>
<version>${project.version}</version>
<type>ejb</type>
</dependency>
</dependencies>
The configuration you are using is intended for supplemental 3rd party libs which should be packaged.
In addition to the answer of khmarbaise I want to note that in order for your EJB Module to be able to access the libraries you have to configure it to include the dependencies inside the META-INF/MANIFEST.MF like this:
<plugin>
<artifactId>maven-ejb-plugin</artifactId>
...
<configuration>
...
<archive>
<manifest>
<addClasspath>true</addClasspath>
</manifest>
</archive>
</configuration>
...
</plugin>
I'm finishing my project build (with maven), and it's working great. Now I just have to "pack it", as an ear.
All I need to do is pack 3 dependencies, one .jar and 2 .war. Don't ask me how, that was the way it was done before (with ant), and I'm translating it to maven - next I'll organize the packages, so we can be more productive.
However, I'm having a few problems. First, the package is named null-${version}.ear. It copies itself right to the repository, but in the target folder is wrongly named. And second, it's copying all the other packages dependencies. I want to know what can I do about the null name, and the copying of the packages.
Here is my pom:
<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>
<parent>
<groupId>owner</groupId>
<artifactId>coreisp</artifactId>
<version>2.0</version>
</parent>
<groupId>owner</groupId>
<artifactId>coreisp-app</artifactId>
<packaging>ear</packaging>
<version>2.0</version>
<name>Projeto CoreISP</name>
<dependencies>
<dependency>
<groupId>${pom.groupId}</groupId>
<artifactId>coreisp-core</artifactId>
<version>${pom.version}</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>${pom.groupId}</groupId>
<artifactId>coreisp-initializer</artifactId>
<type>war</type>
<version>${pom.version}</version>
</dependency>
<dependency>
<groupId>${pom.groupId}</groupId>
<artifactId>coreisp-site</artifactId>
<type>war</type>
<version>${pom.version}</version>
</dependency>
</dependencies>
<build>
<finalName>${application.id}-${pom.version}</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-ear-plugin</artifactId>
<version>2.3</version>
<configuration>
<modules>
<jarModule>
<groupId>owner</groupId>
<artifactId>coreisp-core</artifactId>
<includeInApplicationXml>
true
</includeInApplicationXml>
<bundleDir>/</bundleDir>
</jarModule>
<webModule>
<groupId>owner</groupId>
<artifactId>
coreisp-initializer
</artifactId>
<bundleDir>/</bundleDir>
</webModule>
<webModule>
<groupId>owner</groupId>
<artifactId>
coreisp-site
</artifactId>
<bundleDir>/</bundleDir>
</webModule>
</modules>
</configuration>
</plugin>
</plugins>
</build>
</project>
First of all remove the element from your POM, the application.id property is what gives you the "null" name.
As to ensure that transitive dependencies do not end up in your EAR I suggest you specify explicitly in your POM what you do want and what you do not want. In order to keep a dependency out all you need to do is define it in your POM with a scope of provided. I know it's a painful job, but in my opinion it's worth it, to ensure that you get exactly what you want.
I declared a custom jboss-app.xml in my pom.xml, but the plugin is generating an internal and empty jboss-app.xml file into ear/META-INF.
I created my pom.xml based on this article with the following definition:
<plugin>
<artifactId>maven-ear-plugin</artifactId>
<configuration>
<data-sources>
<data-source>${artifactId}/src/main/resources/mytest-ds.xml</data-source>
</data-sources>
<jboss>${artifactId}/src/main/resources/jboss-app.xml</jboss>
<defaultLibBundleDir>lib</defaultLibBundleDir>
<archive>
<manifest>
<addClasspath>true</addClasspath>
</manifest>
</archive>
<modules>
<ejbModule>
<groupId>com.testproject</groupId>
<artifactId>ejb-project</artifactId>
</ejbModule>
</modules>
</configuration>
</plugin>
But, I can't handle my custom jboss-app.xml. A new is empty descriptor (without defined ejbs) is generated every time.
You should be able to simply include your jboss-app.xml in your source tree and Maven will pull it in.
Your project directory structure for the maven-ear-plugin should look like:
|-- pom.xml
`-- src
`-- main
`-- application
`-- META-INF
|-- application.xml
`-- jboss-app.xml
Then just run mvn package to create your EAR. Assuming the packaging for your pom.xml is 'ear' it will pull jboss-app.xml into your resulting ear.
Also, I believe your <datasources>...</datasources> configuration needs to be within the <jboss>...</jboss> tags.
See also: http://maven.40175.n5.nabble.com/Deployment-of-the-jboss-app-xml-file-td45009.html
From the docs, it looks like jboss tag triggers the generation of jboss-app.xml. How about omitting this tag and generating the ear?
Alternative would be to pull datasources via application.xml as described here. But as <jarModule> requires are full-blown maven artifact, that is longer way (perhaps for application servers other than JBoss):
• project/ds/pom.xml:
<artifactId>project-ds</artifactId>
<packaging>jar</packaging>
<name>My DataSource</name>
• project/ds/src/main/resources/my-ds.xml:
<datasources>
<local-tx-datasource>
...
• project/ear/pom.xml (assuming that driver is also packaged in EAR):
<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>project-ds</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>project-war</artifactId>
<version>${project.version}</version>
<type>war</type>
</dependency>
<dependency>
<groupId>net.sourceforge.jtds</groupId>
<artifactId>jtds</artifactId>
<version>${jtds.driver.version}</version>
</dependency>
</dependencies>
...
<plugin>
<artifactId>maven-ear-plugin</artifactId>
<configuration>
<modules>
<jarModule>
<groupId>net.sourceforge.jtds</groupId>
<artifactId>jtds</artifactId>
<includeInApplicationXml>true</includeInApplicationXml>
</jarModule>
<jarModule>
<groupId>${project.groupId}</groupId>
<artifactId>project-ds</artifactId>
<unpack>true</unpack>
<uri>/</uri>
<bundleFileName>my-ds.xml</bundleFileName>
<includeInApplicationXml>true</includeInApplicationXml>
</jarModule>
<webModule>
<groupId>${project.groupId}</groupId>
<artifactId>project-war</artifactId>
<contextRoot>${context.path}</contextRoot>
</webModule>
</modules>
</configuration>
</plugin>
Will generate META-INF/application.xml:
<application>
<display-name>project-ear</display-name>
<description>...</description>
<module>
<java>jtds-1.2.4.jar</java>
</module>
<module>
<java>my-ds.xml</java>
</module>
<module>
<web>
<web-uri>project-war-1.0.0.war</web-uri>
<context-root>/</context-root>
</web>
</module>
</application>