java - Ant build 无法扩展环境变量

标签 java tomcat ant

我在为开发目的而设置的新服务器上的构建过程有问题。

这是在带有 Java/Tomcat v7 的 Centos 6 机器上运行的。输出结果如下:

Buildfile: /home/ec2-user/twv/trunk/EES/build.xml

init:
     [echo] Build of EES started at 1332 on December 19 2015

clean:
     [echo] Cleaning EES
   [delete] Deleting directory /home/ec2-user/twv/trunk/EES/build

compile:
     [echo] Compiling EES
    [mkdir] Created dir: /home/ec2-user/twv/trunk/EES/build/WEB-INF/classes
    [javac] Compiling 78 source files to /home/ec2-user/twv/trunk/EES/build/WEB-INF/classes

BUILD FAILED
/home/ec2-user/twv/trunk/EES/build.xml:118: /home/ec2-user/twv/trunk/EES/${currentenv.TOMCAT_HOME}/lib does not exist.

关于 SO 的其他回复表明未创建环境变量,但如果我运行以下命令:

echo $TOMCAT_HOME

它返回:

/usr/local/tomcat7

所以我知道变量存在并已设置。

这是 build.xml 文件:

<?xml version="1.0"?>
<!-- #######################################################################
                        B u i l d   S c r i p t
####################################################################### -->

<project name="EES" default="war">
        <description> EES </description>
        <property environment="currentenv" />
        <property name="tomcat.home" location="${currentenv.TOMCAT_HOME}"/>
        <property file="build.${currentenv.ANT_HOST_NAME}" />
        <property name="webapp.path" value="build"/>

<!-- #######################################################################
                T a r g e t : I n i t
####################################################################### -->

  <target name="init">
    <tstamp/>
    <echo>Build of ${ant.project.name} started at ${TSTAMP} on ${TODAY}</echo>
  </target>


<!-- #######################################################################
                T a r g e t : D e f a u l t
####################################################################### -->

        <target name="war" depends="init, clean, compile,compilejsp,copywebroot" description="Bundle up everything">
        <!-- target name="war" depends="init, clean,compile,copywebroot" description="Bundle up everything" -->
                <echo>Packaging ${ant.project.name}</echo>
                <jar destfile="EES.war" basedir="${webapp.path}"/>
                <echo>Finished packaging ${ant.project.name}</echo>
        </target>

<!-- #######################################################################
                T a r g e t : C o p y w e b r o o t
####################################################################### -->

        <target name="copywebroot">
                <copy todir="${webapp.path}" >
                        <fileset dir="WebRoot">
                               <include name="**"/>
                        </fileset>
                </copy>
        </target>

<!-- #######################################################################
                T a r g e t : j s p c
####################################################################### -->
        <target name="jspc">

                <taskdef classname="org.apache.jasper.JspC" name="jasper2" >
                        <classpath id="jspc.classpath">
                                <pathelement location="${java.home}/../lib/tools.jar"/>
                                <fileset dir="${tomcat.home}/bin">
                                        <include name="*.jar"/>
                                </fileset>
                                <fileset dir="${tomcat.home}/lib">
                                        <include name="*.jar"/>
                                </fileset>
                                <fileset dir="${tomcat.home}/lib">
                                        <include name="*.jar"/>
                                </fileset>
                                <fileset dir="${ant.home}/lib">
                                        <include name="ant.jar"/>
                                </fileset>
                        </classpath>
                </taskdef>
                <mkdir dir="${webapp.path}/WEB-INF/src"/>
<!--            <jasper2 verbose="255"
                     validateXml="false"
                     uriroot="${webapp.path}"
                     webXmlFragment="${webapp.path}/WEB-INF/generated_web.xml"
                     outputDir="${webapp.path}/WEB-INF/src" /> -->
                 <java classname="org.apache.jasper.JspC"
                          classpathref="jspc.classpath"
                          fork="true" failonerror="true">
                        <arg line="-v -d ${webapp.path}/WEB-INF/src -webapp ${webapp.path}"/>
                    </java>

        </target>
        <target name="compilejsp" depends="jspc">
                <mkdir dir="${webapp.path}/WEB-INF/classes"/>
                <mkdir dir="${webapp.path}/WEB-INF/lib"/>

                <javac destdir="${webapp.path}/WEB-INF/classes"
                        optimize="off"
                        debug="on" failonerror="false"
                        srcdir="${webapp.path}/WEB-INF/src"
                        excludes="**/*.smap">
                        <classpath>
                                <pathelement location="${webapp.path}/WEB-INF/classes"/>
                                <fileset dir="${webapp.path}/WEB-INF/lib">
                                        <include name="*.jar"/>
                                </fileset>
                                <pathelement location="${tomcat.home}/lib"/>
                                <fileset dir="${tomcat.home}/lib">
                                        <include name="*.jar"/>
                                </fileset>
                                <fileset dir="${tomcat.home}/bin">
                                        <include name="*.jar"/>
                                </fileset>
                        </classpath>
                        <include name="**" />
                        <exclude name="tags/**" />
                </javac>
        </target>

<!-- #######################################################################
                T a r g e t : C o m p i l e
####################################################################### -->

        <target name="compile">
                <echo>Compiling ${ant.project.name}</echo>
                <mkdir dir="${webapp.path}/WEB-INF/classes"/>
                <javac includeAntRuntime="false" srcdir="src"
                                debug="on"
                                destdir="${webapp.path}/WEB-INF/classes">
                        <!--destdir="${webapp.path}/WEB-INF/classes">-->
                        <classpath>
                                <fileset dir="WebRoot/WEB-INF/lib">
                                        <include name="**/*.jar"/>
                                </fileset>
                                <fileset dir="${tomcat.home}/lib">
                                        <include name="**/*.jar"/>
                                </fileset>
                        </classpath>
                </javac>
                <copy file="src/in.xls"
                          tofile="${webapp.path}/WEB-INF/classes/com/xxx/ees/action/in.xls">

                </copy>
        <copy todir="${webapp.path}/WEB-INF/classes">
            <fileset dir="src">
                <include name="**"/>
                <exclude name="**/*.java"/>
                <exclude name="**/*.class"/>
            </fileset>
        </copy>

                         <echo>Finished compiling ${ant.project.name}</echo>
        </target>



        <!-- =================================
          target: deploy
         ================================= -->
    <target name="deploy" depends="war" description="--> deploys the war file locally">
        <copy todir="${tomcat.home}/webapps"  file="EES.war"/>
    </target>

        <target name="remotedeploy" depends="war">
                <scp keyfile="${user.home}/.ssh/id_dsa" passphrase="" file="EES.war"  remoteTodir="x@y.com.com:" verbose="true"/>
                <sshexec keyfile="${user.home}/.ssh/id_dsa" host="x.y.com" username="xxx"  command="/home/xxx/deployees"/>
        </target>

<!-- #######################################################################
                T a r g e t : C l e a n
####################################################################### -->
        <target name="clean">
                <echo>Cleaning ${ant.project.name}</echo>
                <delete dir="${webapp.path}" >
                </delete>
        </target>
</project>

关于如何修复有什么建议吗?

最佳答案

我的猜测是 Ant 没有“看到”TOMCAT_HOME,因为调用 Ant 的系统进程没有在其上定义该变量。

确保您从同一系统用户调用 Ant,该系统用户的配置文件中有 TOMCAT_HOME 变量,并且在启动 Ant 时保留环境变量。

关于java - Ant build 无法扩展环境变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34371384/

相关文章:

tomcat - Jruby On Rails 应用程序在使用 Warble 进行 WAR 时在 Tomcat 上给出 LocalJumpError

java - Apache Ant 'Build.xml' > 由于 '@BeforeClass' 而失败

java.sql.SQLException : Before start of result set already have rs. 下一步

c# - Android与C#之间的进程间通信

java - JPA Criteria Builder OneToMany 限制

session - Openshift 如何在自动缩放应用程序中默认处理 session ?

apache - 反向代理重定向 http 到 https

ant - 从批处理文件 : Later commands don't run 运行 ant

xpath - 如果 XML 文件具有不同 namespace 中的元素,则使用 XMLTasks 的 ant 的 XMLPath 无法匹配

java - 为什么这种泛型的使用不会抛出运行时或编译时异常?