Maven: How to add files to the root inside an EAR with maven-ear-plugin?

 ̄綄美尐妖づ 提交于 2019-12-10 18:02:54

问题


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.


回答1:


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.




回答2:


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.




回答3:


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



来源:https://stackoverflow.com/questions/3944959/maven-how-to-add-files-to-the-root-inside-an-ear-with-maven-ear-plugin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!