package com.nantian.iwapdesigner.transactioneditor.util;
import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.Set;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.launching.JavaRuntime;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.part.FileEditorInput;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.ide.eclipse.beans.core.internal.model.Bean;
import org.springframework.ide.eclipse.beans.core.model.IBean;
import org.springframework.ide.eclipse.beans.core.model.IBeansConfig;
import org.springframework.ide.eclipse.beans.core.model.IBeansProject;
import com.nantian.iwapdesigner.transexplorer.model.IWAPBeansModel;
/**
* Class Helper to load class of java project.
*
* @author elvis refelction part
*
*
*/
public class ClassUtil {
private static final String PROTOCAL_PREFIX = "file:///";
public static Class loadClass(IJavaProject project, String className)
throws CoreException, ClassNotFoundException, MalformedURLException {
ClassLoader loader = getProjectClassLoader(project);
Class clazz = loader.loadClass(className);
loader = null;
return clazz;
}
public static ClassLoader getProjectClassLoader(IJavaProject project)
throws CoreException, MalformedURLException {
String[] classPaths = JavaRuntime
.computeDefaultRuntimeClassPath(project);
URL[] urls = new URL[classPaths.length];
for (int i = 0; i < classPaths.length; i++) {
urls[i] = new URL(PROTOCAL_PREFIX
+ computeForURLClassLoader(classPaths[i]));
}
return new URLClassLoader(urls);
}
private static String computeForURLClassLoader(String classpath) {
if (!classpath.endsWith("/")) {
File file = new File(classpath);
if (file.exists() && file.isDirectory()) {
classpath = classpath.concat("/");
}
}
return classpath;
}
}
分享到:
相关推荐
- ADT(Android Development Tools)是Eclipse的一个插件,提供了对Android项目的全面支持。 - 使用MyEclipse时,可以直接在线安装此插件。 ##### ADT插件安装步骤 - 打开MyEclipse,按照以下步骤完成ADT插件的...
4. **JDK**:确保系统中已安装Java Development Kit (JDK),并正确配置了JAVA_HOME等环境变量。 #### 三、开发环境搭建步骤 接下来,我们将按照以下步骤来搭建开发环境: 1. **打开Eclipse并添加所需插件**: - ...
� Eclipse JDT plugin (included in most Eclipse IDE packages) � WST (optional, but needed for the Android Editors feature; included in most Eclipse IDE packages ) o JDK 5 or JDK 6 (JRE alone is not ...
其实还有更简单的方法,而且是更好的方法,使用合理描述参数和SQL语句返回值的接口(比如IUserOperation.class),这样现在就可以至此那个更简单,更安全的代码,没有容易发生的字符串文字和转换的错误.下面是详细...
- **MyEclipse**:基于Eclipse平台的集成开发环境,专为Java Web应用开发而设计,提供了丰富的功能,如代码编辑、调试、项目管理等。 **1.3 MyEclipse的使用** - **1.3.1 编译运行一个jsp程序**:在MyEclipse中...