Java 使用M2E和外部属性文件进行Maven ressource筛选
我有一个maven projekt,它读取一个外部属性文件来过滤资源。这在使用mvn包时很好,但从JUnit测试开始,只有在pom本身而不是属性文件中声明属性时,这才有效,所以我认为插件配置是问题所在。我在我的pom中得到了这个:Java 使用M2E和外部属性文件进行Maven ressource筛选,java,maven,m2eclipse,Java,Maven,M2eclipse,我有一个maven projekt,它读取一个外部属性文件来过滤资源。这在使用mvn包时很好,但从JUnit测试开始,只有在pom本身而不是属性文件中声明属性时,这才有效,所以我认为插件配置是问题所在。我在我的pom中得到了这个: <plugin> <groupId>org.eclipse.m2e</groupId> <artifactId>lifecycle-mapping</artifactId> <v
<plugin>
<groupId>org.eclipse.m2e</groupId>
<artifactId>lifecycle-mapping</artifactId>
<version>1.0.0</version>
<configuration>
<lifecycleMappingMetadata>
<pluginExecutions>
<pluginExecution>
<pluginExecutionFilter>
<groupId>org.codehaus.mojo</groupId>
<artifactId>properties-maven-plugin</artifactId>
<versionRange>[1.0-alpha-2,)</versionRange>
<goals>
<goal>read-project-properties</goal>
</goals>
</pluginExecutionFilter>
<action>
<execute />
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>properties-maven-plugin</artifactId>
<version>1.0-alpha-2</version>
<executions>
<execution>
<phase>initialize</phase>
<goals>
<goal>read-project-properties</goal>
</goals>
<configuration>
<files>
<file>${build.properties.file}</file>
</files>
</configuration>
</execution>
</executions>
</plugin>
org.eclipse.m2e
生命周期映射
1.0.0
org.codehaus.mojo
属性maven插件
[1.0-α-2,]
读取项目属性
org.codehaus.mojo
属性maven插件
1.0-α-2
初始化
读取项目属性
${build.properties.file}
在Eclipse中,生命周期标记为红色
编辑:
m2e部分需要被插件管理包围,然后错误就消失了。我可以看到目标现在正在Maven首选项下执行
但是,如果我使用这个插件,在执行eclipse的单元测试时,它实际上仍然没有过滤资源。因此,它仍然是开放的;)我不太清楚,当您运行
mvn package
时,它工作得很好,因为包将运行测试用例。
所以我的假设是,通过跳过测试,包可能正在正常运行。
为了将属性传递给测试用例,您可以使用surefire插件,如下所示:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.4.2</version>
<configuration>
<systemProperties>
<property>
<name>filePath</name>
<value>/path/to/the/file</value>
</property>
</systemProperties>
</configuration>
</plugin>
org.apache.maven.plugins
maven surefire插件
2.4.2
文件路径
/路径/到/文件
这将选择属性并传递给测试用例。尝试将lifecycle mapping插件包含在如下所示的块中。我已经成功地使用了其他没有Eclipse连接器的Maven插件
<profile>
<!-- Contents of this profile are only needed to make this project work in
Eclipse. Once all appropriate m2e connectors are available, this can be
removed -->
<id>m2e</id>
<activation>
<property>
<name>m2e.version</name>
</property>
</activation>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.eclipse.m2e</groupId>
<artifactId>lifecycle-mapping</artifactId>
<!-- other plugin config here ->
</plugin>
</plugins>
</pluginManagement>
</build>
</profile>
m2e
可能有点不清楚:如果我使用Maven来构建/测试,测试运行得很好,但不是来自IDE谢谢你的答案,但我真的不知道该怎么做;)。我复制了…部分,现在我得到了一个NPE,而Maven在eclipse中更新项目。只需复制粘贴你的东西,什么都不会发生(我认为这是正确的;))你能给我提供更多关于这个的信息吗?啊,好吧,我弄错了…这实际上使它变绿了,但在生命周期中,它仍然不工作;)
<execute>
<runOnIncremental>true</runOnIncremental>
<runOnConfiguration>true</runOnConfiguration>
</execute>