ant构建后java项目不工作

ant构建后java项目不工作,java,eclipse,ant,Java,Eclipse,Ant,我是Java新手,在这个问题上花了太多时间,无法解决: 我在EclipseJava项目中运行build.xml文件。项目成功构建,所有测试都通过,但在该项目不工作之后,.classpath文件似乎出现了问题,因为如果我更改构建路径设置(例如删除libs并再次添加),一切都正常 build.xml文件 ` 当文件更改时,eclipse通常会弹出 试试这个 右键单击项目,然后按刷新 使用项目->清理。。。日蚀 在eclipse中使用Project->build all 看起来您正在使用Eclips

我是Java新手,在这个问题上花了太多时间,无法解决:

我在EclipseJava项目中运行
build.xml
文件。项目成功构建,所有测试都通过,但在该项目不工作之后,.classpath文件似乎出现了问题,因为如果我更改构建路径设置(例如删除libs并再次添加),一切都正常

build.xml文件 `


当文件更改时,eclipse通常会弹出

试试这个

  • 右键单击项目,然后按刷新
  • 使用项目->清理。。。日蚀
  • 在eclipse中使用Project->build all

  • 看起来您正在使用Eclipse的构建作为ant编译的目标,因此在ant编译目标运行后,您的工作区不同步

    如果Eclipse和Ant之间的类路径相同,为什么需要Ant的干净和编译目标?如果它们不同,Ant应该编译到不同的目的地

    如果您确实希望Ant和Eclipse编译到同一个目标,请告诉Eclipse通过在项目根目录上点击F5来刷新,或者将external tools下的Ant build配置设置为自动刷新:

    在每次生成之前执行
    build clean
    时会发生什么?您知道sef.test.repository.stubprojectrepositoryimpletest类在哪里吗?这是你的一门考试课吗?或者它是第三方?是的,sef.test.repository.stubprojectrepositoryimpletest在我的项目(我的一个测试)中,它工作正常,但在成功构建项目并运行成功测试后,此测试将不起作用
    <!-- Sets variables which can later be used. -->
    <!-- The value of a property is accessed via ${} -->
    <property name="src.dir" location="src" />
    <property name="build.dir" location="build" />
    <property name="dist.dir" location="dist" />
    <property name="test.report.dir" location="test report" />
    
    <!-- Define the classpath which includes -->
    <path id="junit.class.path">
    
        <!-- needed libs -->
        <pathelement location="lib/commons-dbcp.jar" />
        <pathelement location="lib/commons-logging.jar" />
        <pathelement location="lib/commons-pool.jar" />
        <pathelement location="lib/log4j-1.2.15.jar" />
        <pathelement location="lib/mysql-connector-java-5.1.6-bin.jar" />
        <pathelement location="lib/spring.jar" />
        <pathelement location="lib/spring-webmvc.jar" />
        <pathelement location="lib/standard.jar" />
    
        <!-- JUnit 3-4 -->
        <pathelement location="C:\Program Files\eclipse\plugins\org.junit_4.8.1.v4_8_1_v20100427-1100\junit.jar" />
        <pathelement location="C:\Program Files\eclipse\plugins\org.junit_3.8.2.v3_8_2_v20100427-1100\junit.jar" />
    
        <!-- repository-config.xml -->
        <pathelement location="config" />
    
        <!-- classes after compiling -->
        <pathelement location="${build.dir}" />
    </path>
    
    <!-- Deletes the existing build, docs and dist directory-->
    <target name="clean">
        <delete dir="${build.dir}" />
        <delete dir="${dist.dir}" />
        <delete dir="${test.report.dir}" />
    </target>
    
    <!-- Creates the  build, docs and dist directory-->
    <target name="makedir">
        <mkdir dir="${build.dir}" />
        <mkdir dir="${dist.dir}" />
        <mkdir dir="${test.report.dir}" />
    </target>
    
    <!-- Compiles the java code (including the usage of library for JUnit -->
    <target name="compile" depends="clean, makedir">
        <javac srcdir="${src.dir}" destdir="${build.dir}">
            <classpath refid="junit.class.path" />
        </javac>
    </target>
    
    <!--Creates the deployable jar file  -->
    <target name="jar" depends="compile">
        <jar destfile="${dist.dir}\empdb.build.ant.jar" basedir="${build.dir}">
        </jar>
    </target>
    
    <!-- Run the JUnit Tests -->
    <!-- Output is XML, could also be plain-->
    <target name="junit" depends="jar">
        <junit printsummary="on" fork="true" haltonfailure="yes">
            <classpath refid="junit.class.path" />
            <formatter type="xml" />
            <batchtest todir="${test.report.dir}">
                <fileset dir="${src.dir}">
                    <include name="**/*Test*.java" />
                </fileset>
            </batchtest>
        </junit>
    </target>
    
    <target name="main" depends="junit">
        <description>Main target</description>
    </target>
    
    Class not found sef.test.repository.StubProjectRepositoryImplTest
    java.lang.ClassNotFoundException: sef.test.repository.StubProjectRepositoryImplTest
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.loadClass(RemoteTestRunner.java:693)
        at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.loadClasses(RemoteTestRunner.java:429)
        at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:452)
        at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
        at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
        at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)