码迷,mamicode.com
首页 > 编程语言 > 详细

Java动态加载JAR包

时间:2016-03-23 16:50:35      阅读:203      评论:0      收藏:0      [点我收藏+]

标签:

参考代码:

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); } }

 

Java动态加载JAR包

标签:

原文地址:http://www.cnblogs.com/qingwen/p/5311643.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!