使用配置文件时未设置 Maven 属性

标签 maven maven-3

过滤通过 maven package -Pexplode不管用。 “${ds.xml}”未被替换为“openmind-ds.xml”。值“openmind-ds.xml”和键“ds.xml”在 filter.properties 中。还有 ${as.deploy}。
错误信息

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-antrun-plugin:1.3:run (package) on project openmind-ear: An Ant BuildException has occured: Warning: Could not find file /home/localhost/workspaceOM/openmind/openmind-ear/target/${ds.xml} to copy. -> [Help 1]


模式调试
[INFO] Executing tasks
[DEBUG] getProperty(ns=null, name=ant.reuse.loader, user=false)
[antlib:org.apache.tools.ant] Could not load definitions from resource org/apache/tools/ant/antlib.xml. It could not be found.
[DEBUG] getProperty(ns=null, name=as.deploy, user=false)
Property "as.deploy" has not been set
Setting project property: deploy-path -> ${as.deploy}/openmind-ear.ear
[DEBUG] getProperty(ns=null, name=deploy-path, user=false)
     [echo] Exploding to ${as.deploy}/openmind-ear.ear
[DEBUG] getProperty(ns=null, name=deploy-path, user=false)
   [delete] Directory /home/localhost/workspaceOM/openmind/openmind-ear/${as.deploy}/openmind-ear.ear cannot be removed using the file attribute.  Use dir instead.
[DEBUG] getProperty(ns=null, name=deploy-path, user=false)
    [mkdir] Skipping /home/localhost/workspaceOM/openmind/openmind-ear/${as.deploy}/openmind-ear.ear because it already exists.
[DEBUG] getProperty(ns=null, name=deploy-path, user=false)
     [sync] PASS#1: Copying files to /home/argonist/om-umgebung/workspaceOM/openmind/openmind-ear/${as.deploy}/openmind-ear.ear
耳朵项目中的 pom.xml
<?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>de.openmind</groupId>
    <artifactId>openmind</artifactId>
    <version>1.0-SNAPSHOT</version>
    <relativePath>../pom.xml</relativePath>
  </parent>

  <artifactId>openmind-ear</artifactId>
  <packaging>ear</packaging>
  <name>${project.artifactId} : ${project.version} EAR</name>

  <profiles>
    <profile>
      <id>env-dev</id>
      <properties>
        <env>dev</env>
      </properties>
    </profile>

    <profile>
      <id>env-prod</id>
      <properties>
        <env>prod</env>
      </properties>
    </profile>

    <profile>
      <id>explode</id>
      <build>
        <plugins>
          <plugin>
            <artifactId>maven-antrun-plugin</artifactId>
            <executions>
              <execution>
                <id>package</id>
                <phase>package</phase>
                <configuration>
                  <tasks>
                    <property name="deploy-path" value="${as.deploy}/${app.context}-ear.ear" />
                    <echo>Exploding to ${deploy-path}</echo>
                    <delete file="${deploy-path}" quiet="true" />
                    <mkdir dir="${deploy-path}" />
                    <sync todir="${deploy-path}" verbose="true">
                      <fileset
                        dir="${project.build.directory}/${project.build.finalName}" />
                    </sync>
                    <copy todir="${as.deploy}" file="${project.build.directory}/${ds.xml}"
                      verbose="true" />
                  </tasks>
                </configuration>
                <goals>
                  <goal>run</goal>
                </goals>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>
    </profile>

    <profile>
      <id>unexplode</id>
      <build>
        <plugins>
          <plugin>
            <artifactId>maven-antrun-plugin</artifactId>
            <executions>
              <execution>
                <id>clean</id>
                <phase>clean</phase>
                <configuration>
                  <tasks>
                    <property name="deploy-path" value="${as.deploy}/${app.context}-ear.ear" />
                    <echo>Unexploding: ${deploy-path}</echo>
                    <delete file="${deploy-path}" quiet="true" />
                    <delete dir="${deploy-path}" quiet="true" />
                    <delete file="${as.deploy}/${ds.xml}" quiet="true" />
                  </tasks>
                </configuration>
                <goals>
                  <goal>run</goal>
                </goals>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>
    </profile>
  </profiles>

  <dependencies>
    .....
  </dependencies>
  <build>
    <finalName>${app.context}-ear</finalName>
    <filters>
      <filter>../src/main/filters/filter-${env}.properties</filter>
    </filters>
    <plugins>
      <plugin>
        <artifactId>maven-ear-plugin</artifactId>
        <configuration>
          <defaultJavaBundleDir>lib/</defaultJavaBundleDir>
          <version>6</version>
          <archive>
            <manifestEntries>
              <Build-Date>${timestamp}</Build-Date>
              <Build-Revision>${buildNumber}</Build-Revision>
              <Mode>${env}</Mode>
            </manifestEntries>
          </archive>
          <modules>
            <jarModule>
              <groupId>org.jboss.el</groupId>
              <artifactId>jboss-el</artifactId>
              <includeInApplicationXml>false</includeInApplicationXml>
              <bundleDir>lib</bundleDir>
            </jarModule>
            <jarModule>
              <groupId>${project.groupId}</groupId>
              <artifactId>${app.context}-datamodel</artifactId>
              <includeInApplicationXml>false</includeInApplicationXml>
              <bundleDir>lib</bundleDir>
            </jarModule>
            <webModule>
              <groupId>${project.groupId}</groupId>
              <artifactId>${app.context}-war</artifactId>
              <contextRoot>/${app.web.context}</contextRoot>
              <unpack>${app.unpack.modules}</unpack>
              <bundleFileName>${app.context}-war.war</bundleFileName>
            </webModule>

            <ejbModule>
              <groupId>${project.groupId}</groupId>
              <artifactId>${app.context}-bootstrap</artifactId>
              <excluded>${exclude.bootstrap}</excluded>
              <bundleFileName>${app.context}-bootstrap.jar</bundleFileName>
              <unpack>${app.unpack.modules}</unpack>
            </ejbModule>

            <ejbModule>
              <groupId>${project.groupId}</groupId>
              <artifactId>${app.context}-ejb</artifactId>
              <bundleFileName>${app.context}-ejb.jar</bundleFileName>
              <unpack>${app.unpack.modules}</unpack>
            </ejbModule>


            <ejbModule>
              <groupId>org.jboss.seam</groupId>
              <artifactId>jboss-seam</artifactId>
            </ejbModule>

          </modules>
        </configuration>
      </plugin>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>properties-maven-plugin</artifactId>
        <executions>
          <execution>
            <configuration>
              <files>
                <file>${basedir}/../src/main/filters/filter-${env}.properties</file>
              </files>
            </configuration>
          </execution>
          <execution>
            <!-- Properties needed by unexplode profile -->
            <id>pre-clean</id>
            <phase>pre-clean</phase>
            <goals>
              <goal>read-project-properties</goal>
            </goals>
            <configuration>
              <files>
                <file>${basedir}/../src/main/filters/filter-${env}.properties</file>
              </files>
            </configuration>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-resources-plugin</artifactId>
        <version>2.6</version>
        <configuration>
          <!-- <outputDirectory>${env.JBOSS_HOME}/server/default/deploy</outputDirectory> -->
          <outputDirectory>${project.build.directory}</outputDirectory>
          <resources>
            <resource>
              <directory>src/main/resources</directory>
              <filtering>true</filtering>
              <includes>
                <include>${ds.xml}</include>
              </includes>
            </resource>
          </resources>
        </configuration>
        <executions>
          <execution>
            <id>copy-app-ds-xml</id>
            <goals>
              <goal>copy-resources</goal>
            </goals>
          </execution>
        </executions>
        <!-- <execution> <id>copy-mysql-driver</id> <phase>install</phase> <goals> 
          <goal>copy-resources</goal> </goals> <configuration> <outputDirectory>${env.JBOSS_HOME}/server/default/lib</outputDirectory> 
          <resources> <resource> <directory>${settings.localRepository}/mysql/mysql-connector-java/5.1.6</directory> 
          <includes> <include>mysql-connector-java-5.1.6.jar</include> </includes> 
          </resource> </resources> </configuration> </execution> -->
      </plugin>
    </plugins>
    <resources>
      <resource>
        <directory>src/main/resources</directory>
        <filtering>true</filtering>
      </resource>
    </resources>
  </build>
</project>

最佳答案

您的过滤器属性依赖于 ${env}范围:

<filter>../src/main/filters/filter-${env}.properties</filter>

此参数在您的“爆炸”配置文件中没有值(value)。所以 Maven 必须寻找:
../src/main/filters/filter-.properties

我怀疑你希望它是 filter.properties而不是 filter-.properties .

关于使用配置文件时未设置 Maven 属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13093425/

相关文章:

java - 下载源代码后,为什么我会在堆栈跟踪中看到未知源?

java - 以编程方式下载 Maven 依赖项

java - 可以在maven发布插件准备中使用profile吗?

jboss as 7 + Jersey - ClassNotFound com.sun.jersey.server.impl.container.servlet.Include

maven - 如何在 maven pom.xml 文件中拥有另一个父依赖项以及 Spring Boot 父项?

Spring Boot 2.2.1 在 Build 时创建两个 jar

maven - 开始 Spring 3 和错误执行应用程序

Java JDBC MySQL 查询失败

maven - 安装具有 3rd-party non-mvn jar 依赖项的 3rd-party non-mvn jar

android - 使用 Gradle 在 Android Studio 中从编译中排除 .jar