如何将文件添加到 EAR 元 INF 文件夹 - Maven

2022-09-02 20:36:42

我想将文件从我的>移动到>文件夹。我尝试使用插件,但它只是将文件从>复制到文件夹中。但是在内置文件中不可用startup MBEAN(startup-client-service.xml)EJBMETA-INFEARMETA-INFmaven-resources-pluginEJBMETA-INFTargetearearstartup-client-service.xmlMETA-INF

如何将启动文件移动到META-INF到耳朵>META-INF?

这是耳朵的pom文件。

<?xml version="1.0" encoding="UTF-8"?>
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
    <groupId>com.testapp</groupId>
    <artifactId>my-client-parent</artifactId>
    <version>0.0.1-SNAPSHOT</version>
</parent>

<name>Test app EAR</name>
<artifactId>my-client-ear</artifactId>

<packaging>ear</packaging>

<dependencies>

    <dependency>
        <groupId>com.testapp</groupId>
        <artifactId>my-client-ejb</artifactId>
        <version>0.0.1-SNAPSHOT</version>
        <type>ejb</type>
    </dependency>
</dependencies>
<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-ear-plugin</artifactId>
            <version>2.8</version>
            <configuration>
                <defaultLibBundleDir>lib</defaultLibBundleDir>
                <modules>
                </modules>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-resources-plugin</artifactId>
            <version>2.6</version>
            <executions>
                <execution>
                    <id>copy-resources</id>
                    <phase>validate</phase>
                    <goals>
                        <goal>copy-resources</goal>
                    </goals>
                    <configuration>
                        <outputDirectory>META-INF</outputDirectory>
                        <resources>
                            <resource>
                                <directory>${project.parent.basedir}/ejb/src/main/resources/META-INF</directory>
                                <filtering>true</filtering>
                            </resource>
                        </resources>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
    <pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.eclipse.m2e</groupId>
                <artifactId>lifecycle-mapping</artifactId>
                <version>1.0.0</version>
                <configuration>
                    <lifecycleMappingMetadata>
                        <pluginExecutions>
                            <pluginExecution>
                                <pluginExecutionFilter>
                                    <groupId>
                                        org.apache.maven.plugins
                                    </groupId>
                                    <artifactId>
                                        maven-ear-plugin
                                    </artifactId>
                                    <versionRange>
                                        [2.8,)
                                    </versionRange>
                                    <goals>
                                        <goal>
                                            generate-application-xml
                                        </goal>                                         
                                    </goals>
                                </pluginExecutionFilter>
                                <action>
                                    <ignore></ignore>
                                </action>
                            </pluginExecution>
                        </pluginExecutions>
                    </lifecycleMappingMetadata>
                </configuration>
            </plugin>
        </plugins>
    </pluginManagement>
</build>

<profiles>
    <profile>
        <id>copy_bundle</id>
        <properties>
            <install.dir>${jboss.dir}\server\default\deploy</install.dir>
        </properties>
        <build>
            <plugins>
                <plugin>
                    <artifactId>maven-antrun-plugin</artifactId>
                    <executions>
                        <execution>
                            <id>Copying bundle to destination folder</id>
                            <phase>package</phase>
                            <goals>
                                <goal>run</goal>
                            </goals>
                            <configuration>
                                <tasks>
                                    <copy
                                        file="${project.build.directory}/${project.build.finalName}.${project.packaging}"
                                        overwrite="true" todir="${install.dir}" />
                                </tasks>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </build>
    </profile>
</profiles>

以下是项目工作区屏幕抓取

Here is the project structure


答案 1

正确的方法是将文件添加到 而不是 。您还可以指定其他 earSourceDirectory 配置。src/main/applicationsrc/main/resources


答案 2

我建议您在准备包阶段使用Maven资源插件将文件复制到${build.directory}/${project.artifactId}-${project.version}/META-INF文件夹,该文件夹是压缩最终EAR的文件夹。阶段准备包就在 EAR 压缩之前。


推荐