0
是否可以從另一個Java程序啓動Java程序,就像我使用另一個Java命令啓動它一樣?當直接從另一個程序調用程序的main()
方法時,這兩種執行都通用於。我試圖每個線程有一個Java上下文。每個線程有一個「Java上下文」?
插圖:
的src/COM /項目/ ProjectLauncher.java
public class ProjectLauncher {
static {
PropertyConfigurator.configure("log4j.properties");
}
public static void main(String[] args) {
Logger.getLogger(ProjectLauncher.class).info("started!");
// Logs well as expected.
}
}
測試/ COM /項目/ TestProject.java
public class TestProject extends TestCase {
public void testProject() {
ProjectLauncher.main(null);
Logger.getLogger(TestProject.class).info("tested!");
// The above line logs well, while log4j has been initialized in ProjectLauncher.
// I would like it to need its own initialization in this class.
}
}
我嘗試啓動main
方法在另一個線程/ runnable中,但記錄器仍由ProjectLauncher初始化。