Maven: How to add files to the root inside an EAR

2019-07-07 06:11发布

I need to add 2 XML files inside an EAR generated with maven-ear-plugin.

Unfortunately, I haven't seen a way to add an arbitrary file to an EAR; the documentation of the plugin which reads "The EAR plugin supports the following artifacts: ejb, war, jar, ejb-client, rar, ejb3, par, sar, wsr and har". There's nothing for adding a regular file.

org.apache.maven.plugins maven-ear-plugin 2.3.1 foo foo 1.4 lib ${parent.groupId} foo-web /foo org.richfaces.framework richfaces-api commons-lang commons-lang

Many thanks in advance.

3条回答
爱情/是我丢掉的垃圾
2楼-- · 2019-07-07 06:40

In maven-ear-plugin 2.4.2 you can use config elements earSourceDirectory, earSourceExcludes and earSourceIncludes to declare extra files to include in the EAR.

By default you simply place those files to ${basedir}/src/main/application folder.

查看更多
时光不老,我们不散
3楼-- · 2019-07-07 06:44

I had the same issue. I had the ejb.properties file under ejbs/src/main/resources and had used earSourceDirectory and earSourceIncludes to pull the file from the ejbs directory to the ear. However, it did not reliably put it in the lib directory. The EJB does not find it in .; it looks for it in the lib directory.

To fix this, I created the src/main/application/lib directory and created a link to the ejb.properties file. I then removed the earSourceDirectory and Includes properties. Now when I do a mvn clean package, it automatically pulls the properties file and puts it in the lib directory of the ear.

查看更多
Evening l夕情丶
4楼-- · 2019-07-07 07:04

Sorry to be late for @wishihadabettername but I had same issue recently, more I couldn't move the files to include because they were in other folder then earSourceDirectory. I read maven-ear-plugin ear:ear documentation and thought about how to move my release folder on the root of ear.

Binds by default to the lifecycle phase: package.

and

workDirectory - Directory that resources are copied to during the build.

Default value is: ${project.build.directory}/${project.build.finalName}.

Then my submodule pom.xml looks like this:

<plugin>
    <artifactId>maven-resources-plugin</artifactId>
    <executions>
        <execution>
            <id>copy-resources</id>
            <phase>prepare-package</phase> <!-- before package phase -->
            <goals>
                <goal>copy-resources</goal>
            </goals>
            <configuration>
                <!-- Work Directory of Ear plugin -->
                <outputDirectory>${project.build.directory}/${project.build.finalName}</outputDirectory> 
                <resources>
                    <resource>
                        <!-- my resource folder -->
                        <directory>release</directory>
                        <filtering>true</filtering>
                    </resource>
                </resources>
            </configuration>
        </execution>
    </executions>
</plugin>

Hope it help people from now on

查看更多
登录 后发表回答