将文件替换到由mvn package生成的WAR文件中。

huangapple 未分类评论43阅读模式
英文:

replacing file into WAR file which is generated by mvn package

问题

<plugin>
    <artifactId>maven-resources-plugin</artifactId>
    <version>3.0.2</version>
    <executions>
        <execution>
            <id>copy-resources</id>
            <phase>package</phase>
            <goals>
                <goal>copy-resources</goal>
            </goals>
            <configuration>
                <overwrite>true</overwrite>
                <outputDirectory>target/Project-xyz/classes/resources</outputDirectory>
                <resources>
                    <resource>
                        <directory>${basedir}/src/main/java/resources/customers</directory>
                        <filtering>true</filtering>
                    </resource>
                </resources>
            </configuration>
        </execution>
    </executions>
</plugin>
英文:

i have a maven project and i want when using clear package maven command to replace config file from source code and replace it with exciting one in the WAR.
i tried but the replacing only happens in extracted folder not WAR file
this is my pom.xml

            &lt;plugin&gt;
				&lt;artifactId&gt;maven-resources-plugin&lt;/artifactId&gt;
				&lt;version&gt;3.0.2&lt;/version&gt;
				&lt;executions&gt;
					&lt;execution&gt;
						&lt;id&gt;copy-resources&lt;/id&gt;
						&lt;phase&gt;package&lt;/phase&gt;
						&lt;goals&gt;
							&lt;goal&gt;copy-resources&lt;/goal&gt;
						&lt;/goals&gt;
						&lt;configuration&gt;
							&lt;overwrite&gt;true&lt;/overwrite&gt;
							&lt;outputDirectory&gt;target/Project-xyz/classes/resources&lt;/outputDirectory&gt;  
							&lt;resources&gt;
								&lt;resource&gt;
									&lt;directory&gt;${basedir}/src/main/java/resources/customers&lt;/directory&gt;
									&lt;filtering&gt;true&lt;/filtering&gt;
								&lt;/resource&gt;
							&lt;/resources&gt;
						&lt;/configuration&gt;
					&lt;/execution&gt;
				&lt;/executions&gt;
			&lt;/plugin&gt;

答案1

得分: 0

经过多次尝试,通过以下方式使其工作:

&gt; org.apache.maven.plugins

    &lt;plugin&gt;
        &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
        &lt;artifactId&gt;maven-war-plugin&lt;/artifactId&gt;
        &lt;executions&gt;
            &lt;execution&gt;
                &lt;id&gt;default-war&lt;/id&gt;
                &lt;configuration&gt;
                    &lt;webResources&gt;
                        &lt;resource&gt;
                            &lt;directory&gt;src/main/webapp/resources/customer1/css&lt;/directory&gt;
                            &lt;targetPath&gt;resources/css&lt;/targetPath&gt;
                        &lt;/resource&gt;
                    &lt;/webResources&gt;
                &lt;/configuration&gt;
            &lt;/execution&gt;
        &lt;/executions&gt;
    &lt;/plugin&gt;
英文:

after so many trials it worked by using

> org.apache.maven.plugins

&lt;plugin&gt;
    &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
    &lt;artifactId&gt;maven-war-plugin&lt;/artifactId&gt;
    &lt;executions&gt;
        &lt;execution&gt;
            &lt;id&gt;default-war&lt;/id&gt;
            &lt;configuration&gt;
                &lt;webResources&gt;
                    &lt;resource&gt;
                        &lt;directory&gt;src/main/webapp/resources/customer1/css&lt;/directory&gt;
                        &lt;targetPath&gt;resources/css&lt;/targetPath&gt;
                    &lt;/resource&gt;
                &lt;/webResources&gt;
            &lt;/configuration&gt;
        &lt;/execution&gt;
    &lt;/executions&gt;
&lt;/plugin&gt;

huangapple
  • 本文由 发表于 2020年4月6日 20:10:22
  • 转载请务必保留本文链接:https://java.coder-hub.com/61059540.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定