zoukankan      html  css  js  c++  java
  • 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); } }
  • 相关阅读:
    Easy Code 自定义的模板
    LINUX批量修改文件名
    解决FTP登录太慢
    linux 命令
    Linux rename命令
    MySQL字段重复出现多少次
    kafka安装
    Redis 5.0简单安装
    Tomcat常用配置
    jenkins安装和简单配置
  • 原文地址:https://www.cnblogs.com/qingwen/p/5311643.html
Copyright © 2011-2022 走看看