Ant 无法构建 org.json,org.json 确实有效

Ant fails to build org.json, org.json does work

我已经测试了 org.json 是否通过一个非常基本的项目(实际上是一个 class 就这样)正确安装了,所以我知道问题一定出在我尝试构建我的项目时ant.

的项目

我只找到一个与我的问题相同的问题,但没有解决。

我就是这样安装的org.jsonhttps://www.tutorialspoint.com/org_json/org_json_environment.htm

我的 build.xml 长什么样:

<project name="Tracer" default="dist">
    <property file="build.properties"/>
    <property file="${user.home}/build.properties"/>

    <path id="run.classpath">
        <fileset dir="${dist.dir}">
            <include name="${project.name}.jar"/>
        </fileset>
    </path>

    <target name="compile">
        <mkdir dir="${build.dir}"/>
        <mkdir dir="${build.dir}/assets"/>
        <javac srcdir="${src.dir}/nhl"
               destdir="${build.dir}"
               debug="${compile.debug}"
               deprecation="${compile.deprecation}"
               optimize="${compile.optimize}">
            <classpath>
                <pathelement path="C:/JSON/json-20210307.jar"/><!-- tried an absolute path to my jar -->
            </classpath>
        </javac>

    </target>

    <target name="dist" depends="compile">
        <mkdir dir="${dist.dir}"/>
        <jar jarfile="${dist.dir}/${project.name}.jar"
             basedir="${build.dir}"
             manifest="${src.dir}/Manifest.mf"/>
    </target>

    <target name="build" depends="dist">
        <java jar="${dist.dir}/${project.name}.jar" fork="true">
        </java>
    </target>

    <target name="clean">
        <delete dir="${build.dir}"/>
        <delete dir="${dist.dir}"/>
    </target>
</project>

我得到的错误:

 [java] Exception in thread "main" java.lang.NoClassDefFoundError: org/json/JSONTokener
 [java]     at (...).main(Unknown Source)
 [java] Caused by: java.lang.ClassNotFoundException: org.json.JSONTokener
 [java]     at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:636)
 [java]     at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:182)
 [java]     at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:519)

如果重要的话,我在使用 ant 时使用 git-bash

我也完成了 reference libraries 部分。

<project name="RayTracer" default="dist">
    <property file="build.properties"/>
    <property file="${user.home}/build.properties"/>
    <property name="prop1" value="Property 1 from Buildfile"/>// in case you want to set default system properties
    <property name="prop2" value="Property 2 from Buildfile"/>

<path id="run.classpath">
    <fileset dir="${dist.dir}">
        <include name="${project.name}.jar"/>
    </fileset>
</path>

<target name="compile">
    <mkdir dir="${build.dir}"/>
    <mkdir dir="${build.dir}/assets"/>
    <javac srcdir="${src.dir}/nhl"
           destdir="${build.dir}"
           debug="${compile.debug}"
           deprecation="${compile.deprecation}"
           optimize="${compile.optimize}"
           includeantruntime="false">
            <classpath>// compile all JAR files in the src/libs/JSON directory
                <fileset dir="${src.dir}/libs/JSON">
                    <include name="**/*.jar" />
                </fileset>
            </classpath>
    </javac>
</target>

<target name="dist" depends="compile">
    <mkdir dir="${dist.dir}"/>
    <jar jarfile="${dist.dir}/${project.name}.jar"
         basedir="${build.dir}"
         manifest="${src.dir}/Manifest.mf">
         <zipgroupfileset dir="${src.dir}/libs/JSON" includes="**/*.jar"/>// use the file
    </jar>
</target>

<target name="build" depends="dist">
    <java jar="${dist.dir}/${project.name}.jar" fork="true">
        <!-- <sysproperty key="prop1" value="${prop1}"/> --> //set system property when providing argument
        <arg value="${arg0}"/> // provide arguments without using system properties
        <arg value="${arg1}"/>
    </java>
</target>

<target name="clean">
    <delete dir="${bin.dir}"/>
    <delete dir="${build.dir}"/>
    <delete dir="${dist.dir}"/>
    <delete file="output.bmp"/>
</target>