Java “找不到主类。程序将退出”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/120662/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 08:30:27  来源:igfitidea点击:

"Could not find the main class. Program will exit"

javasquirrel-sql

提问by AJ.

I'm trying to run SQuirreL SQL.
I've downloaded it and installed it, but when I try to run it I get this error message:

我正在尝试运行 SQuirreL SQL。
我已经下载并安装了它,但是当我尝试运行它时,我收到以下错误消息:

Java Virtual Machine Launcher.
Could not find the main class.
Program will exit.

Java 虚拟机启动器。
无法找到主类。
程序将会退出。

I get the gist of this, but I have not idea how to fix it. Any help?

我明白了这个要点,但我不知道如何解决它。有什么帮助吗?

more info:

更多信息:

  • I'm on Windows XP pro.
  • I have java 1.6 installed, and other apps are running OK.
  • The install ran OK.
  • I believe I've followed the installation instructions correctly.
  • To run it, I'm invoking the squirrel-sql.batfile.
  • 我在 Windows XP 专业版上。
  • 我安装了 java 1.6,其他应用程序运行正常。
  • 安装运行正常。
  • 我相信我已经正确地遵循了安装说明。
  • 为了运行它,我调用了squirrel-sql.bat文件。

Update

更新

This question: "Could not find the main class: XX. Program will exit."gives some background on this error from the point of view of a java developer.

这个问题:“找不到主类:XX。程序将退出。” 从 Java 开发人员的角度提供了有关此错误的一些背景知识。

采纳答案by MB.

Is Java installed on your computer? Is the path to its bin directory set properly (in other words if you type 'java' from the command line do you get back a list of instructions or do you get something like "java is not recognized as a .....")?

您的计算机上是否安装了 Java?其 bin 目录的路径是否设置正确(换句话说,如果您从命令行输入“java”,您是否会返回指令列表,或者您是否会得到类似“java 未被识别为 .....”之类的信息? )?

You could try try running squirrel-sql.jarfrom the command line (from the squirrel sql directory), using:

您可以尝试squirrel-sql.jar从命令行(从 squirrel sql 目录)运行,使用:

java -jar squirrel-sql.jar

回答by tim_yates

Have you followed these instructions:

您是否遵循了以下说明:

http://www.squirrelsql.org/#installation

http://www.squirrelsql.org/#installation

If so, are you running the batch file or the shell script to run it?

如果是这样,您是运行批处理文件还是 shell 脚本来运行它?

回答by 18Rabbit

The classpath is the path that the system will follow when trying to find the classes that you're trying to run. In the batch file you're trying to execute it probably has a variable like CLASSPATH=blah;blah;etc or a java command that looks similar to

类路径是系统在尝试查找您尝试运行的类时将遵循的路径。在您尝试执行的批处理文件中,它可能有一个变量,如 CLASSPATH=blah;blah;etc 或一个看起来类似于的 java 命令

java -classpath "c:\directory\lib\squirrel-sql.jar" com.some.squirrel.package.file

If you can find or add that classpath setting, make sure that it includes a path to the squirrel-sql.jar and any other jar files that it may depend on separated by semicolons (or the root /lib directory that may be included with the installation).

如果您可以找到或添加该类路径设置,请确保它包含 squirrel-sql.jar 的路径以及它可能依赖的任何其他 jar 文件,用分号分隔(或可能包含在安装)。

Basically you just need to tell java where to find the class files that you're trying to execute. Wikipedia has a more indepth discussion about classpath and can offer you more insight. http://en.wikipedia.org/wiki/Classpath_(Java)

基本上,您只需要告诉 java 在哪里可以找到您要执行的类文件。维基百科对类路径进行了更深入的讨论,可以为您提供更多见解。http://en.wikipedia.org/wiki/Classpath_(Java)

回答by tropikalista

  1. JAVA_HOME variable must be set, to point to the prog files/java/version???/bin
  2. open squirrel-sql.bat file with some text editor and see if the JAVA_HOME variable there is the same as the one in your enviroment variable
  3. change it if it doesn't match....and than run bat file again
  1. 必须设置 JAVA_HOME 变量,指向 prog files/java/version???/bin
  2. 用一些文本编辑器打开 squirrel-sql.bat 文件,看看 JAVA_HOME 变量是否与环境变量中的变量相同
  3. 如果不匹配,请更改它....然后再次运行 bat 文件

回答by Nathan Feger

Tweaking MB's answer for windows, will get rid of the console window:

Tweaking MB's answer for windows,将摆脱控制台窗口:

start javaw -jar squirrel-sql.jar

回答by huug

The .bat file does not seem to work.

.bat 文件似乎不起作用。

Just double-click on:

只需双击:

squirrel-sql.jar

or type:

或输入:

java -jar squirrel-sql.jar

in the command-line.

在命令行中。

回答by Sohail Anwar

You can place .; in classpath in environmental variables to overcome this problem.

你可以放置 .; 在环境变量中的 classpath 中克服了这个问题。

回答by Patrick

I tried to start SQUirrel 3.1 but I received a message stating "Could not find the main class Files\Rational\ClearQuest\cqjni.jar" I noticed that C:\Program Files\Rational\ClearQuest\cqjni.jar is in my existing classpath as defined by the Windows environment variable, CLASSPATH.

我尝试启动 SQUirrel 3.1,但收到一条消息,指出“找不到主类 Files\Rational\ClearQuest\cqjni.jar” 我注意到 C:\Program Files\Rational\ClearQuest\cqjni.jar 在我现有的类路径中由 Windows 环境变量 CLASSPATH 定义。

SQUirrel doesn't need my existing classpath, so I updated the SQUirrel bat file, squirrel-sql.bat.

SQUirrel 不需要我现有的类路径,所以我更新了 SQUirrel bat 文件 squirrel-sql.bat。

REM SET SQUIRREL_CP=%TMP_CP%;%CLASSPATH%

REM SET SQUIRREL_CP=%TMP_CP%;%CLASSPATH%

SET SQUIRREL_CP=%TMP_CP%

设置 SQUIRREL_CP=%TMP_CP%

It no longer appends my existing classpath to its classpath and runs fine.

它不再将我现有的类路径附加到其类路径并且运行良好。

回答by Steve Gelman

I had this problem when I "upgraded" to Windows 7, which is 64-bit. My go to Java JRE is a 64-bit JVM. I had a 32-bit JRE on my machine for my browser, so I set up a system variable:

当我“升级”到 64 位的 Windows 7 时,我遇到了这个问题。我使用的 Java JRE 是 64 位 JVM。我的机器上有一个用于浏览器的 32 位 JRE,因此我设置了一个系统变量:

JRE32=C:\Program Files\Java\jre7

When I run:

当我运行时:

"%JRE32\bin\java" -version

I get:

我得到:

java version "1.7.0_51"
Java(TM) SE Runtime Environment (build 1.7.0_51-b13)
Java HotSpot(TM) Client VM (build 24.51-b03, mixed mode, sharing)

Which is a 32-bit JVM. It would say "Java HotSpot(TM) 64-Bit" otherwise.

这是一个 32 位 JVM。否则它会说“Java HotSpot(TM) 64-Bit”。

I edited the "squirrel-sql.bat" file, REMarking out line 4 and adding line 5 as follows:

我编辑了“squirrel-sql.bat”文件,重新标记第 4 行并添加第 5 行,如下所示:

(4) rem set "IZPACK_JAVA=%JAVA_HOME%"
(5) set IZPACK_JAVA=%JRE32%

And now everything works, fine and dandy.

现在一切正常,很好,很花哨。

回答by eby

I had the same issue with a different application (BI Publisher) because I installed a 32 bit version of this application on a 64 bit version of Windows.

我在使用不同的应用程序 (BI Publisher) 时遇到了同样的问题,因为我在 64 位版本的 Windows 上安装了此应用程序的 32 位版本。

Java Virtual Machine Launcher - could not find the main class

enter image description here

enter image description here

The solution for my case was to tell BI Publisher where to find the x86 version of JRE:

我的情况的解决方案是告诉 BI Publisher 在哪里可以找到 x86 版本的 JRE:

enter image description here

enter image description here