今天在使用Java动态加载odbc Jar得到odbc驱动名字的时候,报错了,错误信息如下:
java.lang.SecurityException: sealing violation: package oracle.net.ns is sealed at java.net.URLClassLoader.defineClass(URLClassLoader.java:227) at java.net.URLClassLoader.access$000(URLClassLoader.java:56) at java.net.URLClassLoader$1.run(URLClassLoader.java:195) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:188) at java.lang.ClassLoader.loadClass(ClassLoader.java:307) at java.lang.ClassLoader.loadClass(ClassLoader.java:252) at com.huse.dyjar.得到驱动名字.getDriverName(得到驱动名字.java:47) at com.huse.dyjar.得到驱动名字.main(得到驱动名字.java:17)
代码如下:
import java.io.File; import java.lang.reflect.Modifier; import java.net.URL; import java.net.URLClassLoader; import java.util.ArrayList; import java.util.Enumeration; import java.util.List; import java.util.jar.JarEntry; import java.util.jar.JarFile; public class 得到驱动名字 { public static void main(String[] args) { List<String> list = new ArrayList<String>(); File fs = new File("E:/新版lib/odbc15.jar"); getDriverName(fs, list); for (String str : list) { System.out.println(str); } } public static void getDriverName(File fs, List<String> list) { if (!fs.getName().endsWith(".zip") && !fs.getName().endsWith(".jar")) { return; } try { URLClassLoader urlClassLoader = new URLClassLoader(new URL[] { fs .toURI().toURL() }); JarFile zip = new JarFile(fs); Enumeration<JarEntry> enu = zip.entries(); String className; String tempName; while (enu.hasMoreElements()) { JarEntry entry = (JarEntry) enu.nextElement(); if (!entry.isDirectory()) { if ((tempName = entry.getName()).endsWith(".class") && tempName.indexOf("$") == -1) { // 将驱动类路径中的/替换成. className = tempName.substring(0, tempName.lastIndexOf(".class")).replaceAll("/", "."); // 这个异常一般是由于classpath中有多个jar包都包含同样的java包,比如oracle.net.ns // sealing violation: package oracle.net.ns is sealed if (!"".equals(className)) { Class c = null; c = urlClassLoader.loadClass(className); if (java.sql.Driver.class.isAssignableFrom(c)// 判断驱动类是java.sql.Driver的子类 && !Modifier.isAbstract(c.getModifiers())) {// 判断驱动类是否为一个抽象类 list.add(className); } } } } } } catch (Exception e) { e.printStackTrace(); } catch (Error ex) { // ex.printStackTrace(); } } }
这个错误是因为classpath中有多个jar包都包含同样的java包,比如oracle.net.ns,说明白点就是classpath下面有类似jar存在,如odbc6.jar。
全文完。
相关推荐
lotus 本地运行1,lotus 本地运行2,16核 1,lotus 本地运行 # lotus-storage-miner info ...2020-02-03T21:24:32.671+0800 INFO sectors sealing/states.go:16 performing filling up rest of the sect
2014最新文件压缩器,进行完美加密数据,不解压无法查看被压缩的文件, 可以解压使用该软件压缩的.sp压缩包.
2020-01-25T14:34:35.251+0800 INFO sectors sealing/states.go:16 performing filling up rest of the sector... {sector: 10} 2020-01-25T14:34:35.281+0800 INFO sectors sealing/states.go:47
基于双重水印技术的数字签章技术,赵磊,滕璇,将自适应性鲁棒水印和简化的脆弱水印相结合就产生了数字签章技术。印章和传统印章在外表上是一样的,它对高斯噪声、中值滤波、JPE
This Geological Society Special Publication is the result of a highly successful joint SEPM and Geological Society conference held in February 2005 in Houston, Texas. The papers attempt to capture the...
But because the gear relative to the bearing of the two-stage cylindrical gear reducer is arranged asymmetrically, the load distribution along the tooth direction is uneven, and the shaft stiffness ...
Table of Contents 1. Grounding and Planes...................................................................................................... 7 1.1 Filters .............................................
AB PLC例程_本资料仅供学习参考
BS EN 16119-2021 LPG equipment and accessories. Sealing caps and plugs for LPG cylinder and pressure vessel valves.pdf
The requirements of sealing for optical windows and laser cavity mirrors are briefly discussed in this paper and several sealing ...mirrors is described and some sealing characteristics are presented.
The assembly of components in the aerospace industry is currently supported through procedures based on the generation of work instructions. This documentation describes both the sequence of ...
BS EN 16119-2021 LPG equipment and accessories. Sealing caps and plugs for LPG cylinder and pressure vessel valves.pdf
美军标,This specification covers the requirements for electrical silicone rubber sealing compounds that are not resistant to fuel. These compounds are intended for use in the temperature range of -62 ...
API STD 614-2022 LUBRICATION ,Shaft-sealing,and Oil-control systems and auxiliaries.pdf
A glass directly sealed with tungsten at high temperatures is introduced. A brief description of the glass composition, performances and mechanism for sealing with tungsten is given.
• All are for general duty applications and environmental sealing is achieved with the grommet and clamp design. • Operating temperature is from –55°C to +125°; Operating voltage to 1000 VAC (RMS...
固体氧化物燃料电池封接玻璃中的Cr(VI)形成,张腾,Richard K. Brow,固体氧化物燃料电池的玻璃陶瓷封接材料与含铬铁素体型连接体之间的高温反应导致有害相如BaCrO或者SrCrO4的生成,从而引起电池的机械�
本论文来自IEEEE,使用请注明出处。Reliability performance of split seal technology when combined with a centrifugal flow device
中温固体氧化物燃料电池封接玻璃的结构与封接性能:TiO2含量对TiO2-CaO-SrO-B2O3-SiO2玻璃体系的影响,张腾,陈嘉琳,本文中,TiO2作为CaO-SrO-B2O3-SiO2玻璃体系的形核添加剂,通过改变体系的结晶过程来调整微晶...
2、机器人的用途 Arc welding(弧焊),Spot welding(点焊),Handing(搬运),Sealing(涂胶),Painting(喷 漆),去毛刺,切割,激光焊接.测量等. 4. 实验步骤 1. 熟悉机器人的各组成部分及各部分的功能。 2. 熟悉机器人的各个...