我正在尝试使用JavaCompiler接口:
class A<T extends TrackableObject>{
}
public class JavaCompolierDemo {
/**
* @param args
* @throws IOException
*/
public static void main(String[] args) throws IOException {
File sourceFile = new File("c:\\java\\DOModel.java");
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
compiler.run(null, null, null, "-cp", System.getProperties().getProperty("java.class.path") + ";F:\\IndigoSpace\\ejp", sourceFile.getPath());
System.out.println(new File("c:\\java\\").toURI().toURL());
URLClassLoader loader = new URLClassLoader(new URL[]{new File("c:\\java\\").toURI().toURL()});
try {
loader.loadClass("amarsoft.dbmp.credit.web.model.DOModel");
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
}
但是当我运行上述代码时,会抛出一个ClassNotFoundException异常:
file:/c:/java/
java.lang.ClassNotFoundException: amarsoft.dbmp.credit.web.model.DOModel
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
at amarsoft.rcp.base.util.test.JavaCompolierDemo.main(JavaCompolierDemo.java:31)
正在编译的源代码:
package amarsoft.dbmp.credit.web.model;
import amarsoft.rcp.base.databinding.TrackableObject;
import ejp.annotations.ConcreteTableInheritance;
@ConcreteTableInheritance
public class DOModel extends TrackableObject {
/**
*
*/
private static final long serialVersionUID = -7066464988987508089L;
/**
* 编号
*/
private String id;
/**
* 名称
*/
private String name;
/**
* 模板类型,没有太大意义
*/
private String type;
/**
* 模板参数
*/
private String args;
private String updateTable;
private String updateWhere;
private String fromClause;
private String whereClause;
private String groupClause;
private String orderClause;
public String getId() {
return id;
}
public void setId(String id) {
this.firePropertyChange("id", this.id, this.id = id);
}
public String getName() {
return name;
}
public void setName(String name) {
this.firePropertyChange("name", this.name, this.name = name);
}
public String getType() {
return type;
}
public void setType(String type) {
this.firePropertyChange("type", this.type, this.type = type);
}
public String getArgs() {
return args;
}
public void setArgs(String args) {
this.firePropertyChange("args", this.args, this.args = args);
}
public String getUpdateTable() {
return updateTable;
}
public void setUpdateTable(String updateTable) {
this.firePropertyChange("updateTable", this.updateTable, this.updateTable = updateTable);
}
public String getDoUpdateWhere() {
return updateWhere;
}
public void setDoUpdateWhere(String doUpdateWhere) {
this.firePropertyChange("updateWhere", this.updateWhere, this.updateWhere = doUpdateWhere);
}
public String getFromClause() {
return fromClause;
}
public void setFromClause(String fromClause) {
this.firePropertyChange("fromClause", this.fromClause, this.fromClause = fromClause);
}
public String getWhereClause() {
return whereClause;
}
public void setWhereClause(String whereClause) {
this.firePropertyChange("whereClause", this.whereClause, this.whereClause = whereClause);
}
public String getGroupClause() {
return groupClause;
}
public void setGroupClause(String groupClause) {
this.firePropertyChange("groupClause", this.groupClause, this.groupClause = groupClause);
}
public String getOrderClause() {
return orderClause;
}
public void setOrderClause(String orderClause) {
this.firePropertyChange("orderClause", this.orderClause, this.orderClause = orderClause);
}
@Override
public String toString() {
return "DOModel [id=" + id + ", name=" + name + "]";
}
}
我的代码出了什么问题?类文件已经生成,我很确定。
![在此输入图片描述](https://istack.dev59.com/IQqTZ.webp)