0

我同时设置了 JAVA_HOME 和 ANT_HOME:

damechen@ubuntu:~/apache-tomcat-7.0.42-src$ echo $ANT_HOME 
/home/damechen/tmp/damechen/apache-ant-1.9.1
damechen@ubuntu:~/apache-tomcat-7.0.42-src$ echo $JAVA_HOME 
/usr/lib/jvm/jdk1.7.0.25
damechen@ubuntu:~/apache-tomcat-7.0.42-src$ java -version
java version "1.7.0_25"
Java(TM) SE Runtime Environment (build 1.7.0_25-b15)
Java HotSpot(TM) 64-Bit Server VM (build 23.25-b01, mixed mode)

我试图使用ant来构建tomcat,但是由于一些与build.xml相关的原因它失败了。

BUILD FAILED
/home/damechen/apache-tomcat-7.0.42-src/build.xml:2396: The following error occurred while executing this line:
/home/damechen/apache-tomcat-7.0.42-src/build.xml:2625: Directory /usr/share/java/tomcat-native-1.1.27 creation was not successful for an unknown reason
    at org.apache.tools.ant.taskdefs.Mkdir.execute(Mkdir.java:70)
    at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:292)
    at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
    at org.apache.tools.ant.Task.perform(Task.java:348)
    at org.apache.tools.ant.Target.execute(Target.java:435)
    at org.apache.tools.ant.Target.performTasks(Target.java:456)
    at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1393)
    at org.apache.tools.ant.helper.SingleCheckExecutor.executeTargets(SingleCheckExecutor.java:38)
    at org.apache.tools.ant.Project.executeTargets(Project.java:1248)
    at org.apache.tools.ant.taskdefs.Ant.execute(Ant.java:440)
    at org.apache.tools.ant.taskdefs.CallTarget.execute(CallTarget.java:105)
    at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:292)
    at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
    at org.apache.tools.ant.Task.perform(Task.java:348)
    at org.apache.tools.ant.Target.execute(Target.java:435)
    at org.apache.tools.ant.Target.performTasks(Target.java:456)
    at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1393)
    at org.apache.tools.ant.Project.executeTarget(Project.java:1364)
    at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
    at org.apache.tools.ant.Project.executeTargets(Project.java:1248)
    at org.apache.tools.ant.Main.runBuild(Main.java:851)
    at org.apache.tools.ant.Main.startAnt(Main.java:235)
    at org.apache.tools.ant.launch.Launcher.run(Launcher.java:280)
    at org.apache.tools.ant.launch.Launcher.main(Launcher.java:109)

Total time: 0 seconds
damechen@ubuntu:~/apache-tomcat-7.0.42-src$ 

任何人都可以帮我一把吗?非常感谢!

4

2 回答 2

1

正如例外所说。构建失败,因为它试图创建一个名为tomcat-native-1.1.27./usr/share/java/

请给予适当的权利。

于 2013-07-13T01:56:33.530 回答
1

您需要阅读 Apache tomcat 的构建说明:

(3.2) 建筑

  1. 通过创建 ${tomcat.source}/build.properties 文件来控制构建。

    建议始终创建文件,因为不幸的是 base.path 属性的默认值。您可以从文件的以下内容开始:

    # ----- Default Base Path for Dependent Packages -----
    # Replace this path with the directory path where dependencies binaries
    # should be downloaded
    base.path=/home/me/some-place-to-download-to
    
  2. 通过将 base.path 属性添加到 ${tomcat.source}/build.properties 文件来配置它。

    base.path 属性指定下载构建所需的 Tomcat 依赖项的位置。建议将此目录放在源代码树之外,这样您就不会浪费时间重新下载库。

    • 警告:base.path 属性的默认值使构建脚本将构建 Tomcat 所需的库下载到 /usr/share/java 目录。在典型的 Linux 或 MacOX 系统上,普通用户将无权写入此目录。即使您确实有权访问该目录,您也可能不适合在此处编写。

请注意最后的警告......这是您问题的根本原因。

分析

构建文件在失败时调用“download-2”目标:

  <target name="extras-commons-logging-prepare"
          depends="extras-prepare"
          description="Prepare to build web services extras package">

    <antcall target="downloadfile-2">
      <param name="sourcefile.1" value="${commons-logging-src.loc.1}"/>
      <param name="sourcefile.2" value="${commons-logging-src.loc.2}"/>
      <param name="destfile" value="${commons-logging-src.tar.gz}"/>
      <param name="destdir" value="${commons-logging.home}"/>
    </antcall>

    ..
    ..

在您的 build.properties 文件中,您已将commons-logging.home属性的值设置为您无权创建目录的目录路径,即:

/usr/share/java/...

进一步挖掘我看到默认属性文件设置此路径如下:

# ----- Default Base Path for Dependent Packages -----
# Please note this path must be absolute, not relative,
# as it is referenced with different working directory
# contexts by the various build scripts.
base.path=/usr/share/java
#base.path=C:/path/to/the/repository
#base.path=/usr/local

..
..

commons-logging.version=1.1.1
commons-logging.home=${base.path}/commons-logging-${commons-logging.version}
于 2013-07-13T08:20:37.147 回答