Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/eclipse/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 刷新不';在Eclipse上创建与Ant的战争之前,我无法工作_Java_Eclipse_Ant_File Copying - Fatal编程技术网

Java 刷新不';在Eclipse上创建与Ant的战争之前,我无法工作

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

在Eclipse上,我使用ant创建war文件

问题是war文件中没有包含正确的
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
因此,第一步应该是定义一种定位文件夹的方法,然后在任何地方都使用这种模式

如果这不能解决您的问题,您需要确保Ant注意到文件已更改。像FAT这样的旧文件系统只支持具有第二分辨率的时间戳。如果您使用U盘作为源代码,则可以更改文件并快速运行Ant,使Ant认为文件没有更改

最后,您需要检查类路径。如果其中一个JAR依赖项还包含一个名为
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.