Thanks to visit codestin.com
Credit goes to github.com

Skip to content

elvinmahmudov/DynoCom

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

DynoCom - Compile classes on the fly


Build Status

Getting Started

The aim of this project is to help developers compile source Java classes in memory on the fly.

Installing

Step 1: Add to maven dependencies

        <dependency>
            <groupId>com.github.elvinmahmudov</groupId>
            <artifactId>dynocom</artifactId>
            <version>1.2.3</version>
        </dependency>

Step 2: compile string and load class:

public class Main {

    private static String MODEL_NAME = "com.elvinmahmudov.dynocom.MathTeacher";

    public static void main(String[] args) {
        var compiler = new JavaStringCompiler();
        var results = compiler.compile("Teacher.java", SINGLE_CLASS);
        var clazz = compiler.loadClass(MODEL_NAME, results);
        
        var teacher = (Teacher) clazz.newInstance();
    }

    static final String SINGLE_CLASS = "                                      "
            + "package com.elvinmahmudov.dynocom.model;                       "
            + "                                                               "
            + "import com.elvinmahmudov.dynocom.model.*;                      "
            + "import lombok.Data;                                            "
            + "                                                               "
            + "@Data                                                          "
            + "public class MathTeacher extends Teacher {                     "
            + "    String mainSubject = \"Math\";                             "
            + "}                                                              ";
}

About

Dynamic Java Code Compiler

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages