首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Ant构建失败,不能扩展出环境变量。

Ant构建失败,不能扩展出环境变量。
EN

Stack Overflow用户
提问于 2015-12-19 13:36:09
回答 4查看 1.1K关注 0票数 3

我对新服务器上的构建过程有一个问题,我只是为了开发目的而设置了这个过程。

这是在一个带有Java/Tomcat v7的Centos 6盒上运行的。产出如下:

代码语言:javascript
复制
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.

因此,其他响应表明没有创建环境变量,但如果我运行以下命令:

代码语言:javascript
复制
echo $TOMCAT_HOME

它返回:

代码语言:javascript
复制
/usr/local/tomcat7

所以我知道变量是存在的,并且已经设置好了。

这是build.xml文件:

代码语言:javascript
复制
<?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>

对如何修复有什么建议吗?

EN

回答 4

Stack Overflow用户

回答已采纳

发布于 2015-12-21 11:20:25

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

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

票数 1
EN

Stack Overflow用户

发布于 2015-12-19 19:40:26

不确定这是否是最好的解决方案,但我在build.xml中更改了这一行

代码语言:javascript
复制
<fileset dir="${tomcat.home}/lib">

指向tomcat的位置:

代码语言:javascript
复制
<fileset dir="/usr/local/tomcat7/lib">

这就成功了。

如果这一行读到了如下内容:

代码语言:javascript
复制
<fileset dir="${TOMCAT_HOME}/lib">

为了匹配环境变量?

票数 0
EN

Stack Overflow用户

发布于 2015-12-19 23:20:26

您已经通过分配硬编码值dir="/usr/local/tomcat7/lib"暂时解决了构建问题,但这不是一个永久的修复。如果格式化计算机并更改路径,或者与可能具有不同tomcat安装路径的人共享此代码,则会出现问题。ant脚本中真正的罪魁祸首是这行代码:

代码语言:javascript
复制
<property name="tomcat.home" location="${currentenv.TOMCAT_HOME}"/>

您知道,如果要指定一个location属性,则ant属性将用于relative path属性。您已经指定了location属性,因此ant build正在拼命地搜索相对于当前路径的tomcat安装(因此失败):

代码语言:javascript
复制
/home/ec2-user/twv/trunk/EES/${currentenv.TOMCAT_HOME}/lib

这里的解决方案是指定一个value属性,而不是location,因为您的$TOMCAT_HOME引用了/usr/local中的绝对路径

代码语言:javascript
复制
<property name="tomcat.home" value="${currentenv.TOMCAT_HOME}"/>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/34371384

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档