当前位置: 首页 > 知识库问答 >
问题:

在Eclipse上与Ant创建战争之前,刷新不起作用

柳德义
2023-03-14

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

问题是在war文件中没有包含正确的mypropfile.properties。该文件被正确复制,但如果我使用

对于Ant,我使用“在与工作区相同的JRE中运行”选项。

<?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.

共有1个答案

贺季同
2023-03-14

Ant不关心Eclipse是否刷新了文件<代码>eclipse。refreshLocal仅与IDE内部的编辑器和编译器相关。

当您运行Ant构建时。xml,Ant将real目标中有问题的文件复制到源文件夹中,并将其复制到类中(至少它应该这样做)。因此,在创建WAR之前,必须确保编译步骤已经完成了工作(即查看每个文件,确保每个副本中都有可见的更改)。

我担心的是,您使用不同的方式访问类:

  • ${build}/classes

所以第一步应该是定义一种单一的方法来定位文件夹,然后在任何地方使用这种模式。

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

最后,您需要检查类路径。如果其中一个JAR依赖项还包含一个名为mypropfile的文件。属性,则Java资源加载可以找到任何一个版本。

这个问题和其他问题使我使用不同的解决方案来配置WAR文件:我传递一个带有配置文件绝对路径的系统属性。这样,配置更改时WAR文件不会更改,我可以完全控制加载哪个配置文件。

 类似资料:
  • 我已经尝试使用Config Server实现spring外部配置。当应用程序启动时,它第一次工作得很好,但对属性文件的任何更改都不会反映出来。我试图使用/refreshendpoint来动态刷新我的属性,但它似乎不起作用。在这方面的任何帮助都将是非常有帮助的。 我尝试向localhost:8080/refresh发帖,但得到404错误响应。 下面是我的应用程序类的代码 和bootstrap.pro

  • 我有一个简单的Spring Boot应用程序,当我在Eclipse中使用我的Liberty服务器运行时,我可以运行良好,问题是当我尝试对war文件进行构建(使用maven)并将该war添加到同一服务器并尝试运行它时,服务器启动良好,但在点击服务器URL后,它会显示Spring Security登录名/密码弹出窗口,但在我的应用程序中,我配置了登录名和几个示例endpoint,但服务器找不到它们,从

  • 我想使用Spring初始值设定项为tomcat创建WAR… 我们的DevOp仍然不习惯将java作为独立运行的想法,并且希望在tomcat中将应用程序作为WAR 我能够产生一个项目,但它似乎产生了一个独立的Spring启动应用程序 我仍然想使用Spring Launalizr来生成所有依赖项,例如: Rest存储库 JDBC模板 石英 Rest 一种解决方案是在eclipse中创建一个动态web项

  • 我有一个jquery移动页面,里面有JavaScript。问题是,除非刷新页面,否则JavaScript无法工作。这是我的代码:

  • 我尝试在Ubuntu11.02的命令行上运行ant build.xml中的javac。然后运行“ant deploy-live”之后,命令行打印如下: 我关于javac的任务: 操作系统:Ubuntu 11.10(oneiric) Java版本:Java版本“1.7.0”Java(TM)SE运行时环境(build 1.7.0-B147)Java HotSpot(TM)64位服务器VM(build