代码之家  ›  专栏  ›  技术社区  ›  Juliar Nasution

java.lang.ClassNotFoundException:com.mysql.jdbc.Driver如果项目内置到jar中

  •  1
  • Juliar Nasution  · 技术社区  · 7 年前

    我让我的项目使用NetBeans,当我通过NetBeans运行它时,它可以正常运行而没有任何错误。 但是,当我将它构建到一个jar文件并尝试登录到我的应用程序时,我得到了一个错误:

    error1

    在cmd中:

    error

    我一直在做什么 this 我已经阅读并遵循类似的教程,我的问题在这个网站和其他网站,但没有任何工作为我。

    这是我的图书馆: my library

    这是我的密码

     package config;
    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.SQLException;
    import java.sql.Statement;
    import javax.swing.JOptionPane;
    /**
     *
     * @author nasution
     */
    public class Koneksi {
        private static Connection koneksi;
        public static Statement stm;
    
        public static Connection getKoneksi() throws ClassNotFoundException{
            try{
                Class.forName("com.mysql.jdbc.Driver");
                    koneksi = DriverManager.getConnection("jdbc:mysql://localhost/db_surat","root","");
            }catch(SQLException e){
                JOptionPane.showMessageDialog(null, "koneksi gagal"+ e.getMessage());
            }
            return koneksi;
        }
    
    }
    

    这是我的项目,已转换为jar: project jar

    这是我在“dist/lib”文件夹中的库,它是在我构建项目时生成的 my library

    1 回复  |  直到 7 年前
        1
  •  2
  •   Karol Dowbecki    7 年前

    /META-INF/MANIFEST.MF manifest file . 如果你看 Adding Classes to the JAR File's Classpath 语法为:

    Class-Path: lib/mysql-connector-java-5.1.23-bin.jar
    

    /META-INF/清单.MF