简体   繁体   English

如何为 JAR 文件参数设置类路径

[英]How to set classpath for JAR file paermanenlty

There are thousands of materials on the internet.互联网上有成千上万种材料。 I followed some of the trusted sources but still I'm getting this error:我遵循了一些受信任的来源,但仍然收到此错误:

java.lang.ClassNotFoundException: oracle.jdbc.driver.OracleDriver java.lang.ClassNotFoundException: oracle.jdbc.driver.OracleDriver

I'll quickly show you what I've tried:我会很快向你展示我的尝试:

Added classpath in environment variables在环境变量中添加类路径

在此处输入图片说明

在此处输入图片说明

Then I tried adding with command prompt also with this command:然后我尝试使用命令提示符添加以下命令:

set classpath=%classpath%;C:Users\\320050772\\Documents\\task-tracker\\*.jar

在此处输入图片说明

But still I'm getting this error:但我仍然收到此错误:

在此处输入图片说明

Either I'm not doing this correctly or I'm missing an important step here.要么我没有正确地做这件事,要么我在这里错过了一个重要的步骤。 Please correct me.请纠正我。

Here's is my DataService.java这是我的DataService.java

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

public class DataService {
    public static void main(String args[]){
        try {
            Class.forName("oracle.jdbc.driver.OracleDriver");
            Connection con=DriverManager.getConnection(
            "jdbc:oracle:thin:@localhost:1521:xe","system","scott");
            Statement stmt=con.createStatement();
            ResultSet rs=stmt.executeQuery("select * from emp");
            while(rs.next())
            System.out.println(rs.getInt(1)+"  "+rs.getString(2));
            con.close();
        }
        catch(Exception e){ 
            System.out.println(e);
        }
    }
}

From the java docs:从java文档:

Class path entries that are neither directories nor archives (.zip or JAR files) nor the asterisk (*) wildcard character are ignored.既不是目录也不是档案(.zip 或 JAR 文件)也不是星号 (*) 通配符的类路径条目将被忽略。

My advise is to replace "*.jar" with concrete .jar - File references.我的建议是用具体的 .jar - 文件引用替换“*.jar”。 Please double check the output of echo %CLASSPATH% (Windows) or echo $CLASSPATH (Linux and related OS)请仔细检查echo %CLASSPATH% (Windows) 或echo $CLASSPATH (Linux 和相关操作系统) 的输出

Java Documentation 1.8: Setting the Class Path Java 文档 1.8:设置类路径

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

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