1

I am trying to read the properties from a property file into my parent pom.xml. From there I need to put the read properties to the variables defined in my html file.

Code for including properties file :

  <plugins>
            <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>properties-maven-plugin</artifactId>
            <executions>
               <!-- Associate the read-project-properties goal with the initialize phase, to read the properties file. -->
              <execution>
                <phase>initialize</phase>
                <goals>
                  <goal>read-project-properties</goal>
                </goals>
                <configuration>
                  <files>
                    <file>${basedir}/build.${build.env}.properties</file>
                  </files>
                </configuration>
              </execution>
            </executions>
          </plugin>


            <!-- Maven War file generator plugin -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <configuration>
                    <webResources>
                        <resource>
                            <directory>${basedir}/src/main/java</directory>
                            <targetPath>WEB-INF/classes</targetPath>
                            <includes>
                                <include>**/*.properties</include>
                                <filtering>false</filtering>
                                <include>**/*.xml</include>
                                <filtering>false</filtering>
                                <include>**/*.css</include>
                                <filtering>false</filtering>
                                <include>**/*.html</include>
                                <filtering>true</filtering>
                            </includes>
                        </resource>
                    </webResources>
                </configuration>
                <version>2.3</version>
            </plugin>

            <!-- Maven compiler plugin -->
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                </configuration>
                <version>2.3</version>
            </plugin>
           </plugins>

I was using ant before and there I was using filterset tag to apply these filters like

code in build.xml:

   <filterset>
            <filter token="HOSTNAME_PREFIX" value="${hostname.prefix}"/>
            <filter token="MIN_SUFFIX" value="${min.suffix}"/>
            <filter token="APP_VERSION" value="${build.app.version}"/>
        </filterset>

but I dont know how to achieve the same thing using maven.

the code to be replaced in index.html is :

<link rel="shortcut icon" href="@HOSTNAME_PREFIX@appimages/app-logo.ico" type="image/png"/>
<link rel="stylesheet" href="@HOSTNAME_PREFIX@css/jquery.mobile-1.2.0@MIN_SUFFIX@.css" />
4

1 回答 1

0

您需要在 war 插件配置中使用多个资源元素来实现此目的,一个用于您要过滤的资源,一个用于您不想过滤的资源。

<webResources>
    <resource>
        <directory>${basedir}/src/main/java</directory>
        <targetPath>WEB-INF/classes</targetPath>
        <filtering>false</filtering>
        <includes>
            <include>**/*.properties</include>
            <include>**/*.xml</include>
            <include>**/*.css</include>
        </includes>
    </resource>
    <resource>
        <directory>${basedir}/src/main/java</directory>
        <targetPath>WEB-INF/classes</targetPath>
        <filtering>true</filtering>
        <includes>
            <include>**/*.html</include>
        </includes>
    </resource>
</webResources>

另外,我建议不要将您的资源放入/src/main/java; 该目录用于 Java 文件,而资源则不是。

于 2013-06-19T13:39:12.540 回答