我在eclipse中編寫一個java程序來從lotusnotes db中提取表單。每當我得到一個表單時,我需要創建一個.java文件,它包含一個具有與表單相同名稱的類。然後我必須編譯這個新的.java類,它給了我.class文件&因此我可以創建一個新類的實例。我需要知道這種創建,編譯&的方法是否可以從一個現有的java程序實例化一個新類。從現有的java程序編譯並創建一個新的java程序的實例
我的僞低於
import java.util.Iterator;
import de.bea.domingo.*;
import java.util.List;
import java.io.*;
public class LotusNotesDBExtraction
{
public static void main(String[] args) throws DNotesException,IOException
{
DNotesFactory factory = DNotesFactory.getInstance();
DSession session = factory.getSession();
DDatabase database = session.getDatabase("", "employee.nsf");
List formlist=database.getForms();
//System.out.println("Number of forms are :"+formlist.size());
for(int i=0;i<formlist.size();i++)
{
DForm formn=(DForm)(formlist.get(i));
DForm formname= database.getForm(formn.getName());
**//Creating a class in a file
FileWriter outputfile = new FileWriter("D:\\Lotusnotesformfiles\\"+formn.getName()+".java",true);
BufferedWriter out = new BufferedWriter(outputfile);
out.write("public class "+formn.getName()+" {");
out.newLine();
out.flush();**
try
{
**//Compile the class here**
Process p1 = Runtime.getRuntime().exec("cmd javac \"D:\\Lotusnotesformfiles\\"+formn.getName()+".java\"");
System.out.println("compiled");
}
catch(IOException x)
{
x.printStackTrace();
}
**//instantiate the new class here**
}
}
但我不能夠得到的.class文件爲新類。我可以在同一個程序中實例化新類嗎?我被困在這一點上。任何人都可以幫助我
這不是一個答案,但我有興趣爲什麼你想要在同一個程序中可用的每個表單有一個類?你想如何使用這個類? – michael667
我需要爲表單的每個文檔創建一個對象,並將其傳遞給另一個將要在salesforce中轉儲數據的人員db –
是否要創建_instance_(object)或_class_? – michael667