Java 如何将文件添加到 EAR META-INF 文件夹 - Maven
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23026183/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to add a file to EAR META-INF folder - Maven
提问by user2771655
I want to move a startup MBEAN
file (startup-client-service.xml)
from my EJB
>META-INF
, to EAR
> META-INF
folder. I tried with the maven-resources-plugin
plugin but it just copy the file from EJB
>META-INF
to Target
in ear
folder. But in built ear
the startup-client-service.xml
file is not available in META-INF
我想将startup MBEAN
文件(startup-client-service.xml)
从EJB
>移动META-INF
到EAR
>META-INF
文件夹。我试着用了maven-resources-plugin
插件,但它只是将文件从复制EJB
>META-INF
到Target
的ear
文件夹中。但在内置ear
的startup-client-service.xml
文件不在可用META-INF
How can I move my startup file to META-INF into ear > META-INF ?
如何将我的启动文件移动到 META-INF 到 ear > META-INF 中?
This is the pom file of ear.
这是ear的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>
Below is the project workspace screen grab
下面是项目工作区屏幕截图
回答by mekondelta
I suggest you use the Maven resources plugin at the prepare-package phase to copy the file to the ${build.directory}/${project.artifactId}-${project.version}/META-INF folder which is the folder where the final EAR is zipped from. The phase prepare-package is just before the EAR is zipped up.
我建议您在准备包阶段使用 Maven 资源插件将文件复制到 ${build.directory}/${project.artifactId}-${project.version}/META-INF 文件夹,这是其中的文件夹最终的 EAR 是从拉链中提取出来的。准备包阶段就在 EAR 被压缩之前。
回答by Constantino Cronemberger
The correct way is to add files to src/main/application
instead of src/main/resources
.
You can also specify a different earSourceDirectoryconfiguration.
正确的方法是将文件添加到src/main/application
而不是src/main/resources
. 您还可以指定不同的earSourceDirectory配置。
回答by otonglet
- Use the phase "process-resources" with the goal "resources" (or mekondelta proposition of using "prepare-package")
- Set the output directory to ${basedir}/target/${project.artifactId}-${project.version}
- 使用阶段“处理资源”和目标“资源”(或使用“准备包”的 mekondelta 命题)
- 将输出目录设置为 ${basedir}/target/${project.artifactId}-${project.version}
Here's a complete example
这是一个完整的例子
<build>
<plugins>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<executions>
<execution>
<id>copy-resources</id>
<phase>process-resources</phase>
<goals>
<goal>resources</goal>
</goals>
<configuration>
<outputDirectory>
${basedir}/target/${project.artifactId}-${project.version}
</outputDirectory>
<resources>
<resource>
<directory>${project.parent.basedir}/ejb/src/main/resources/META-INF</directory>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
...
回答by Ceddaerrix
Based on mekondelta's suggestion, I have succeeded adding files into the EAR META-INF using the maven-assembly-plugin. In my case, the files are **.properties* kept under "src/main/resources/META-INF" in my project.
根据 mekondelta 的建议,我已成功使用maven-assembly-plugin将文件添加到 EAR META-INF 中。就我而言,文件是 **.properties* 保存在我的项目中的“src/main/resources/META-INF”下。
In my POM.XML has the following build configuration:
在我的 POM.XML 中有以下构建配置:
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-ear-plugin</artifactId>
<version>2.10.1</version>
<configuration>
<version>5</version>
<defaultLibBundleDir>lib/</defaultLibBundleDir>
<skinnyWars>true</skinnyWars>
<jboss>
<version>5</version>
<loader-repository>mcsa:loader=my-application</loader-repository>
<loader-repository-config>java2ParentDelegation=false</loader-repository-config>
<data-sources>
<data-source>my-ds.xml</data-source>
</data-sources>
</jboss>
</configuration>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<id>make-metainf</id>
<!--<phase>initialize</phase>-->
<phase>generate-resources</phase>
<configuration>
<!--<finalName>.</finalName>-->
<finalName>${project.artifactId}-${project.version}</finalName>
<appendAssemblyId>false</appendAssemblyId>
<descriptors>
<descriptor>src/main/resources/metainf-assembly.xml</descriptor>
</descriptors>
</configuration>
<goals>
<goal>directory</goal>
</goals>
</execution>
</executions>
</plugin>
</build>
The metainf-assembly.xmlis as follow:
该metainf-assembly.xml情况如下:
<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2
http://maven.apache.org/xsd/assembly-1.1.2.xsd">
<id>meta-data</id>
<includeBaseDirectory>false</includeBaseDirectory>
<formats>
<format>dir</format>
</formats>
<fileSets>
<fileSet>
<directory>${project.build.directory}/filtered-resources/META-INF/</directory>
<outputDirectory>META-INF</outputDirectory>
<includes>
<include>*.properties</include>
</includes>
</fileSet>
</fileSets>
回答by Eliran_Mesika
I managed to do it using maven-resources-plugin
我设法使用 maven-resources-plugin 做到了
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.1.0</version>
<executions>
<execution>
<id>copy-resources</id>
<phase>validate</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${basedir}/target/${env.APPLICATION_NAME}/META-INF/</outputDirectory>
<resources>
<resource>
<directory>src/main/application/</directory>
<filtering>true</filtering>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
Note:resource need to be located in src\main\application\META-INF\weblogic-application.xml
注意:资源需要位于 src\main\application\META-INF\weblogic-application.xml
回答by Angel O'Sphere
The simplest way, at least if it is not an EAR (did not try that), is to simply have a META-INF directory with the wanted files in ./src/main/resources. Of course that does not solve your problem is the file is generated to a different place.
最简单的方法,至少如果它不是 EAR(没有尝试过),就是简单地在 ./src/main/resources 中有一个包含所需文件的 META-INF 目录。当然,不能解决您的问题是文件生成到不同的地方。