[英]Java compilation error: could not find or load main class Main
I've tried many configurations and parameter settings, but keep getting Error: Could not find or load main class Main
error. 我已经尝试了许多配置和参数设置,但是一直得到Error: Could not find or load main class Main
错误。
Most of the code I've copied from other SO questions and the documentation of the ant project, and I don't really see where the issue lies. 我从其他SO问题和ant项目的文档中复制的大多数代码,但我并没有真正看到问题所在。 Perhaps someone can see what I'm overlooking. 也许有人可以看到我所忽略的东西。
Directory structure 目录结构
├───build
│ ├───com
│ │ └───cfsware
│ │ └───osco
│ │ └───test
│ └───META-INF
├───dist
│ └───lib
└───src
└───com
└───cfsware
└───osco
└───test
build.properties 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 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 Main.java
package com.cfsware.osco.test;
public class Main{
public static void main(String[] args) throws Exception{
}
}
I suspect this is the problem: 我怀疑这是问题所在:
<attribute name="Main-Class" value="Main"/>
It should be: 它应该是:
<attribute name="Main-Class" value="com.cfsware.osco.test.Main"/>
... in other words, the fully-qualified name of the class. ...换句话说,是班级的全限定名。 Your Java file should be in a directory matching the package declaration, too. 您的Java文件也应位于与包声明匹配的目录中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.