Java 刷新不';在Eclipse上创建与Ant的战争之前,我无法工作
在Eclipse上,我使用ant创建war文件 问题是war文件中没有包含正确的Java 刷新不';在Eclipse上创建与Ant的战争之前,我无法工作,java,eclipse,ant,file-copying,Java,Eclipse,Ant,File Copying,在Eclipse上,我使用ant创建war文件 问题是war文件中没有包含正确的mypropfile.properties。 文件已正确复制,但如果我使用也会包含旧文件。我必须手动刷新项目 对于Ant,我使用“在与工作区相同的JRE中运行”选项 Ant不关心Eclipse是否刷新了文件eclipse.refreshLocal仅与IDE内部的编辑器和编译器相关 运行Antbuild.xml时,Ant将real目标中有问题的文件复制到源文件夹中,然后compile将其复制到${build}/clas
mypropfile.properties
。
文件已正确复制,但如果我使用
也会包含旧文件。我必须手动刷新项目
对于Ant,我使用“在与工作区相同的JRE中运行”选项
Ant不关心Eclipse是否刷新了文件<代码>eclipse.refreshLocal仅与IDE内部的编辑器和编译器相关 运行Ant
build.xml
时,Ant将real
目标中有问题的文件复制到源文件夹中,然后compile
将其复制到${build}/classes
(至少它应该这样做)。因此,在创建WAR之前,您必须确保编译
步骤已完成其工作(即查看每个文件,确保每个副本中都有可见的更改)
我担心的是,您使用不同的方式访问类
:
${build}/classes
${build.classes}
${basedir}/./build/classes
mypropfile.properties
的文件,那么Java资源加载可以找到任何一个版本
这个问题和其他问题使我使用不同的解决方案来配置WAR文件:我传递一个带有配置文件绝对路径的系统属性。这样,配置更改时WAR文件不会更改,我可以完全控制加载哪个配置文件。哪个版本的Ant?您如何知道它不是正确的文件?目标
clean
是错误的。我已经更正了。我必须将文件复制到源文件夹中,因为需要根据war类型在该文件中添加不同的未注释部分。我不能为此使用两个不同的文件。这就是war-real
和war-real2
的用途吗?这两个目标具有不同的倾向性。基本上,它们复制相同的文件,但未注释不同的部分(realprop.properties或real2prop.properties)。最终,文件名为mypropfile.properties
将属性传递给WAR,告诉它您想要的类型如何?将其视为mypropfile.properties
文件中所有键的前缀。这样,您就不必对任何内容进行注释/取消注释。我考虑过这一点,但由于不同的原因(取决于deploy env),这是不可能的。我想找到一种方法来复制该文件,并将其正确地包含在战争中。
<?xml version="1.0" encoding="UTF-8"?>
<project name="MyProject" basedir=".">
<description>
My Project
</description>
<property name="workspace.dir" value="${basedir}/../../"/>
<property name="src" value="${basedir}/../src"/>
<property name="build" value="${basedir}/../build"/>
<property name="build.classes" value="${basedir}/../build/classes"/>
<property name="lib.dir" value="${basedir}/WEB-INF/lib"/>
<property name="web.dir" value="${basedir}/WEB-INF"/>
<property environment="env"/>
<property name="real.dir" value="${basedir}/real"/>
<property name="real2.dir" value="${basedir}/real2"/>
<path id="classpath.server">
<fileset dir="${env.CATALINA_HOME}/lib" includes="*.jar"/>
<pathelement path="${build.classes}"/>
</path>
<path id="classpath.app">
<fileset dir="${lib.dir}" includes="*.jar"/>
</path>
<target name="refreshResource" if="eclipse.refreshLocal">
<eclipse.refreshLocal resource="projectdir" depth="infinite"/>
</target>
<target name="clean">
<delete dir="${build}/classes"/>
<delete dir="${build}"/>
</target>
<target name="init" depends="clean, refreshResource">
<tstamp/>
<mkdir dir="${build}"/>
<mkdir dir="${build}/classes"/>
</target>
<target name="compile" depends="init">
<javac encoding="UTF8" srcdir="${src}" destdir="${build}/classes" includeantruntime="false">
<compilerarg value="-Xlint:unchecked"/>
<classpath>
<path refid="classpath.server.bin"/>
</classpath>
<classpath>
<path refid="classpath.server"/>
</classpath>
<classpath>
<path refid="classpath.app"/>
<fileset dir="${lib.dir}" includes="*.jar"/>
</classpath>
</javac>
</target>
<target name="deleteConfig">
<delete file="${src}/mypropfile.properties"/>
</target>
<target name="real" depends="deleteConfig">
<copy file="${real.dir}/realprop.properties" tofile="${src}/mypropfile.properties"/>
</target>
<target name="real2" depends="deleteConfig">
<copy file="${real2.dir}/real2prop.properties" tofile="${src}/mypropfile.properties"/>
</target>
<target name="war-real" depends="real, compile">
<input message="Warname (without .war):" addproperty="warname"/>
<war destfile="${workspace.dir}/${warname}.war" webxml="${web.dir}/web.xml">
<fileset dir="${basedir}">
<include name="**/*.*"/>
</fileset>
<classes dir="${build.classes}"/>
</war>
</target>
<target name="war-real2" depends="real2, compile">
<input message="Warname (without .war):" addproperty="warname"/>
<war destfile="${workspace.dir}/${warname}.war" webxml="${web.dir}/web.xml">
<fileset dir="${basedir}">
<include name="**/*.*"/>
</fileset>
<classes dir="${build.classes}"/>
</war>
</target>
BUILD FAILED ... Reference classpath.server.bin not found.