简体   繁体   English

无法找到或加载主类,但是.class存在

[英]Could not find or load main class, but .class exists

I want to compile a bunch of .java files with a library .jar file. 我想用库.jar文件编译一堆.java文件。 Following this topic , my previous GUI program runs fine. 按照这个主题 ,我以前的GUI程序运行良好。 However, this command line program fails! 但是,此命令行程序失败!

$ /opt/jdk1.8.0_131/bin/javac -classpath lib/*.jar *.java
$ ls
Module1.class  Cross.class  Ora.java  Safe.class
Module1.java   Cross.java   p1/       Safe.java
lib/           Ora.class      
$ grep main Module1.java
   public static void main(String[] args) {
$ ls lib
jsoup-1.10.3.jar
$ /opt/jdk1.8.0_131/bin/java -classpath .:lib/* Module1
Error: Could not find or load main class Module1

How can I fix that? 我该如何解决?

Does Module1.java have no package statement? Module1.java是否没有package语句? If there is a package statement then it would need to be moved into the package folder and run with a command like 如果有一个package语句,则需要将其移到package文件夹中并使用类似以下的命令运行

/opt/jdk1.8.0_131/bin/java -classpath .:lib/* package.Module1

I didn't know classpath would support wildcards but looks like that added that in java 6 which shows how long since I have run java from the command line. 我不知道类路径是否支持通配符,但看起来像在Java 6中添加的通配符,它​​显示了我从命令行运行Java的时间。

Add the body of Module1.java to your question if you are not sure what I am asking. 如果不确定我要问的内容,则将Module1.java的正文添加到您的问题中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM