Java &引用;无法加载com.apple.laf.AquaLookAndFeel“;使用Ant执行JAR文件时出错
我有一个Ant文件:Java &引用;无法加载com.apple.laf.AquaLookAndFeel“;使用Ant执行JAR文件时出错,java,macos,swing,ant,Java,Macos,Swing,Ant,我有一个Ant文件: <?xml version="1.0"?> <project name="tetris" default="all" basedir="."> <description> simple example build file </description> <!-- set global properties for this build --> <property name="name"
<?xml version="1.0"?>
<project name="tetris" default="all" basedir=".">
<description>
simple example build file
</description>
<!-- set global properties for this build -->
<property name="name" value="tetris"/>
<property name="src" location="src"/>
<property name="bin" location="bin"/>
<property name="dist" location="dist"/>
<property name="classpath" value="${dist}/${name}.jar"/>
<property name="main" value="com.els.test.Game"/>
<target name="init">
<!-- Create the time stamp -->
<tstamp/>
<!-- Create the bin directory structure used by compile -->
<mkdir dir="${bin}"/>
</target>
<target name="compile" depends="init"
description="compile the source">
<!-- Compile the java code from ${src} into ${bin} -->
<javac srcdir="${src}" destdir="${bin}" debug="on" deprecation="on"/>
</target>
<target name="dist" depends="compile"
description="generate the distribution">
<!-- Create the distribution directory -->
<mkdir dir="${dist}"/>
<!-- Put everything in ${bin} into the MyProject-${DSTAMP}.jar file -->
<!-- <jar jarfile="${dist}/MyProject-${DSTAMP}.jar" basedir="${bin}"/> -->
<jar jarfile="${dist}/${name}.jar" basedir="${bin}"/>
</target>
<target name="run" depends="dist"
description="Run the program">
<java classname="${main}"
classpath="${classpath}"/>
</target>
<!-- Delete the ${bin} directory trees -->
<target name="clean"
description="clean up">
<delete dir="${bin}"/>
<mkdir dir="${bin}"/>
<delete dir="${dist}"/>
<mkdir dir="${dist}"/>
</target>
<target name="all" depends="clean,compile,dist,run"/>
</project>
build.xml文件怎么样了?我正在macOS Catalina 10.15.1上运行JDK.Java.net中的Java JDK-14和Ant.apache.org中的Ant apache-Ant-1.10.7。在build.xml中为java任务添加fork=“true”解决了这个问题。build.xml文件附在下面:
<project name="Threads" default="dist" basedir=".">
<description>
Decision screen.
</description>
<property name="src" location="sources"/>
<property name="build" location="classes"/>
<property name="dist" location="dist"/>
<property name="resources" location="resources"/>
<target name="init">
<tstamp/>
<mkdir dir="${build}"/>
<mkdir dir="${dist}"/>
</target>
<target name="compile" depends="init" description="compile the source">
<!-- Compile the Java code from ${src} into ${build} -->
<javac srcdir="${src}" destdir="${build}" includeantruntime="false"/>
</target>
<target name="DecisionScreen" depends="compile" description="Run program DecisionScreen">
<!-- HERE IS THE CHANGE -->
<java classname="Decision.DecisionScreen" fork="true">
<classpath>
<pathelement path="${build}"/>
</classpath>
</java>
</target>
<target name="dist" depends="compile" description="generate the distribution">
<!-- Create the distribution directory -->
<mkdir dir="${dist}/lib"/>
<jar jarfile="${dist}/lib/Decision-${DSTAMP}.jar" basedir="${build}">
<manifest>
<attribute name="Main-Class" value="Decision.DecisionScreen"/>
</manifest>
</jar>
</target>
<target name="clean" description="clean up">
<!-- Delete the ${build} and ${dist} directory trees -->
<delete dir="${build}"/>
<delete dir="${dist}"/>
</target>
</project>
“java.lang.Error:无法加载apple.laf.AquaLookAndFeel”不再出现。您是否验证了Ant使用的是哪个java版本,以及是否在提示符下运行程序?如果是,您是否尝试使用不同的Java版本?
$ ant DecisionScreen
$ java -cp classes Decision.DecisionScreen
$ java -jar dist/lib/Decision-20200306.jar