GithubHelp home page GithubHelp logo

doytsujin / jcompiler Goto Github PK

View Code? Open in Web Editor NEW

This project forked from miho/jcompiler

0.0 1.0 0.0 209 KB

Simple API for in-memory compilation of Java code.

License: Apache License 2.0

Java 100.00%

jcompiler's Introduction

JCompiler

javadoc Maven Central

The purpose of this project is to provide a simple API for in-memory compilation of Java code. While the JDK provides a full-blown API for this, in many cases a much simpler API is sufficient.

This project is based on abandoned code by @trung and a reduced version of language utils from VRL.

Using JCompiler

Note: This project needs the full JDK as runtime-dependency to work properly (the JRE does not contain the JavaCompiler API).

Compiling Java classes is as simple as this:

// compile code
CompilationResult result = JCompiler.newInstance().
compile(
    "public class MyClass {\n"+
    "  public static String hello() {\n"+
    "    return \"hello\";\n"+
    "  }\n"+
    "}"
).checkNoErrors();
// load class and invoke static method
Class<?> myClass = result.loadClasses().get("MyClass");    
String msg = (String)myClass.getMethod("hello").invoke(null);          

How To Build The Project

1. Dependencies

  • JDK >= 11
  • Internet Connection (other dependencies will be downloaded automatically)
  • Optional: IDE with Gradle support

2. Building

IDE

To build the project from an IDE do the following:

  • open the Gradle project
  • call the assemble Gradle task to build the project

Command Line

Building the project from the command line is also possible.

Navigate to the project folder and call the assemble Gradle task to build the project.

Bash (Linux/OS X/Cygwin/other Unix-like OS)
cd Path/To/JCompiler
./gradlew assemble
Windows (CMD)
cd Path\To\JCompiler
gradlew assemble
Windows (PowerShell)
cd Path\To\JCompiler
.\gradlew assemble

jcompiler's People

Contributors

trung avatar miho avatar turpid-monkey avatar pkeidel avatar fossabot avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.