我的 Ant 构建文件的类路径问题

发布于 2024-09-19 01:50:36 字数 3354 浏览 6 评论 0原文

我一直在使用这个确切的 Build.xml 文件。我一开始使用 junit 任务时遇到了问题,但几个月前我解决了这些问题。

最近,当我使用测试任务运行构建文件时,我收到了所有常见的错误消息。

test:
[junit] Testsuite: com.mmz.mvc.test.AgentDAOTest
[junit] Tests run: 1, Failures: 0, Errors: 1, Time elapsed: 0 sec
[junit] Null Test:  Caused an ERROR
[junit] com.mmz.mvc.test.AgentDAOTest
[junit] java.lang.ClassNotFoundException: com.mmz.mvc.test.AgentDAOTest
[junit]     at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
[junit]     at java.lang.Class.forName0(Native Method)
[junit]     at java.lang.Class.forName(Class.java:247)
[junit]     at org.eclipse.ant.internal.ui.antsupport.EclipseDefaultExecutor.executeTargets(EclipseDefaultExecutor.java:32)
[junit]     at org.eclipse.ant.internal.ui.antsupport.InternalAntRunner.run(InternalAntRunner.java:423)
[junit]     at org.eclipse.ant.internal.ui.antsupport.InternalAntRunner.main(InternalAntRunner.java:137)

BUILD FAILED
C:\Users\myName\Documents\Java\mmz\WEB-INF\build.xml:45: 
Testcom.mmz.mvc.test.AgentDAOTest failed

我知道这个问题与我的类路径有关,但我不确定为什么它工作了这么长时间会突然中断。

我的构建如下所示。

<property file="build.properties"/>
<property name="src.dir" value="src"/>
<property name="build.dir" value="classes"/>
<property name="web.dir" value="war"/>

 <path id="build.classpath">
  <fileset dir="lib">
      <include name="*.jar"/>
  </fileset>
  <fileset dir="${appserver.lib}">
      <include name="servlet*.jar"/>
  </fileset>
  <pathelement path="${build.dir}"/>
  <pathelement path="${test.dir}"/>
 </path>

 <path id="classpath.base"/>
 <path id="classpath.test">
 <pathelement location="c:/ant/lib/junit.jar" />
 <pathelement location="${build.dir}"/>
 <pathelement location="${src.dir}"/>
 <pathelement location="${test.dir}" />
 <pathelement location="classes"/>
 <path refid="classpath.base" />
 </path>

 <target name="build">
    <mkdir dir="${build.dir}"/>
     <mkdir dir="${test.dir}"/>
     <javac destdir="${build.dir}" source="1.5" target="1.5" debug="true"    deprecation="false" optimize="false" failonerror="true">
      <src path="${src.dir}"/>
       <classpath refid="build.classpath"/>
     </javac>
  <javac destdir="${build.dir}" source="1.5" target="1.5" debug="true" deprecation="false" optimize="false" failonerror="true">
      <src path="${test.dir}"/>
      <classpath refid="build.classpath"/>
  </javac>
  </target>

    <target name="test">
    <junit haltonfailure="true">
      <classpath refid="classpath.test" />
      <classpath refid="build.classpath"/>
      <formatter type="brief" usefile="false" />
      <test name="com.mmz.mvc.test.AgentDAOTest"/>
      <test name="com.mmz.mvc.test.AgentProfileDAOTest"/>
      <test name="com.mmz.mvc.test.BuyerDAOTest"/>
      <test name="com.mmz.mvc.test.BuyerSellerDAOTest"/>
      <test name="com.mmz.mvc.test.BaseDAOTest"/>
      <test name="com.mmz.mvc.test.MemberDAOTest"/>
      <test name="com.mmz.mvc.test.SellerDAOTest"/>
    </junit>

我不太擅长构建文件,也不擅长理解如何设置类路径和所有内容,因此如果有人可以提供帮助,我将不胜感激。

I have been using this exact Build.xml file. I had problems in the beginning using the junit task with it, but I figured out those problems a couple months ago.

Recently I got the all to common error message when I ran my build file with the test task.

test:
[junit] Testsuite: com.mmz.mvc.test.AgentDAOTest
[junit] Tests run: 1, Failures: 0, Errors: 1, Time elapsed: 0 sec
[junit] Null Test:  Caused an ERROR
[junit] com.mmz.mvc.test.AgentDAOTest
[junit] java.lang.ClassNotFoundException: com.mmz.mvc.test.AgentDAOTest
[junit]     at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
[junit]     at java.lang.Class.forName0(Native Method)
[junit]     at java.lang.Class.forName(Class.java:247)
[junit]     at org.eclipse.ant.internal.ui.antsupport.EclipseDefaultExecutor.executeTargets(EclipseDefaultExecutor.java:32)
[junit]     at org.eclipse.ant.internal.ui.antsupport.InternalAntRunner.run(InternalAntRunner.java:423)
[junit]     at org.eclipse.ant.internal.ui.antsupport.InternalAntRunner.main(InternalAntRunner.java:137)

BUILD FAILED
C:\Users\myName\Documents\Java\mmz\WEB-INF\build.xml:45: 
Testcom.mmz.mvc.test.AgentDAOTest failed

I know this problem is related to my classpath, but I am not sure why this would all of a sudden break when it has been working for so long.

My build follow looks like the following.

<property file="build.properties"/>
<property name="src.dir" value="src"/>
<property name="build.dir" value="classes"/>
<property name="web.dir" value="war"/>

 <path id="build.classpath">
  <fileset dir="lib">
      <include name="*.jar"/>
  </fileset>
  <fileset dir="${appserver.lib}">
      <include name="servlet*.jar"/>
  </fileset>
  <pathelement path="${build.dir}"/>
  <pathelement path="${test.dir}"/>
 </path>

 <path id="classpath.base"/>
 <path id="classpath.test">
 <pathelement location="c:/ant/lib/junit.jar" />
 <pathelement location="${build.dir}"/>
 <pathelement location="${src.dir}"/>
 <pathelement location="${test.dir}" />
 <pathelement location="classes"/>
 <path refid="classpath.base" />
 </path>

 <target name="build">
    <mkdir dir="${build.dir}"/>
     <mkdir dir="${test.dir}"/>
     <javac destdir="${build.dir}" source="1.5" target="1.5" debug="true"    deprecation="false" optimize="false" failonerror="true">
      <src path="${src.dir}"/>
       <classpath refid="build.classpath"/>
     </javac>
  <javac destdir="${build.dir}" source="1.5" target="1.5" debug="true" deprecation="false" optimize="false" failonerror="true">
      <src path="${test.dir}"/>
      <classpath refid="build.classpath"/>
  </javac>
  </target>

    <target name="test">
    <junit haltonfailure="true">
      <classpath refid="classpath.test" />
      <classpath refid="build.classpath"/>
      <formatter type="brief" usefile="false" />
      <test name="com.mmz.mvc.test.AgentDAOTest"/>
      <test name="com.mmz.mvc.test.AgentProfileDAOTest"/>
      <test name="com.mmz.mvc.test.BuyerDAOTest"/>
      <test name="com.mmz.mvc.test.BuyerSellerDAOTest"/>
      <test name="com.mmz.mvc.test.BaseDAOTest"/>
      <test name="com.mmz.mvc.test.MemberDAOTest"/>
      <test name="com.mmz.mvc.test.SellerDAOTest"/>
    </junit>

I am not very good with build files and I am not very good at understanding the how to setup classpaths and everything so If somebody could help I would appreciate it.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

日久见人心 2024-09-26 01:50:36

看起来像缺少 jar 文件,包含类“com.mmz.mvc.test.AgentDAOTest”。读取您的构建文件表明该 jar 曾经位于您的“lib”目录中。

当然,我假设这个类不是位于“src”或“${test.dir}”目录下的缺失Java源文件......

Looks like a missing jar file, containing the class "com.mmz.mvc.test.AgentDAOTest". Reading your build file suggests the jar used to be located in your "lib" directory.

I'm assuming, of course, that this class is not a missing Java source file located under you "src" or "${test.dir}" directories.....

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文