Java動態加載JAR包


參考代碼:

package org;

import java.io.File;
import java.net.URL;
import java.net.URLClassLoader;
import java.sql.Connection;
import java.sql.Driver;
import java.util.Properties;

public class Test
{
    public static void main(String[] args) throws Exception
    {
        File file = new File("/root/workspace/RPT2.9SP1/WebContent/WEB-INF/lib/ojdbc14.jar");
        URLClassLoader loader = new URLClassLoader(new URL[]{ file.toURI().toURL() });
//URLClassLoader loader = new URLClassLoader(new URL[]{file.toURI().toURL()}, getClass().getClassLoader()) Class clazz
= loader.loadClass("oracle.jdbc.driver.OracleDriver"); Driver driver = (Driver) clazz.newInstance(); Properties p = new Properties(); p.put("user", "newrpt_plt"); p.put("password", "newrpt_plt"); Connection con = driver.connect("jdbc:oracle:thin:@10.0.1.204:1521:lgdnew", p); System.out.println(con); } }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM