@RequestMapping("/testJar")
public @ResponseBody String exteriorJar(int ys, int csd,int jg,int sf,int yf,int sd){
String result = "error";
//从数据库中读取算法类
String sql = "select EXTERIOR from T_EXTERIOR where id=2";
InputStream ins = null;
try{
Connection con = jdbcTemplate.getDataSource().getConnection();
Statement ps = con.createStatement();
ResultSet rs = ps.executeQuery(sql);
while(rs.next()){
Blob blob = rs.getBlob("EXTERIOR");
ins = blob.getBinaryStream();
}
File file = new File("test.jar");
OutputStream os = new FileOutputStream(file);
byte[] bt = new byte[1024];
int size = 0;
while((size=ins.read(bt))!=-1){
os.write(bt,0,size);
}
os.flush();
os.close();
ins.close(); URLClassLoader loader = new URLClassLoader(new URL[]{new URL("file:"+file.getAbsolutePath())});
Class cs = loader.loadClass("com.tf.userApp.bean.Exterior");
Object obj = cs.newInstance(); Method[] methods = obj.getClass().getMethods();
for(Method method : methods){
if(method.getName().equals("add")){
Class[] css = method.getParameterTypes();
Object[] params = new Object[css.length];
params[0] = ys;
params[1] = csd;
params[2] = jg;
params[3] = sf;
params[4] = yf;
params[5] = sd;
/**
int index = 0;
for(Class cs : css){
if(String.class == cs){
params[index++] = "String val is :" + index;
}
}*/
Object rt = method.invoke(obj, params);
if(rt.getClass() == Integer.class){
result = String.valueOf((Integer)rt);
}else if(rt.getClass()==String.class){
result = (String)rt;
}
}
}
}catch (Exception e) {
e.printStackTrace();
} return result;
}

java手动加载jar的更多相关文章

  1. java动态加载jar文件

    public static void main(String[] args) throws IllegalAccessException, IllegalArgumentException, Invo ...

  2. JAVA动态加载JAR包的实现

    如何动态的加载这些驱动!不可能把所有的数据库驱动都集成到JAR包中吧?!于是动态加载驱动的JAR包就产生了!其实这些在做系统基础代码时,经常用到,只是一般我们没有机会去搞而已. 动态加载JAR包,使用 ...

  3. Java动态加载jar及class文件

    经常碰到需要动态加载jar及class文件的场景.Java类由于需要加载和编译字节码,动态加载class文件较为麻烦,但JDK仍提供了一整套方法来动态加载jar文件和class文件. 一.动态加载ja ...

  4. tomcat/Java指定加载jar包的路径

    背景:部署的web站点,应用默认加载工程的/webapps/工程名/WEB-INF/lib下的jar包   但是我需要提供一个和web工程没关系的的jar包管理目录   解决方法: 执行java方法时 ...

  5. java动态加载jar包,并运行其中的类和方法

    动态加载jar包,在实际开发中经常会需要用到,尤其涉及平台和业务的关系的时候,业务逻辑部分可以独立出去交给业务方管理,业务方只需要提供jar包,就能在平台上运行. 下面通过一个实例来直观演示: 第一: ...

  6. JAVA动态加载JAR

    // 生成JAR包D:\TestClass.jar package hand.java.loadjar; public class TestClass { private String sayHell ...

  7. Java动态加载JAR包

    参考代码: package org; import java.io.File; import java.net.URL; import java.net.URLClassLoader; import ...

  8. JAVA动态加载JAR包执行程序

    入口代码 import java.io.File; import java.net.MalformedURLException; import java.net.URL; import java.ne ...

  9. 27 Java动态加载第三方jar包中的类

    我加载的方法是://参数fileName是jar包的路径,processorName 是业务类的包名+类名public static A load(String fileName, String pr ...

随机推荐

  1. Linux- systemd

    systemd被设计用来改进sysvinit的缺点,它和ubuntu的upstart是竞争对手,预计会取代它们.systemd的很多概念来源于苹果的launchd.创始人Lennart是redhat员 ...

  2. 32.NET中加密解密基本概念

    对消息的接收方来说,安全的交流方式需要同时满足3个条件: 1.完整性:消息在传输途中没有被篡改过,即消息是完好无损的. 2.保密性:接收放可以理解或解密来自发送方的信息.(不保证第三方无法获得,但保证 ...

  3. cocos2d-x 3.0 事件处理

    參考文章: star特530的CSDN博客:http://blog.csdn.net/star530/article/details/18325493 https://github.com/chuko ...

  4. LeetCode: Implement strStr() [027]

    [题目] Implement strStr(). Returns a pointer to the first occurrence of needle in haystack, or null if ...

  5. 对JVM还一知半解

    对JVM还一知半解?这篇文章让你彻底搞定JVM 摘要: 对于Java开发者来说,想把自身能力提升到更高层次,某些JVM相关知识应该是优先级很高的.比如说GC策略,JVM调优. 就我在工作中遇到的情况来 ...

  6. 计算Fisher vector和VLAD

    This short tutorial shows how to compute Fisher vector and VLAD encodings with VLFeat MATLAB interfa ...

  7. 我所遭遇过的游戏中间件---HumanIK

    我所遭遇过的游戏中间件---HumanIK Autodesk HumanIK游戏中间件,为游戏创建更加可信.真实的角色动画.该中间件的全身逆向运动(FBIK)系统支持角色真实地与所在环境及其它角色进行 ...

  8. TCP三次握手四次挥手相关问题探讨

    TCP的握手挥手和状态转换是很多网络问题的基础.在此进行相关问题的讨论及记录. 首先,这幅图大致介绍了TCP连接和断开的过程: 注意其中的几个状态: LISTEN, SYN-SEND, SYN-RCV ...

  9. UVA 10194 (13.08.05)

    :W Problem A: Football (aka Soccer)  The Problem Football the most popular sport in the world (ameri ...

  10. 【泛型】Generic 参数化类型 类型转换

    参考: http://blog.csdn.net/lonelyroamer/article/details/7864531#comments http://blog.csdn.net/lonelyro ...