`

jar文件Could not find the main class解决办法

    博客分类:
  • JAVA
阅读更多
辛辛苦苦写了个java的DES字符加解密程序,准备送给朋友的,做完导出成JAR文件,却发现不能运行。Could not find the main class:Mycipher.jar Program will exit.郁闷大了,之前做个很多的jar文件都能运行的,这次确不行,上网搜了搜,问的一大堆,却没真正解决问题的原因,决定自己动手了。
程序再Eclipse中能运行,程序肯定没有问题,用Eclipse的向导导出应该也不会有问题,唉,直接执行不了,到cmd试一下,java -jar MyCipher.jar,报错了,一看错误,是某个类找不到,这个类是我应用的jar文件里的,这让我想到了jvm的类装载机制,一定是类装载器在当前路径里找不到我引入的jar文件里的类。终于让我发现的问题的真正原因。

解决办法:
1.把lib目录里的jar文件一一解压,把解压后的类文件连同目录添加到Mycipher.JAR文件中,很easy的搞定。
2.修改MANIFEST.MF文件的Class-Path属性的值(目录路径用/或者.代替,jar之间用空格分开)如:Class-Path: ../lib/miglayout-3.5.5.jar  ../lib/TableLayout.jar  ../lib/swing-layout-1.0.jar,同时把用到的jar文件放到指定的路径下。

JAR文件的详解
http://www.ibm.com/developerworks/cn/java/j-jar/
4
0
分享到:
评论
2 楼 xsmmk 2011-10-13  
我下载了怎么运行部了哦
1 楼 150312q 2011-08-23  

相关推荐

    Could not find the main class

    当我们添加这个 JAR 文件到 MyEclipse 8.5 的 Tomcat 配置中时,服务器就可以正确地找到主类,解决 "Could not find the main class" 的错误。 结论 通过添加 Tomcat 7.0 的 "tomcat-juli.jar" 包,我们可以解决 ...

    could not find the main class,program will exit

    ### "Could Not Find the Main Class, Program Will Exit" 错误解析及解决方法 在Java编程过程中,我们经常会在开发环境中遇到各种各样的错误提示,其中“Could not find the main class, program will exit”是一...

    WIN7下运行Jar文件提示Could not find the main class

    在Windows 7系统下运行Java应用包(JAR文件)时遇到“Could not find the main-...通过上述步骤,可以有效解决在Windows 7系统下运行JAR文件时出现的“Could not find the main-class”错误,使应用程序能够顺利启动。

    jd-gui-1.4.0

    java反编译工具jd-gui, 1.4.0版本, 使用方式: 打开的文件应该为类似jar包文件,而不是单独的Class文件

    java打jar包的方法

    ### Java打包成JAR文件的方法及解决“Could not find the main class, Program will exit”错误 在Java开发中,将程序打包成一个可执行的JAR文件是非常常见且实用的操作。这种方式不仅便于程序的分发与部署,还能...

    sqoop-1.4.7.jar

    解决错误:Could not find or load main class org.apache.sqoop.Sqoop。把这个sqoop-1.4.7.jar放到sqoop根目录下的lib目录中,即可。 如果你没有积分,也可以自己去这个地址下载:...

    IDEA打包jar-解决找不到或无法加载主类 main的问题

    本文将详细讲解如何在IDEA中正确打包jar文件,并解决这个常见的问题。 首先,我们来理解这个问题的原因。当Java运行时系统尝试执行jar文件时,它需要找到一个名为`main`的方法,该方法定义在主类中,通常以`public ...

    人大金仓驱动包kingbasejdbc.jar V8.6.0、8.8.0驱动jar包

    ${basedir}/src/main/resources/jar/kingbase8-8.6.0.jar jdbc driver-class-name: com.kingbase8.Driver url: jdbc:kingbase8://127.0.0.1:54321/template1?characterEncoding=utf8 username: system password: ...

    连接sqlserver的驱动以及jar文件

    System.out.println("Could not find the driver."); e.printStackTrace(); } catch (SQLException e) { System.out.println("Error connecting to the database."); e.printStackTrace(); } } } ``` 请根据...

    打jar包注意点.docx

    1. **`<mainClass>`**: 指定运行JAR包时的主类,即程序的入口点。必须提供完整的类名,包括包名。 2. **`<addClasspath>true</addClasspath>`**: 表示需要在生成的JAR文件中包含一个类路径,使得运行时能够找到依赖...

    myEclipse工程打包及exe文件制作

    如果你遇到"could not find main class"的错误,很可能是因为manifest文件中的Main-Class配置不正确。 在完成以上步骤后,通过组合使用myEclipse的jar打包、Launch4j的exe制作和ResHacker的资源编辑,你就能成功地...

    oracle ojdbc6-11.2.0.3.jar

    Oracle是世界上最流行的关系型数据库管理系统之一,而ojdbc6-11.2.0.3.jar是Oracle公司为Java开发者提供的一个关键组件,用于在Java应用程序中与Oracle数据库进行交互。这个jar包是Oracle JDBC驱动程序的一个版本,...

    DB2 11.5版本 jdbc db2jcc db2jcc4驱动

    5. **db2dbgm.jar**:可能涉及到DB2的调试工具或功能,帮助开发者诊断和解决数据库问题。 6. **db2ext.jar**:扩展库,可能包含了额外的功能或对特定数据库特性的支持。 7. **db2qgjdbc.jar**:与db2qgjava.jar...

    eclipse 下打包

    - **Could not find the main class, Program will exit.** - 当遇到这类问题时,通常是因为JAR文件缺少必要的类或库。如果项目中使用了特殊库(如SWT等),则需要进行额外的配置。 4. **处理SWT等特定库的情况**...

    commons-httpclient-3.0.jar JAVA中使用HttpClient可以用到

    《JAVA中使用HttpClient:commons-httpclient-3.0.jar详解》 在JAVA开发中,进行HTTP请求时,Apache的HttpClient库是一个不可或缺的工具。本文将深入解析`commons-httpclient-3.0.jar`,它是HttpClient的一个重要...

    SQLserver2000-jar包

    System.out.println("Could not find the driver."); e.printStackTrace(); } catch (SQLException e) { System.out.println("Error connecting to the database."); e.printStackTrace(); } } } ``` 请注意...

    aspose-words-15.8.0-jdk16 jar包

    public static void main(String[] args) throws Exception { // 加载Word文档 Document doc = new Document("input.docx"); // 添加水印 DocumentBuilder builder = new DocumentBuilder(doc); TextFragment...

    linux上实现视频截图

    java -Djava.library.path=/path/to/your/libs -jar yourapp.jar ``` 现在,可以编写Java代码来实现视频截图功能。下面是一个简单的示例: ```java import org.bytedeco.javacpp.*; import org.bytedeco.ffmpeg....

    达梦 6 数据库驱动 jar 包

    System.out.println("Could not find the driver."); e.printStackTrace(); } catch (SQLException e) { System.out.println("Failed to connect to the database."); e.printStackTrace(); } } } ``` 在上述...

Global site tag (gtag.js) - Google Analytics