首页 > 解决方案 > Netbeans - 构建错误,类文件夹为空

问题描述

我正在将我的项目从一个系统迁移到另一个系统。该项目位于 Bitbucket 中。该项目在旧系统中运行良好。所以为了迁移到新系统,我在新系统中克隆了项目。我添加了所需的库并设置了正确的 JAVA 平台。(这个项目构建了一个 .jar 文件,该文件用于另一个商业现成(COTS)工具。这基本上为 COTS 工具创建了一个宏。)在我设置项目之后,当我尝试在系统中构建项目时,我得到以下输出。

ant -f C:\\Users\\userid\Documents\Project package-for-store
init:
Deleting: C:\Users\userid\Documents\Project\build\built-jar.properties
deps-jar:
Updating property file: C:\Users\userid\Documents\Project\build\built-jar.properties
Compiling 53 source files to C:\Users\userid\Documents\Project\build\classes
BUILD FAILED (total time: 0 seconds)

我没有显示实际路径。我看到类文件夹是空的。我将classes文件夹的内容从旧系统复制到新系统。我仍然遇到同样的错误。唯一的区别是现在它说的是 52 个源文件而不是 53 个。我还在下面显示了 build.xml 文件

<?xml version="1.0" encoding="UTF-8"?>
<!-- You may freely edit this file. See commented blocks below for -->
<!-- some examples of how to customize the build. -->
<!-- (If you delete it and reopen the project it will be recreated.) -->
<!-- By default, only the Clean and Build commands use this build script. -->
<!-- Commands such as Run, Debug, and Test only use this build script if -->
<!-- the Compile on Save feature is turned off for the project. -->
<!-- You can turn off the Compile on Save (or Deploy on Save) setting -->
<!-- in the project's Project Properties dialog box.-->
<project name="DUMMY_PROJECT" default="default" basedir=".">
    <description>Builds, tests, and runs the project DUMMY_PROJECT.</description>
    <import file="nbproject/build-impl.xml"/>
    <!--

    There exist several targets which are by default empty and which can be 
    used for execution of your tasks. These targets are usually executed 
    before and after some main targets. They are: 

      -pre-init:                 called before initialization of project properties
      -post-init:                called after initialization of project properties
      -pre-compile:              called before javac compilation
      -post-compile:             called after javac compilation
      -pre-compile-single:       called before javac compilation of single file
      -post-compile-single:      called after javac compilation of single file
      -pre-compile-test:         called before javac compilation of JUnit tests
      -post-compile-test:        called after javac compilation of JUnit tests
      -pre-compile-test-single:  called before javac compilation of single JUnit test
      -post-compile-test-single: called after javac compilation of single JUunit test
      -pre-jar:                  called before JAR building
      -post-jar:                 called after JAR building
      -post-clean:               called after cleaning build products

    (Targets beginning with '-' are not intended to be called on their own.)

    Example of inserting an obfuscator after compilation could look like this:

        <target name="-post-compile">
            <obfuscate>
                <fileset dir="${build.classes.dir}"/>
            </obfuscate>
        </target>

    For list of available properties check the imported 
    nbproject/build-impl.xml file. 


    Another way to customize the build is by overriding existing main targets.
    The targets of interest are: 

      -init-macrodef-javac:     defines macro for javac compilation
      -init-macrodef-junit:     defines macro for junit execution
      -init-macrodef-debug:     defines macro for class debugging
      -init-macrodef-java:      defines macro for class execution
      -do-jar:                  JAR building
      run:                      execution of project 
      -javadoc-build:           Javadoc generation
      test-report:              JUnit report generation

    An example of overriding the target for project execution could look like this:

        <target name="run" depends="DUMMY_PROJECT-impl.jar">
            <exec dir="bin" executable="launcher.exe">
                <arg file="${dist.jar}"/>
            </exec>
        </target>

    Notice that the overridden target depends on the jar target and not only on 
    the compile target as the regular run target does. Again, for a list of available 
    properties which you can use, check the target you are overriding in the
    nbproject/build-impl.xml file. 

    -->
    <target name="package-for-store" depends="jar">
        <property name="store.jar.name" value="DUMMY_PROJECT"/>
        <property name="store.dir" value="store"/>
        <property name="store.jar" value="${store.dir}/${store.jar.name}.jar"/>
        <echo message="Packaging ${application.title} into a single JAR at ${store.jar}"/>
        <delete dir="${store.dir}"/>
        <mkdir dir="${store.dir}"/>

        <jar destfile="${store.dir}/temp_final.jar" filesetmanifest="skip">
            <zipgroupfileset dir="dist" includes="*.jar"/>
            <zipgroupfileset dir="dist/lib" includes="*.jar"/>
            <manifest>
                <attribute name="Main-Class" value="${main.class}"/>
            </manifest>
        </jar>

        <zip destfile="${store.jar}">
            <zipfileset src="${store.dir}/temp_final.jar"
                        excludes="META-INF/*.SF, META-INF/*.DSA, META-INF/*.RSA"/>
        </zip>

        <delete file="${store.dir}/temp_final.jar"/>
    </target>
</project>

我添加了一个新的目标“package-for-store”来包含所需的附加库和 jar 文件,这些库和 jar 文件将包含在最终的 jar 文件中。这在旧系统中运行良好。事实上,如果我尝试调试构建过程,它根本不会到达目标标签。它进入 build-impl.xml 文件。

build-impl.xml 是一个非常大的文件。但是我将标签放在构建失败的地方进行调试。

    <target depends="init,deps-jar,-pre-pre-compile,-pre-compile, -copy-persistence-xml,-compile-depend" if="have.sources" name="-do-compile">
        <j2seproject3:javac gensrcdir="${build.generated.sources.dir}"/>
        <copy todir="${build.classes.dir}">
            <fileset dir="${src.dir}" excludes="${build.classes.excludes},${excludes}" includes="${includes}"/>
        </copy>
    </target>

以上部分在编译部分。

另一个需要注意的是,“保存时编译”在新系统中启用,但在旧系统中它是灰色的。在新系统中,我尝试过打开和关闭“保存时编译”,我得到了同样的错误。

我对构建在 Ant 和 Netbeans 中的工作方式不是很熟悉。所以我真的不确定我能用我有限的知识做些什么。任何帮助表示赞赏。

标签: javanetbeansbuildcompilation

解决方案


推荐阅读