解决方案 »
- jsp struts2一次上传多张图片
- 这个资源文件如何读取???
- lucene错误,请教是什么问题
- sql注入攻击?
- 用户登录后将用户id用session共享并sendRedirect到一个页面,当在到下个页面时,session中的对象确消失了,这个怎么解决!谢谢
- 一个初学的问题,希望大家帮忙,谢谢
- struts如何獲得一組單選框的值?
- 请教取javabean里过程返回值,jsp调用出错,谢谢!
- [求助]jsp的中文问题?(急!!!)
- 请问,如果安装了JBUIDER是否就自动安装了TOMCAT?
- deploy myeclipse j2ee project to server
- 菜鸟求助Service层Dao层的说法是基于MVC模式的吗
/**
* Loads the class with the specified binary name.The default implementation
* throws a ClassNotFoundException.
*
* @param classData
* The data of the class.
* @param className
* The binary name of the class.
*
* @return The resulting Class object.
*
* @throws ClassNotFoundException
* If the class could not be found.
*/
public Class loadClass(byte[] classData, String className)
throws ClassNotFoundException {
System.out.println("MyClassLoader is loading : " + className + "");
Class c = defineClass(className, classData, 0, classData.length);
loadClassHashTable.put(className, c);
System.out.println("Complete to load the class :" + className);
return c;
}
/** */
/**
* Loads the class with the specified binary name.The default implementation
* throws a ClassNotFoundException.
*
* @param className
* The binary name of the class.
* @param jarName
* The binary name of the jar that search the class from it.
*
* @return The resulting Class object.
*
* @throws ClassNotFoundException
* If the class could not be found.
*/
public Class loadClass(String className, String jarName)
throws ClassNotFoundException {
String jarPath = searchFile(myClasspath, jarName + ".jar");
System.out.println(jarPath);
JarInputStream in = null;
System.out.println(111111111);
if (!(jarPath == null || jarPath == "")) {
try {
in = new JarInputStream(new FileInputStream(jarPath));
System.out.println(22222222);
JarEntry entry;
while ((entry = in.getNextJarEntry()) != null) {
String outFileName = entry.getName().substring(
entry.getName().lastIndexOf("/") + 1,
entry.getName().length());
if (outFileName.equals(className + ".class")) {
if (entry.getSize() == -1) {
System.err.println("error : can't read the file!");
return null;
}
byte[] classData = new byte[(int) entry.getSize()];
System.out
.println("It have found the file : "
+ className
+ ". Begin to read the data and load the class。");
in.read(classData);
return loadClass(classData, className);
}
}
System.out.println("Haven't found the file " + className
+ " in " + jarName + ".jar.");
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
in.close();
} catch (IOException e) {
e.printStackTrace();
}
}
} else {
System.out.println("Haven't found the jarFile: " + jarName
+ ".jar.");
return null;
}
return null;
}
/** */
/**
* Reloads the class with the specified binary name. Needn't have to restart
* JVM then reload the class.
*
* @param className
* The binary name of the class need to reload .
*
* @return The resulting Class object.
*
* @throws ClassNotFoundException
* If the class was not found.
*/
public Class reload(String fileName) {
String filePath = searchFile(myClasspath, fileName + ".class");
Long a = new File(filePath).lastModified();
if (!a.equals(loadClassTime.get(fileName))) {
loadClassHashTable.remove(fileName);
loadClassTime.remove(fileName);
try {
MyClassLoader mc2 = new MyClassLoader(myClasspath);
mc2.loadClass(fileName);
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
} else {
System.out
.println("The class is the newest version , needn't reloading.");
}
return null;
}
/** */
/**
* search the file with the specified binary name. Needn't have to restart
* JVM then reload the class.
*
* @param classpath
* the specified path where we search.
* @param fileName
* The binary name of the file that want to search.
*
* @return The resulting file path.
*/
public String searchFile(String classpath, String fileName) {
String cut = fileName.substring(fileName.lastIndexOf('.'), fileName
.length());
String path = fileName.substring(0, fileName.lastIndexOf('.')).replace(
'.', '/')
+ cut;
File f = new File(classpath + path);
if (f.isFile()) {
return f.getPath();
} else {
String objects[] = new File(classpath).list();
for (int i = 0; i < objects.length; i++) {
if (new File(classpath + File.separator + objects[i])
.isDirectory()) {
String s = searchFile(classpath + objects[i]
+ File.separator, fileName);
if (s == null || s == "") {
continue;
} else {
return s;
}
}
}
}
return null;
};
}