3

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. enter image description here

1 Answer 1

4

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.