相关疑难解决方法(0)

Maven2属性,指示父目录

我有一个多模块项目,像这样:

main-project/
    module1/
    module2/
        sub-module1/
        sub-module2/
        sub-module3/
        ...
    module3/
    module4/
    ...
Run Code Online (Sandbox Code Playgroud)

我需要在Maven2中定义一组属性(取决于我想要释放项目的环境).我不会使用<properties>因为有很多属性...因此,我使用Properties Maven2插件.

属性文件位于main-project/目录中.如何在主pom.xml中设置正确的目录,以便为任何子项指定在哪里找到属性文件?

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>properties-maven-plugin</artifactId>
    <version>1.0-alpha-1</version>
    <executions>
        <execution>
            <phase>initialize</phase>
            <goals>
                <goal>read-project-properties</goal>
            </goals>
            <configuration>
                <files>
                    <file>???/env_${env}.properties</file>
                </files>
            </configuration>
        </execution>
    </executions>
</plugin>
Run Code Online (Sandbox Code Playgroud)

如果我只设置<file>env_${env}.properties</file>,那么当Maven2编译第一个模块时,它将找不到该main-project/env_dev.properties文件.如果我设置<file>../env_${env}.properties</file>,那么将在父级别或任何子模块级别引发错误...

maven-2 properties

98
推荐指数
8
解决办法
14万
查看次数

从Maven中的POM文件读取属性文件

为什么这不起作用?如何从属性文件中选择版本号.

在pom.xml中读取属性

<project>
  <build>
    <plugins>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>properties-maven-plugin</artifactId>
        <version>1.0</version>
        <executions>
          <execution>
            <phase>initialize</phase>
            <goals>
              <goal>read-project-properties</goal>
            </goals>
          </execution>
          <configuration>
            <files>
              <file>dev.properties</file>
            </files>
          </configuration>
        </executions>
      </plugin>
    </plugins>
  </build>
</project>
Run Code Online (Sandbox Code Playgroud)

在dev.properties中

org.aspectj.aspectjrt.version = 1.6.11

pom.xml中的依赖关系

        <dependency>
            <groupId>org.aspectj</groupId>
            <artifactId>aspectjrt</artifactId>
            <version>${org.aspectj.aspectjrt.version}</version>
        </dependency>
Run Code Online (Sandbox Code Playgroud)

错误:依赖项必须是有效版本

pom.xml maven

20
推荐指数
1
解决办法
3万
查看次数

如何在Maven2模块之间共享过滤器文件?

我有一个多模块项目,我想定义一个将属性应用于所有子模块的过滤器文件.例如,我想有以下结构:

parent
- filter.properties
- module1
    - resource1
- module2
   - resource2

这样,当我构建父级时,它会在构建子模块时将过滤器应用于resource1和resource2.

如果我创建上面的结构并在父POM中定义过滤器,则构建失败,因为它期望在每个子模块中定义过滤器...是否有一种简单的方法可以忽略我?

maven-2

6
推荐指数
1
解决办法
3884
查看次数

加载属性文件Maven时出错

当我尝试从pom.xml加载过滤器文件时,我从eclipse标记中得到此错误.它会显示以下信息.

 Error loading property file 'src/main/filters/filter.properties' (org.apache.maven.plugins:maven-resources-plugin:2.6:resources:default-resources:process-resources)
Run Code Online (Sandbox Code Playgroud)

pom.xml中:

 <execution>
        <id>default-resources</id>
            <phase>process-resources</phase>
        <goals>
            <goal>resources</goal>
        </goals>
        <configuration>
            <resources>
                <resource>
                    <directory>src/main/resources</directory>
                    <filtering>true</filtering>
                </resource>
            </resources>
            <filters>
                <filter>src/main/filters/filter.properties</filter>
            </filters>
        </configuration>
    </execution>
Run Code Online (Sandbox Code Playgroud)

那是一个bug吗?

java maven maven-resources-plugin

3
推荐指数
1
解决办法
9384
查看次数