我尝试了很多配置和参数设置,但一直收到Error: Could not find or load main class Main
错误。
我从其他SO问题和蚂蚁项目的文档中复制了大部分代码,但我并没有真正看到问题所在。也许有人可以看到我忽略的东西。
目录结构
├───build
│ ├───com
│ │ └───cfsware
│ │ └───osco
│ │ └───test
│ └───META-INF
├───dist
│ └───lib
└───src
└───com
└───cfsware
└───osco
└───test
build.properties
main.dir=.
src.dir=${main.dir}/src
build.dir=build
classes.dir=${build.dir}/classes
jar=${build.dir}/test.jar
javadoc.dir=${build.dir}/javadoc
build.sysclasspath=ignore
# E.g.: cp=lib/x.jar:lib/y.jar
cp=
extra.run.cp=
main.class=com.cfsware.osco.test.Main
run.cp=${cp}:${classes.dir}:${extra.run.cp}
debug=true
deprecation=false
nbjdk.home=${basedir}/../../..
的build.xml
<?xml version="1.0" encoding="UTF-8"?>
<project name="ant" default="dist" basedir=".">
<description>ant build file</description>
<property name="src" location="src"/>
<property name="build" location="build"/>
<property name="dist" location="dist"/>
<target name="init"><tstamp/><mkdir dir="${build}"/></target>
<target name="compile" depends="init" description="compile the source"><javac srcdir="${src}" destdir="${build}"/></target>
<target name="dist" depends="compile">
<mkdir dir="${dist}/lib" />
<manifest file="${build}/META-INF/MANIFEST.MF">
<attribute name="Class-Path" value="test.jar"/>
<attribute name="Main-Class" value="Main"/>
</manifest>
<jar manifest="${build}/META-INF/MANIFEST.MF" jarfile="${dist}/lib/test.jar" basedir="${build}"/>
</target>
<target name="clean" description="clean up"><delete dir="${build}"/><delete dir="${dist}"/></target>
</project>
Main.java
package com.cfsware.osco.test;
public class Main{
public static void main(String[] args) throws Exception{
}
}
答案 0 :(得分:0)
我怀疑这是问题所在:
<attribute name="Main-Class" value="Main"/>
应该是:
<attribute name="Main-Class" value="com.cfsware.osco.test.Main"/>
...换句话说,该类的完全限定名称。您的Java文件也应该位于与包声明匹配的目录中。