How does javac.exe work?

M

Murrgon

Does the javac.exe just push source files through JNI to produce
..class files or is there more involved? If not what is it doing
to produce the .class file from a .java file? What I am looking
for is a way to compile .java files without using javac. Thanks.

Murrgon
 
J

John C. Bollinger

Murrgon said:
Does the javac.exe just push source files through JNI to produce
.class files or is there more involved? If not what is it doing
to produce the .class file from a .java file? What I am looking
for is a way to compile .java files without using javac. Thanks.

Are you looking for an alternative Java compiler? There are several.
No doubt Roedy is already writing a response pointing you to the
appropriate page on mindprod, but you could Google for it if you don't
want to wait.

On the other hand, it seems more like you're saying that you want to
compile Java source to bytecode without using a compiler. Huh? Any
tools that inputs Java source and outputs corresponding class files is
by definition a Java compiler. You cannot compile without a compiler of
some sort, even if you fill the compiler role yourself by hand-coding
the bytecode.


John Bollinger
(e-mail address removed)
 
M

Murrgon

John said:
Are you looking for an alternative Java compiler? There are several. No
doubt Roedy is already writing a response pointing you to the
appropriate page on mindprod, but you could Google for it if you don't
want to wait.

On the other hand, it seems more like you're saying that you want to
compile Java source to bytecode without using a compiler. Huh? Any
tools that inputs Java source and outputs corresponding class files is
by definition a Java compiler. You cannot compile without a compiler of
some sort, even if you fill the compiler role yourself by hand-coding
the bytecode.

What I want to be able to do is allow third parties to be able to write
some java extensions to our app without needing to run a compiler
themselves. We would handle running the compilation of the source files
when we load them. Basically I'm looking to implement the same type
of setup that, say, TCL or Python has where it compiles the source when
it is loaded.

Murrgon
 
A

Andy Fish

What I want to be able to do is allow third parties to be able to write
some java extensions to our app without needing to run a compiler
themselves. We would handle running the compilation of the source files
when we load them. Basically I'm looking to implement the same type
of setup that, say, TCL or Python has where it compiles the source when
it is loaded.

you need the class com.sun.tools.javac.Main
 
R

Roedy Green

Does the javac.exe just push source files through JNI to produce
.class files or is there more involved? If not what is it doing
to produce the .class file from a .java file?

No JNI would be needed. A class file is just a complicated string of
bytes. Study up on parsers and compilers to learn how the magic is
accomplished. Normally your learn this stuff in computer science
courses at university.

see http://mindprod.com/jgloss/parser.html
see http://mindprod.com/jgloss/jasm.html

With JASM-type tools you too can create class files out of thin air.
 
R

Roedy Green

What I want to be able to do is allow third parties to be able to write
some java extensions to our app without needing to run a compiler
themselves. We would handle running the compilation of the source files
when we load them. Basically I'm looking to implement the same type
of setup that, say, TCL or Python has where it compiles the source when
it is loaded

You need nothing fancy at all. If you have a JDK, you have a compiler
you can invoke dynamically either as a class or with exec.

See http://mindprod.com/jgloss/javacexe.html

see also http://mindprod.com/jgloss/eval.html
 
T

Thomas Kellerer

Murrgon said:
This is exactly what I was looking for. Thanks.

javac.exe does nothing else then to fire up a JVM and then call
com.sun.tools.javac.Main


Thomas
 
R

Roedy Green

javac.exe does nothing else then to fire up a JVM and then call
com.sun.tools.javac.Main

the catch is it fires the JVM up every time you type Javac.exe.
Further it has a limited length command line. With javac.Main, you
can give thousands of things to compile and it will load the JVM only
once.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top