Skip to content

Commit 99c41f8

Browse files
authored
Merge pull request #31 from joirn-pettersen/patch-1
Changed README.md to use code fences
2 parents 52d3572 + 2101101 commit 99c41f8

File tree

1 file changed

+25
-19
lines changed

1 file changed

+25
-19
lines changed

README.md

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,27 +9,31 @@ By default it uses the current ClassLoader. It supports nested classes, but oth
99

1010
You can include in your project with
1111

12-
<dependency>
13-
<groupId>net.openhft</groupId>
14-
<artifactId>compiler</artifactId>
15-
<version><!-- The latest version (see above) --></version>
16-
</dependency>
12+
```xml
13+
<dependency>
14+
<groupId>net.openhft</groupId>
15+
<artifactId>compiler</artifactId>
16+
<version><!-- The latest version (see above) --></version>
17+
</dependency>
18+
```
1719

1820
## Simple example
1921

2022
You need a CachedCompiler and access to your JDK's tools.jar.
2123

22-
// dynamically you can call
23-
String className = "mypackage.MyClass";
24-
String javaCode = "package mypackage;\n" +
25-
"public class MyClass implements Runnable {\n" +
26-
" public void run() {\n" +
27-
" System.out.println(\"Hello World\");\n" +
28-
" }\n" +
29-
"}\n";
30-
Class aClass = CompilerUtils.CACHED_COMPILER.loadFromJava(className, javaCode);
31-
Runnable runner = (Runnable) aClass.newInstance();
32-
runner.run();
24+
```java
25+
// dynamically you can call
26+
String className = "mypackage.MyClass";
27+
String javaCode = "package mypackage;\n" +
28+
"public class MyClass implements Runnable {\n" +
29+
" public void run() {\n" +
30+
" System.out.println(\"Hello World\");\n" +
31+
" }\n" +
32+
"}\n";
33+
Class aClass = CompilerUtils.CACHED_COMPILER.loadFromJava(className, javaCode);
34+
Runnable runner = (Runnable) aClass.newInstance();
35+
runner.run();
36+
````
3337

3438
I suggest making you class implement a KnownInterface of your choice as this will allow you to call/manipulate instances of you generated class.
3539

@@ -41,9 +45,11 @@ you have compiler redefine a class and code already compiled to use the class wi
4145

4246
In this example, you can configure the compiler to write the files to a specific directory when you are in debug mode.
4347

44-
private static final CachedCompiler JCC = CompilerUtils.DEBUGGING ?
45-
new CachedCompiler(new File(parent, "src/test/java"), new File(parent, "target/compiled")) :
46-
CompilerUtils.CACHED_COMPILER;
48+
```java
49+
private static final CachedCompiler JCC = CompilerUtils.DEBUGGING ?
50+
new CachedCompiler(new File(parent, "src/test/java"), new File(parent, "target/compiled")) :
51+
CompilerUtils.CACHED_COMPILER;
52+
```
4753

4854
By selecting the src directory to match where your IDE looks for those files, it will allow your debugger to set into code you have generated at runtime.
4955

0 commit comments

Comments
 (0)