如何从javac类路径设置项目的类路径?

时间:2015-06-23 06:36:55

标签: eclipse ant

我收到以下错误: “从javac类路径设置项目的类路径时出现问题:C:\ usr \ share \ hadoop不存在。”我不确定错误在说什么。我查看了构建文件,但没有看到任何对此类路径的引用。

构建文件,即build.xml如下所示:

<project name="Common Crawl Examples" default="dist" basedir=".">

  <description>
    Common Crawl Examples Build File
  </description>

  <!-- set global properties for this build -->
  <property name="name" value="commoncrawl-examples" />
  <loadfile srcfile="${basedir}/VERSION" property="version">
    <filterchain>
      <striplinebreaks />
    </filterchain>
  </loadfile>

  <!-- include any user specific or environment specifc build properties -->
  <property file="${user.home}/build.properties"/>
  <property file="${basedir}/build.properties"/>

  <!-- ensure that 'hadoop.path' is set -->
  <fail message="Please define the 'hadoop.path' property in this 'build.properties' file">
    <condition>
      <not>
        <isset property="hadoop.path"/>
      </not>
    </condition>
  </fail>

  <property name="lib"   location="lib"  />
  <property name="src"   location="src"  />
  <property name="build" location="build"/>
  <property name="dist"  location="dist" />
  <property name="test"  location="test" />

  <target name="init">
    <tstamp/>
    <mkdir dir="${build}"/>
  </target>

  <target name="compile" depends="init"
          description="compile the source" >
    <echo message=""/>
    <echo message="Building '${name}': Version ${version}"/>
    <echo message=""/>
    <javac srcdir="${src}" destdir="${build}" debug="on" debuglevel="lines,vars,source" target="1.6">
      <compilerarg value="-Xlint"/>
      <classpath>
        <pathelement path="${classpath}"/>
        <fileset dir="${hadoop.path}">
          <include name="**/hadoop-core-*.jar"/>
          <include name="**/log4j-*.jar"/>
          <include name="**/junit-*.jar"/>
        </fileset>
        <fileset dir="lib">
          <include name="**/*.jar"/>
        </fileset>
      </classpath>
    </javac>
  </target>

  <target name="dist" depends="compile"
          description="generate the distribution" >
    <mkdir dir="${dist}/lib"/>
    <mkdir dir="${build}/lib"/>
    <jar jarfile="${dist}/lib/${name}-${version}.jar" basedir="${build}">
      <zipfileset dir="lib" prefix="lib" >
        <include name="**/*.jar" />
      </zipfileset>
    </jar>
  </target>

  <target name="compile-tests" depends="dist"
          description="compile test cases" >
    <mkdir dir="${build}-test"/>
    <javac srcdir="${test}" destdir="${build}-test" debug="on" debuglevel="lines,vars,source" target="1.6">
      <compilerarg value="-Xlint"/>
      <classpath>
        <pathelement path="${classpath}"/>
        <pathelement path="/usr/share/java/junit.jar"/>
        <fileset dir="${hadoop.path}">
          <include name="**/hadoop-core-*.jar"/>
          <include name="**/log4j-*.jar"/>
        </fileset>
        <fileset dir="lib">
          <include name="**/*.jar"/>
        </fileset>
        <pathelement path="${dist}/lib/${name}-${version}.jar"/>
      </classpath>
    </javac>
  </target>

  <target name="test" depends="compile-tests"
          description="run Junit test cases" >
    <junit printsummary="true">
      <classpath>
        <pathelement path="${classpath}"/>
        <pathelement path="/usr/share/java/junit.jar"/>
        <fileset dir="${hadoop.path}">
          <include name="**/hadoop-core-*.jar"/>
          <include name="**/log4j-*.jar"/>
        </fileset>
        <fileset dir="lib">
          <include name="**/*.jar"/>
        </fileset>
        <pathelement path="${dist}/lib/${name}-${version}.jar"/>
        <pathelement path="${build}-test"/>
      </classpath>
      <batchtest>
        <fileset dir="${build}-test"/>
        <formatter type="plain" usefile="false"/>
      </batchtest>
    </junit>
  </target>

  <target name="clean"
          description="clean up" >
    <!-- Delete the ${build} and ${dist} directory trees -->
    <delete dir="${build}"/>
    <delete dir="${build}-test"/>
    <delete dir="${dist}"/>
  </target>
</project>

关于错误所指的任何想法?

谢谢,我很感激指点。我通过帖子阅读reg。类似的问题,但没有一个解决方案似乎解决了我的问题。

1 个答案:

答案 0 :(得分:0)

条件<isset property="hadoop.path"/>检查属性hadoop.path是否在以前加载的那些build.properties文件中定义。
查看这些文件以获取{{1}的定义}
hadoop.path=C:\usr\share\hadoop之后添加<echoproperties prefix="hadoop"/>以使所有hadopp.xxx属性回显或增加loglevel =&gt; <property file=.../>
查看所有属性和详细信息 如果未定义hadoop.path,则必须将其设置为userproperty,表示您的ant脚本以ant -f yourbuild.xml -debug启动。 在Eclipse中,您将使用ant编辑器或导航器中的上下文菜单,并且: ant -f yourbuild.xml -Dhadoop.path=...然后在Run As | 2 AntBuild...窗口中选择Edit Configuration并输入
Main Tab进入-Dhadoop.path=whateveryoulike以设置您的用户属性。
此外,loglevel通过Main | Arguments设置,只需将-debug或-verbose放入。