D:\CRM_Project\CRM_Metadata_Structure\NetBeamsICM_TestProject\ICM_DB_TestComponents\src\java\unstructured_data_parser\DAO_DynamicCompilation.java
 1 /*
 2  * To change this license header, choose License Headers in Project Properties.
 3  * To change this template file, choose Tools | Templates
 4  * and open the template in the editor.
 5  */
 6 package unstructured_data_parser;
 7 
 8 import java.io.*;
 9 import java.lang.reflect.Method;
10 import java.net.URLClassLoader;
11 import java.util.Arrays;
12 import java.io.File;
13 import java.net.URL;
14 import java.util.ArrayList;
15 import java.util.List;
16 //import java.net.URLClassLoader;
17 
18 import javax.tools.JavaCompiler;
19 import javax.tools.JavaFileObject;
20 import javax.tools.StandardJavaFileManager;
21 import javax.tools.StandardLocation;
22 import javax.tools.ToolProvider;
23 
24 /**
25  *
26  * @author sameldin
27  */
28 public class DAO_DynamicCompilation {
29 
30     String folderName               = "D:/CRM_Project/CRM_Metadata_Structure/ICM_InputData/TestJavaFiles/DAO_TargetCompilation";
31     String fileName                 = "SimpleInputExcelSheetDAO.java";
32     String javaDAO_SourceCodePath   = "D:/CRM_Project/CRM_Metadata_Structure/ICM_InputData/TestJavaFiles/DAO_TargetCompilation/SimpleInputExcelSheetDAO.java";
33     
34     public DAO_DynamicCompilation() {
35 
36         try
37         {
38             File sourceFile   = new File(javaDAO_SourceCodePath);
39             
40             JavaCompiler compiler    = ToolProvider.getSystemJavaCompiler();
41             StandardJavaFileManager fileManager =
42                 compiler.getStandardFileManager(null, null, null);
43 
44             fileManager.setLocation(StandardLocation.CLASS_OUTPUT,
45                                    // Arrays.asList(new File("/temp")));
46                                     Arrays.asList(new File(folderName)));
47 
48             // Compile the file
49             compiler.getTask(null,
50                        fileManager,
51                        null,
52                        null,
53                        null,
54                        fileManager.getJavaFileObjectsFromFiles(Arrays.asList(sourceFile)))
55                     .call();
56             fileManager.close();
57         }
58             catch (Exception e) {
59       e.printStackTrace();
60     }
61         System.out.println("\nEnd of DAO_DynamicCompilation\n") ;
62         
63     }
64     /*
65     
66     */
67     public static void main(String[] args) throws Exception {
68         
69         DAO_DynamicCompilation localDAO_DynamicCompilation = new DAO_DynamicCompilation();
70         System.out.println("\nEnd of main \n") ;
71     }    
72     
73 }
74