> >> ...programmatically
> >> compile a class with a third party compiler.
..
> > Sun recommends the following procedure,
....
> > http://java.sun.com/developer/JDCTechTips/2003/tt0722.html#2
> >
> Is this possible with jdk1.1.8?
What did your tests indicate?
Note 1: That the compiler will probably only be able
to write the 1.1 class fromat, & will only be able to
compile code up to the Java version the end-user
has installed, though I doubt it could ever handle
such language developments as generics or
annotations - in any form.
> There is a java.lang.Compiler class there too...
> I would prefer because of the size of tools.jar in 1.2 + versions
> of jdk
Note 2: That the (very not publicly) documented classes
of the com.sun.* package heirarchy are undocumented
for a variety of reasons, one of which is that Sun
reserved the right to move the 'entry points' to the code
at will. AFAIR - their were a number of changes that
affected the developers of Apache/Tomcat.
Andrew T.
Jean Pierre Daviau - 31 Dec 2006 13:07 GMT
"Andrew Thompson" <andrewthommo@gmail.com> a écrit dans le
message de news:
1167543313.265084.108700@i12g2000cwa.googlegroups.com...
Jean Pierre Daviau wrote:
> "Gordon Beaton" <n.o.t@for.email> a écrit dans le message de
> news: 4596b037$0$22507$8404b019@news.wineasy.se...
> > On Sat, 30 Dec 2006 12:18:48 -0500, Jean Pierre Daviau wrote:
> >> ...programmatically
> >> compile a class with a third party compiler.
..
> > Sun recommends the following procedure,
....
> > http://java.sun.com/developer/JDCTechTips/2003/tt0722.html#2
> >
> Is this possible with jdk1.1.8?
What did your tests indicate?
When I use compileClasses("string.java") I get a class not found
exception.
java.lang.ClassNotFoundException: Sample
at Sketch.compile(Compile8.java:37)
at Sketch.main(Compile8.java:47)
But I can make with exec (I know I would have to develop the exec
method: using wait etc.)
--------------------
Sketch ---------------------------------
/*
"C:\Program Files\Java\jdk1.5.0_10\bin\java" -classpath
.;"C:\Program Files\Java\jdk1.5.0_10\lib\tools.jar" CompileIt
"C:\Program Files\Java\jdk1.5.0_
10\bin\java" -classpath .;"C:\Program
Files\Java\jdk1.5.0_10\lib\tools.jar" CompileIt Sample
public class Sample {
public static void main(String args[]) {
System.out.println(new java.util.Date());
}
}
*/
import java.io.*;
import java.lang.reflect.*;
import java.lang.Class;
import java.lang.Compiler;
class Sketch{
public static void compile(String filename)throws Exception {
/*
Runtime.getRuntime().exec("javac " + filename);
*/
String aclass = filename.substring(0, filename.length()-5);
// compile it
boolean compileReturnCode =
java.lang.Compiler.compileClasses(filename);
// run it
Object objectParameters[] = {new String[]{filename.substring(0,
filename.length()-5)}};
Class classParameters[] = {objectParameters[0].getClass()};
Class aClass = Class.forName(aclass);
Object instance = aClass.newInstance();
Method theMethod = aClass.getDeclaredMethod("main",
classParameters);
theMethod.invoke(instance, objectParameters);
}
public static void main(String[] args)throws Exception {
String sourceFile = args[0];
compile(sourceFile);
/* 1.2
System.setProperty("java.compiler", "Jikes");
*/
}
}
-------------------------------------------------
>Note 1: That the compiler will probably only be ableto write the
>1.1 class fromat,
good enough
>Note 2: That the (very not publicly) documented classes
of the com.sun.* package heirarchy are undocumented
for a variety of reasons, one of which is that Sun
reserved the right to move the 'entry points' to the code
at will. AFAIR - their were a number of changes that
affected the developers of Apache/Tomcat.
Has long has there is nothing personnal against me ;-)
JPD
Gordon Beaton - 31 Dec 2006 13:20 GMT
> Note 2: That the (very not publicly) documented classes of the
> com.sun.* package heirarchy are undocumented for a variety of
> reasons, one of which is that Sun reserved the right to move the
> 'entry points' to the code at will. AFAIR - their were a number of
> changes that affected the developers of Apache/Tomcat.
Note that Sun only warns about the sun.* hierarchy, not the com.sun.*
hierarchy, of which the javac package is a part.
Note too that the tip I posted is from a publicly available Sun
document that in fact recommends the use of com.sun.tools.javac.
/gordon

Signature
[ don't email me support questions or followups ]
g o r d o n + n e w s @ b a l d e r 1 3 . s e
Andrew Thompson - 31 Dec 2006 15:26 GMT
> > Note 2: That the (very not publicly) documented classes of the
> > com.sun.* package heirarchy are undocumented for a variety of
[quoted text clipped - 4 lines]
> Note that Sun only warns about the sun.* hierarchy, not the com.sun.*
> hierarchy, of which the javac package is a part.
My bad. That's what I was thinking of.
Oh, and of course, I also forgot to mention..
<http://java.sun.com/javase/6/docs/api/javax/tools/ToolProvider.html>
(the new ability, in 1.6+, to compile code from
within a Java program - no 'tools.jar' needed)
Andrew T.
Jean Pierre Daviau - 31 Dec 2006 18:15 GMT
"Andrew Thompson" <andrewthommo@gmail.com> a écrit dans le
message de news:
1167578801.962763.36470@48g2000cwx.googlegroups.com...
>> > Note 2: That the (very not publicly) documented classes of
>> > the
[quoted text clipped - 16 lines]
> (the new ability, in 1.6+, to compile code from
> within a Java program - no 'tools.jar' needed)
It is to easy
After a runaround the clock on this last day of 2006 in Sun's
website I am looking for jdk1.1.8 com.sun sources . . . if they
exists