无法从双击运行jar文件

无法从双击运行jar文件

本文介绍了无法从双击运行jar文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我双击我的jar文件,我得到找不到主类:HelloWorld。程序将退出。

If I double-click on my jar file, I get "Could not find the main class: HelloWorld. Program will exit."

当我运行它命令行为java -jar HelloWorld.jar它工作正常。

When I run it from the command line as "java -jar HelloWorld.jar" it works fine.

它也可以从Eclipse运行。

It also runs fine from the Eclipse.

其他没有我写的jar文件可以运行双击。

Other jar files, not written by me, run fine from the double click.

我将CLASSPATH变量设置为。并将jdk路径添加到PATH变量中。

I have set CLASSPATH variable to "." and added the jdk path to the PATH variable.

我已经检查过jar是否与javaw.exe相关联

I have checked that jars are associeted with the javaw.exe

要制作一个jar文件,我使用Eclipse-> File->导出 - > Java-> Runnable JAR文件 - >当前项目的启动配置&第一个单选按钮 - >完成

To make a jar file I'm using Eclipse->File->Export->Java->Runnable JAR file->Current project's launch configuration & the first radio button->finish

此外,其他人在尝试运行我的jar时也会收到相同的错误。

Also, other people get the same error when trying to run my jar.

推荐答案

创建jar文件并不是很困难。但是创建一个可启动的jar文件需要更多的步骤:创建一个包含start类的清单文件,创建目标目录并归档文件。

Creating a jar-file is not very difficult. But creating a startable jar-file needs more steps: create a manifest-file containing the start class, creating the target directory and archiving the files.

echo Main-Class: oata.HelloWorld>myManifest
md build\jar
jar cfm build\jar\HelloWorld.jar myManifest -C build\classes .
java -jar build\jar\HelloWorld.jar

检查:

这篇关于无法从双击运行jar文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 18:47