Re: Java: Compile String -> byte[] -> Class

Joachim Durchholz <joachim_d@gmx.de>
20 Jan 2003 23:57:23 -0500

          From comp.compilers

Related articles
Java: Compile String -> byte[] -> Class wickborn@mail.CS.Uni-Magdeburg.De (Fabian Wickborn) (2003-01-17)
Re: Java: Compile String -> byte[] -> Class joachim_d@gmx.de (Joachim Durchholz) (2003-01-20)
| List of all articles for this month |

From: Joachim Durchholz <joachim_d@gmx.de>
Newsgroups: comp.compilers
Date: 20 Jan 2003 23:57:23 -0500
Organization: Compilers Central
References: 03-01-085
Keywords: Java
Posted-Date: 20 Jan 2003 23:57:23 EST

John wrote:
> [Personally, I'd configure my system with a ramdisk and put the
> files there. -John]


Ramdisks must have their size configured in advance, and they must be
configured using root user privileges (unless things have changed
since I last looked). This restricts their usefulness. So I think a
good answer would be helpful even if Fabian can work with a ramdisk.


One idea might be this one:
.class files can be served from HTTP servers. Write a library that
accepts Java source via an API, and that contains a http server that
serves only requests from localhost. The API could look like this (just
a *very* rough sketch):
      char [] compile_java (char [] source)
          // Compile the submitted source code.
          // Return a token that can be used in URLs to retrieve
          // the information, like this:
          // http://localhost/<token>/log
          // will give the error log (if any errors occurred)
          // http://localhost/<token>/java.class
          // the compiled class "file" (maybe a package would be better)


The next idea would be like this:
Look at the class loader classes. Identify the routines that you call to
load a class - I'd expect there is one for each possible source of
classes, or a different subclass of ClassLoader for each source. However
it is defined, you'll get a set of Java classes that the class loader
expects to identify the source: a URL, a HttpConnection, a Stream, or
whatever. Write a class that implements the interface of such a source
but draws its input from the character array.
IIRC you'll have to register your class somewhere in the class loader
machinery of the JVM.


Disclaimer: This all draws from a cursory knowledge of Java and its
loader mechanism, plus general OO experience. All class names, Java
syntax, and other statements may vary slightly from reality; the above
are strategies I'd use if I were in Fabian's position, not ready-to-run
recipes.


HTH
Joachim


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.