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
  - 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>
                <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>

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


-----Ursprüngliche Nachricht-----
Von: Hohl, Gerrit <g.h...@aurenz.de> 
Gesendet: Donnerstag, 12. November 2020 13:33
An: Maven Users List (users@maven.apache.org) <users@maven.apache.org>
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: users-unsubscr...@maven.apache.org
For additional commands, e-mail: users-h...@maven.apache.org

Reply via email to