Hi,
On 12.11.20 14:13, Hohl, Gerrit wrote:
Hello everyone,
maybe some additional information will be helpful.
The project structure is like (and also build in this order due to the
dependencies of the modules):
- XXX-pom
- XXX-ejb
My assumption is that ejb project uses packaging: ejb?
Where is the ejb module used? And how?
Which version of maven-ejb-plugin have you defined in your build?
- XXX-web
- XXX-ear
Here the excerpt from the pom.xml of the XXX-web module:
<project>
<parent>
<groupId>XXX</groupId>
<artifactId>XXX-pom</artifactId>
<version>1.0.18</version>
</parent>
<artifactId>XXX-web</artifactId>
<packaging>war</packaging>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<webResources>
<resource>
<directory>${generated-webbapp-folder}</directory>
</resource>
</webResources>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<executions>
<!-- Ensure that the JAR version ends up in the
local repository -->
<execution>
<id>jar-install</id>
<phase>install</phase>
<goals>
<goal>install-file</goal>
</goals>
<configuration>
<file>${project.build.directory}/${project.artifactId}-${project.version}.jar</file>
<packaging>jar</packaging>
<javadoc>${project.build.directory}/${project.artifactId}-${project.version}-javadoc.jar</javadoc>
<sources>${project.build.directory}/${project.artifactId}-${project.version}-sources.jar</sources>
</configuration>
</execution>
</executions>
</plugin>
This does not make sense. If you like to create and deploy a separate
jar file of the classes which are being compiled in the war module you
should use:
<archiveClasses>true</archiveClasses>
<attachClasses>true</attachClasses>
configuration of the maven-war-plugin which will do and create an
appropriate jar file for those classes.
I strongly recommend to upgrade maven-war-plugin, maven-ear-plugin
versions to the most recent ones...
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<executions>
<!-- Ensure that the JAR version ends up in the
remote repository -->
<execution>
<id>jar-deploy</id>
<phase>deploy</phase>
<goals>
<goal>deploy-file</goal>
</goals>
<configuration>
<file>${project.build.directory}/${project.artifactId}-${project.version}.jar</file>
<groupId>${project.groupId}</groupId>
<artifactId>${project.artifactId}</artifactId>
<version>${project.version}</version>
<packaging>jar</packaging>
<generatePom>false</generatePom>
<javadoc>${project.build.directory}/${project.artifactId}-${project.version}-javadoc.jar</javadoc>
<sources>${project.build.directory}/${project.artifactId}-${project.version}-sources.jar</sources>
<repositoryId>${project.distributionManagement.repository.id}</repositoryId>
<url>${project.distributionManagement.repository.url}</url>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Same as above... remove this part...
Manually calling install-file/deploy-file is in 99.999% of the cases
simply wrong...
And here the excerpt from the pom.xml of the XXX-ear module:
<project>
<parent>
<groupId>XXX</groupId>
<artifactId>XXX-pom</artifactId>
<version>1.0.18</version>
</parent>
<artifactId>XXX-web</artifactId>
<packaging>war</packaging>
<dependencies>
<dependency>
<groupId>XXX</groupId>
<artifactId>XXX-web</artifactId>
<version>${project.version}</version>
<type>war</type>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-ear-plugin</artifactId>
<configuration>
<modules>
<webModule>
<groupId>XXX</groupId>
<artifactId>XXX-web</artifactId>
<uri>XXX-web-${project.version}.war</uri>
<bundleFileName>XXX-web-${project.version}.war</bundleFileName>
<contextRoot>/XXX</contextRoot>
<bundleDir>/</bundleDir>
</webModule>
</modules>
</configuration>
</plugin>
</plugins>
</build>
</project>
The <webModule> specifies that the type of the artifact must be WAR.
So the maven-ear-plugin tries to match that against the artifacts of the project
(means the <dependencies>).
And that also works.
But it seems that the maven-install-plugin and / or maven-deploy-plugin
overwrite the file-path of the WAR at runtime of the Maven build in memory.
I don't know why and I also don't know how to prevent it.
Best regards,
Gerrit
Best would be to have an example project on Github or alike where we can
take a look on it ...and help here...
Kind regards
Karl Heinz Marbaise
-----Ursprüngliche Nachricht-----
Von: Hohl, Gerrit <[email protected]>
Gesendet: Donnerstag, 12. November 2020 13:33
An: Maven Users List ([email protected]) <[email protected]>
Betreff: Creating JAR file in WAR module leads to error in EAR creation
Hello everyone,
I have a project consisting of several modules, one being a WAR module and one
being an EAR module.
The EAR module has a dependency on the WAR module.
It turned out that I need the classes of that WAR module also as a JAR file for
our UI project.
So I added a install-file goal for the maven-install-plugin and a deploy-file
goal for the maven-deploy-plugin.
The WAR module build now creates the JAR file successfully and also deploys it.
But now my EAR module fails:
Failed to execute goal org.apache.maven.plugins:maven-ear-plugin:3.0.2:ear
(default-ear) on project XXX-ear: Cannot copy a directory:
C:\XXX\XXX-pom\XXX-web\target\classes; Did you package/install
XXX:XXX-web:war:1.0.18:compile? -> [Help 1]
I looked up the code of the maven-ear-plugin. It seems it the following line is
the problem:
https://github.com/apache/maven-ear-plugin/blob/b289e6c271d50172c871e528105dda81d6f702b8/src/main/java/org/apache/maven/plugins/ear/EarMojo.java#L424
For some reason the file attribute of the Artifact object seems to contain the
path to the classes directory if the JAR file is build.
If I uncomment the JAR file creation in the WAR module it seems it contains the
WAR file path.
Things get even more interesting: When I created the JAR file, but build the
WAR and the EAR independently (not by building the parent project), it works
perfectly.
Seems something overwrites that information (the path of the WAR) and that
information is kept also during the build step of the EAR file.
So I'm not sure what I'm doing wrong or how I can fix it.
Anyone faced a similar problem in the past?
Best regards,
Gerrit
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]