Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

20
LINES

< > BotCompany Repo | #1000595 - compileAndLoadMainClass

JavaX fragment (include)

// compile JavaX source and load main class
static Class<?> compileAndLoadMainClass(String src) ctex {
  O javax = getJavaX();
  File srcDir = cast call(javax, "TempDirMaker_make");
  File classesDir = cast call(javax, "TempDirMaker_make");
  saveTextFile(new File(srcDir, "main.java"), src);
  new List<File> libraries;
  set(javax, "safeTranslate", true);
  File transpiledDir = cast call(javax, "topLevelTranslate", srcDir, libraries);
  String javacOutput = cast call(javax, "compileJava", transpiledDir, libraries, classesDir);
  System.out.println(javacOutput);
  URL[] urls = {classesDir.toURI().toURL()};
  
  // make class loader
  URLClassLoader classLoader = new URLClassLoader(urls);

  // load main class
  Class<?> mainClass = classLoader.loadClass("main");
  return mainClass;
}

download  show line numbers  debug dex   

Travelled to 12 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz

No comments. add comment

Snippet ID: #1000595
Snippet name: compileAndLoadMainClass
Eternal ID of this version: #1000595/1
Text MD5: c448ae451102854af320b5fc84fdc816
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2016-04-20 18:51:39
Source code size: 812 bytes / 20 lines
Pitched / IR pitched: No / No
Views / Downloads: 460 / 603
Referenced in: [show references]

Formerly at http://tinybrain.de/1000595 & http://1000595.tinybrain.de