我们的项目使用Log4J,通过log4j.properties文件配置.我们有多个生产服务器,可以记录到不同的日志文件,以便区分日志.所以节点1的log4j.properties如下所示:
...
log4j.appender.Application.File=D:/logs/application_1.log
...
log4j.appender.tx_info.File=D:/logs/tx_info_1.log
...
Run Code Online (Sandbox Code Playgroud)
而节点2的log4j.properties看起来像
...
log4j.appender.Application.File=D:/logs/application_2.log
...
log4j.appender.tx_info.File=D:/logs/tx_info_2.log
...
Run Code Online (Sandbox Code Playgroud)
我们已经使用Maven配置文件生成我们的服务器配置.到目前为止,它包含几个不同的log4j.properties文件,这些文件仅在日志文件名中有所不同,如上所示.我想使用像这样的资源模板文件使用Maven生成这些文件:
...
log4j.appender.Application.File=${log.location}/application${log.file.postfix}.log
...
log4j.appender.tx_info.File=${log.location}/tx_info${log.file.postfix}.log
...
Run Code Online (Sandbox Code Playgroud)
使用不同的${log.file.postfix}值多次运行Maven很容易,每次都会生成一个不同的日志属性文件.但是,我想要为一个构建中的每个服务器生成一个不同的属性文件(名称/路径不同).我相信这可以做到,例如通过antrun插件,但我不熟悉.实现这一目标的最简单方法是什么?
我们有一个特殊的例程来将子文件夹中的文件分解为扩展,这些扩展将被复制并放入单个扩展文件中.对于这种特殊的方法,我想使用maven-antrun-plugin,通过dirset的顺序迭代和jar包装,我们需要库ant-contrib.
即将推出的插件配置失败并显示错误.我错误配置了什么?谢谢.
插件配置
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.6</version>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target>
<for param="extension">
<path>
<dirset dir="${basedir}/src/main/webapp/WEB-INF/resources/extensions/">
<include name="*" />
</dirset>
</path>
<sequential>
<basename property="extension.name" file="${extension}" />
<echo message="Creating JAR for extension '${extension.name}'." />
<jar destfile="${basedir}/target/extension-${extension.name}-1.0.0.jar">
<zipfileset dir="${extension}" prefix="WEB-INF/resources/extensions/${extension.name}/">
<include name="**/*" />
</zipfileset>
</jar>
</sequential>
</for>
</target>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>ant-contrib</groupId>
<artifactId>ant-contrib</artifactId>
<version>1.0b3</version>
<exclusions>
<exclusion>
<groupId>ant</groupId>
<artifactId>ant</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.ant</groupId>
<artifactId>ant-nodeps</artifactId>
<version>1.8.1</version>
</dependency>
</dependencies>
</plugin>
Run Code Online (Sandbox Code Playgroud)
错误
[ERROR] Failed to execute goal …Run Code Online (Sandbox Code Playgroud) 我正在尝试在maven构建中使用"if"ant任务.
我发现许多文章建议使用"ant-nodeps"依赖.最终所有这些技巧都不适用于maven3 + ant 1.8.1 + maven-antrun-plugin 1.6.
"出现了一个Ant BuildException:问题:如果创建任务或输入失败"
有什么帮助吗?
这是真正的代码(相反,它没有必要,但以防万一):
<profiles>
<profile>
<id>smtpConfigurationProfile</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.6</version>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<tasks>
<if>
<isset property="${smtpFile}"/>
<then>
<delete file="${project.build.outputDirectory}/smtp.properties"/>
<copy file="${smtpFile}"
tofile="${project.build.outputDirectory}/smtp.properties"/>
</then>
<elseif>
<isset property="${smtpProfile}"/>
<then>
<delete file="${project.build.outputDirectory}/smtp.properties"/>
<copy file="src/main/resources/${smtpProfile}.smtp.properties"
tofile="${project.build.outputDirectory}/smtp.properties"/>
</then>
<else>
<delete file="${project.build.outputDirectory}/smtp.properties"/>
<copy file="src/main/resources/production.smtp.properties"
tofile="${project.build.outputDirectory}/smtp.properties"/>
</else>
</elseif>
</if>
</tasks>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.apache.ant</groupId>
<artifactId>ant-nodeps</artifactId>
<version>1.8.1</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
</profile>
</profiles>
Run Code Online (Sandbox Code Playgroud)