CompileRun.java
import java.io.*;
import java.lang.reflect.*;
public class CompileRun
{
public static void main(String arg[])throws Exception
{
System.out.println(“Helo”);
new com.sun.tools.javac.Main().compile(new String[]
import java.lang.reflect.*;
public class CompileRun
{
public static void main(String arg[])throws Exception
{
System.out.println(“Helo”);
new com.sun.tools.javac.Main().compile(new String[]
{“HelloWorld.java”});
Class c=Class.forName(“HelloWorld”);
Object o=c.newInstance();
Object ar[]=new Object[]{};
Class cl[]=new Class[]{};
Method m=c.getDeclaredMethod(“print”,cl);
m.invoke(o,ar);
}
}
Class c=Class.forName(“HelloWorld”);
Object o=c.newInstance();
Object ar[]=new Object[]{};
Class cl[]=new Class[]{};
Method m=c.getDeclaredMethod(“print”,cl);
m.invoke(o,ar);
}
}
HelloWorld.java
public class HelloWorld
{
public void print()
{
System.out.println(“Hello World”);
}
}
{
public void print()
{
System.out.println(“Hello World”);
}
}
Classpath
1) %classpath%;Q:\SDE7_Tomcat6_JDK6\Java\jdk1.6.0_24\lib\*
2) javac CompileRun.java
3) java -cp “Q:\SDE7_Tomcat6_JDK6\Java\jdk1.6.0_24\lib\*;.” CompileRun
No comments:
Post a Comment