verhas / jscc

Auxilliary classes to help compilation of Java source generated on the fly

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

jscc

This project is obsolete. Based on the code of this project a new project was started and it is currently supported and alive at https://github.com/sourcebuddy/sourcebuddy

A very simple Java source compiler code based on the javac provided by the JDK. The API built into the Java runtime is complex because it is designed to handle several input (Java source code) and output (generated byte code) reading and writing possibilities. This needs the implementation of complex classes that provide the source code and can store the generated byte code.

To ease the burden this library implements these classes along with a class loader to handle the simple case when you want to compile Java source available during run-time in String objects and you want to load the compiled classes instead generating .class files.

The library also implements a facade to provide a simple API.

Usage

import com.javax0.jscc.Compiler;

...

// create a new compiler
Compiler compiler = new Compiler();
// compile and load the class providing source code and
// fully qualified class name
Class<?> newClass = compiler.compile(sourceCode, className);

Using the class you can use the standard JDK way to get a new instance of the class calling

// get a new instance
Object object = newClass.newInstance();

For more information read the JavaDoc documentation of the project. This may be needed in case you want to handle source code that contains error, or you want to compile a class that needs special class loader.

This project was developed primarily to support the djcproxy library.

Maven Dependency

		<dependency>
			<groupId>com.javax0</groupId>
			<artifactId>jscc</artifactId>
			<version>1.0.1</version>
		</dependency>

Releases

  • 1.0.1 Handles source code that generate more than one class. For example classes that contain nested or inner classes, anonymous classes. Previous release did not handle the case and is not able to load the auxiliary classes.
  • 1.0.0 Initial release

About

Auxilliary classes to help compilation of Java source generated on the fly


Languages

Language:Java 100.0%