I have a maven ear module with the following configuration for my ear file:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-ear-plugin</artifactId>
<version>2.6</version>
<configuration>
<displayName>app</displayName>
<description>app</description>
<modules>
...
<ejbModule>
<groupId>com.example</groupId>
<artifactId>example-client</artifactId>
<bundleFileName>example-client.jar</bundleFileName>
</ejbModule>
..
</modules>
<defaultLibBundleDir>lib</defaultLibBundleDir>
<version>5</version>
</configuration>
</plugin>
When I use Intellij (ultimate 12.1.4) to deploy my ear to a jboss as, the bundleFileName is ignored.
It creates a jar file with version number, but in the application.xml the jar file is defined without version.
Is there a way to fix this? I deploy using the "exploded" ear.
Thanks!
The issue is fixed in Intelij 13 (currently not yet release): see http://youtrack.jetbrains.com/issue/IDEA-114355
Related
I am working on converting a J2EE application to Maven where the EAR project will contain a WAR module. I have followed the below URL to convert the project and it does work with some minor changes:
https://www.ibm.com/docs/en/wasdtfe?topic=projects-converting-existing-maven
In the current project, there are some libraries under the EAR folder which I cannot move to the local maven repository. The reason is old legacy code which expects these library names to be intact (myCommon.jar and no version to be added like myCommon-1.0.jar).
As a workaround, I placed these libs under EAR->src->main->application->lib folder. There is no build failure observed but the major problem is with the ClassPath for these EAR lib files as shown below:
[err] java.lang.ClassNotFoundException: com.myClass.classFromWAR
[err] at java.lang.Class.forNameImpl(Native Method)
[err] at java.lang.Class.forName(Class.java:332)
E.g. myCommon.jar contains code like the below:
public void EARLibFunc( string classNameFromWAR){
.........
//E.g. classNameFromWAR = "com.myClass.classFromWAR";
final Class warClass = Class.forName( classNameFromWAR );
.........
}
Calling above function from the java files inside WAR module reports ClassNotFoundException: EARLibFunc("com.myClass.classFromWAR");
The directory structure looks like the below:
WARProject
-src
----com
--------myClass
------------classFromWAR.java
EARProject
-src
----main
--------application
------------lib
----------------myCommon.jar
The jar files from EAR/src/main/application don't seem to be part of the ClassPath.
Can you please suggest the best practice to handle such an issue? What should be the correct layout of the EAR libraries to make it part of the ClassPath? Please be informed that the code from the EAR libraries cannot be changed (legacy code dependency issue).
For reference here are my pom settings:
WARProject pom.xml:
.......
.......
<groupId>MyApp</groupId>
<artifactId>MyApp</artifactId>
<version>3.5</version>
<packaging>war</packaging>
<description>MyApp Maven</description>
........
<build>
<resources>
<resource>
<directory>Java Source</directory>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
</resource>
</resources>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>3.0.0</version>
<configuration>
<warSourceDirectory>Web Content</warSourceDirectory>
</configuration>
</plugin>
</plugins>
</build>
......
EAR Project pom.xml (contains WAR module as dependency):
.....
<groupId>EARProject_EAR</groupId>
<artifactId>EARProject_EAR</artifactId>
<version>3.5</version>
<packaging>ear</packaging>
<description>My Project EAR</description>
<build>
<plugins>
<plugin>
<artifactId>maven-ear-plugin</artifactId>
<version>2.10</version>
<configuration>
<version>7</version>
<skinnyWars>true</skinnyWars>
<defaultLibBundleDir>lib</defaultLibBundleDir>
<archive>
<manifest>
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
<addClasspath>true</addClasspath>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>MyApp</groupId>
<artifactId>MyApp</artifactId>
<version>3.5</version>
<type>war</type>
</dependency>
</dependencies>
......
SOLUTION:
The crash reported for the CLASSPATH is resolved. Since I am moving an old legacy application to Maven, there were some old references to be cleaned-up. Below changes were required:
There were duplicate classpath references in the eclipse Project
(Project -> Properties -> Java Build Path). Even though I had
dependencies mentioned in the pom.xml of the WAR file, the project
properties were also having its references. This may or may not be
the real reason.
Reverted earlier workaround solution. Removed libraries from
EAR->src-main->application->lib and added those as dependency in the
WAR pom.xml reference. Though it has re-created other legacy issue
but I believe this will adhere to the best practices.
I think, it should be possible this way:
Install the jar in your local maven repository.
Configure the maven-ear-plugin to include third party libraries as shown here.
Add <bundleFileName>myCommon.jar</bundleFileName> to jarModule in order to give your JAR file the desired name within the EAR.
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-ear-plugin</artifactId>
<version>3.2.0</version>
<configuration>
[...]
<modules>
<jarModule>
<groupId>artifactGroupId</groupId>
<artifactId>artifactId</artifactId>
<includeInApplicationXml>true</includeInApplicationXml>
<bundleFileName>myCommon.jar</bundleFileName>
</jarModule>
</modules>
</configuration>
</plugin>
</plugins>
</build>
More information can be found at the usage page of the plugin.
I am building this multi-module project with Maven. The folder structure of the project at root is as follows:
core (dir)
|--- pom.xml
|--- pom (dir)
|---com.loc.dist.core.msp.osgi.pom (dir)
|---pom.xml
|--- com.lgc.dist.core.msp.example.helloservice.client (dir)
|---pom.xml
Project com.lgc.dist.core.msp.example.helloservice.client is packaged as OSGI bundle and it is a child module of com.loc.dist.core.msp.osgi.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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.lgc.dist</groupId>
<artifactId>com.lgc.dist.core.msp.osgi.pom</artifactId>
<relativePath>../pom/com.lgc.dist.core.msp.osgi.pom</relativePath>
<version>0.1</version>
</parent>
<artifactId>com.lgc.dist.core.msp.example.helloservice.client</artifactId>
<packaging>bundle</packaging>
<dependencies>
<dependency>
<groupId>com.lgc.dist</groupId>
<artifactId>com.lgc.dist.core.msp.service</artifactId>
<version>0.1</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<configuration>
<instructions>
<Export-Package>com.lgc.dist.core.msp.example.helloservice.client.*;version=${project.version}</Export-Package>
<Private-Package>com.lgc.dist.core.msp.example.helloservice.client.internal</Private-Package>
<Import-Package>*</Import-Package>
</instructions>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-scr-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
The pom.xml in top level shows pom folder and com.lgc.dist.core.msp.example.helloservice.client are in the reactor list.
<modules>
<module>pom</module>
<module>com.lgc.dist.core.msp.example.helloservice.client</module>
</modules>
When I ran mvn clean install from the root, it tends to build com.lgc.dist.core.msp.example.helloservice.client back to back twice. It is ok to install twice, but it will cause trouble when I run mvn deploy. All other submodules just built once. It is only the child modules of com.loc.dist.core.msp.osgi.pom are being built twice. I guess osgi builds all the bundle modules by default. But if I comment it out in pom.xml, the osgi bundle modules won't get built at all. What should I do to build these OSGI bundles just once?
EDIT It works fine if I change the packaging mode from bundle to jar, but that negates the purpose of having OSGI bundles.
Since the project "com.lgc.dist.core.msp.example.helloservice.client" is not a direct child of top level pom.xml, remove it from there.
So, in top level pom.xml, the entries should be :
<modules>
<module>pom/com.loc.dist.core.msp.osgi.pom</module>
</modules>
And pom.xml in pom/com.loc.dist.core.msp.osgi.pom should be having :
<modules>
<module>com.lgc.dist.core.msp.example.helloservice.client</module>
</modules>
After some research, it turns out maven-bundle-plugin 2.5.4 deploys the bundles by default. According to one of the answers of When using “bundle” packaging with maven-bundle-plugin goals are executed twice
(I'm surprised it did not get any up votes), you need to stop deploying by adding the execution block
<executions>
<execution>
<id>default-deploy</id>
<phase>no-execute</phase>
<goals>
<goal>deploy</goal>
</goals>
</execution>
</executions>
It is working now.
EDIT, based on the comment of this answer, it is resolved in 2.5.5. Haven't tried it though.
I have a War file that has dependencies and class files that I need in it that I am trying to include in my project with Maven. Inside the War file, there is a WEB-INF that contains those libs and classes. I have tried everything that I know to try to get this going, but my knowledge of Maven is limited.
I have tried simply listing the War as a dependency and following the process described here to install the third-party library, but when I do that Maven says it can't find my packages that I need when I try to install.
I have tried overlaying the War as described here with no luck.
I have tried maven-warpath-plugin but didn't really have any luck either.
Should any of these tools solve my problem? Is how I am trying to solve the problem possible in this way? Or am I completely off base?
Here are the important parts of my pom.xml from using the maven-warpath-plugin:
<build>
...
<pluginManagement>
<plugins>
<plugin>
<groupId>org.appfuse</groupId>
<artifactId>maven-warpath-plugin</artifactId>
<version>1.0-SNAPSHOT</version>
<extensions>true</extensions>
<executions>
<execution>
<goals>
<goal>add-classes</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
...
</build>
<repositories>
<repository>
<id>data-local</id>
<name>data</name>
<url>file://${project.basedir}/o</url>
</repository>
</repositories>
<dependencies>
...
<dependency>
<groupId>my.local.dep</groupId>
<artifactId>MyLocalDep</artifactId>
<version>1.1.1.1</version>
<type>war</type>
</dependency>
<dependency>
<groupId>my.local.dep</groupId>
<artifactId>MyLocalDep</artifactId>
<version>1.1.1.1</version>
<type>warpath</type>
</dependency>
</dependencies>
Unpack the war in a separate clean step first and add the unpacked jars as system dependency in the main step.
Idea is from here: https://stackoverflow.com/a/6120395/503025
I'm using Eclipse Luna with Websphere Application Sever 8.5.
When I run a dynamic web project using the Websphere Application Sever 8.5 it runs fine.
However, when I convert a dynamic web project to a maven project, i'm getting around 53 errors starting with Missing artifact com.ibm.websphere e.g Missing artifact com.ibm.websphere.xml:xmlapi:jar:1.0.0' all located in my pom.xml.
I am also getting this error:
The container 'Maven Dependencies' references non existing library
C:\Users\Brian242\.m2\repository\com\ibm\websphere\ws\com.ibm.ws.wccm\1.0.0\com.ibm.ws.wccm-1.0.0.jar'
Not sure if that's part of the problem.
I've looked everywhere for a solution but haven't found anything. So I have decided to ask for some help. Does anyone know how to solve the above problem/s?
Thank you,
Brian
<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>TrialProj</groupId>
<artifactId>TrialProj</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<dependencies>
<dependency>
<groupId>com.ibm.tools.target</groupId>
<artifactId>was</artifactId>
<version>8.5.5</version>
<type>pom</type>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.4</version>
<configuration>
<warSourceDirectory>WebContent</warSourceDirectory>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
</plugins>
</build>
</project>
you created M2_REPO environment variable?
right click on the project root
Build Path-> Configure Puild Path ...
Click button 'Add Variable'
Click 'Set Variable ...'
Click 'New ...'
name: M2_REPO
Path: / path_to_repository_the_maven /
Click Ok
Recompile
If you are using eclipse make sure you add suport for eclipse web tools using:
mvn eclipse:eclipse -Dwtpversion=2.0
(2.0 or your required version) And afterwards recompile maven project:
mvn compile
I'd like to use maven to include jar/war's libraries in my EAR project's lib folder.
Currently my ear looks like this :
lib
lib/<entities>.jar
lib/<ejb-client>.jar
<ejb-impl>.jar
<web-app-project>.war
Each jar/war have maven dependencies which are declared with scope provided.
Why scope provided? I'm using Glassfish 3.1.2 and having issue when I put libraries in /WEB-INF/lib. I fixed the issue by copying libs in ear/lib instead (see Spring / Glassfish 3.1.2 stale files).
What I want to do is to tell to maven he has to put thoses librairies in the ear's lib folder.
I tried to put all projects in the ear's maven dependencies but it's not working actually.
Could someone help me ?
Thanks,
Smoky
This is similar to Including A Third Party Library In application.xml
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-ear-plugin</artifactId>
<version>2.9</version>
<configuration>
[...]
<modules>
<jarModule>
<groupId>artifactGroupId</groupId>
<artifactId>artifactId</artifactId>
<bundleFileName>entities.jar</bundleFileName>
</jarModule>
</modules>
</configuration>
</plugin>
</plugins>
</build>