I am trying to play with JavaCompiler interface:
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();
}
}
}
but when I run above code a ClassNotFoundException was thrown:
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)
the source code being compiled :
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 + "]";
}
}
what's wrong with my code ? the class file was generated, I am sure of that.

The package name of required class must be found in the filesystem path of the same name. The DOModel class must be in the filesystem path of amarsoft.dbmp.credit.web.model, ie. C:\\java\\amarsoft\\dbmp\\credit\\web\\model\\DOModel.class
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With