[英]Integrate (embed) Openfire-Server into another Java-Project
I cloned the Openfire-Source from Git-Repository ( https://github.com/igniterealtime/Openfire ), set it up into Eclipse and did an Ant-Build of it. 我从Git-Repository( https://github.com/igniterealtime/Openfire )克隆了Openfire-Source,将其设置到Eclipse中并对其进行了Ant构建。 Openfire is running with my prefered custom configuration and is connected to an MySQL-Database, which stores users, passwords... Launching the server from Eclipse works fine. Openfire以我喜欢的自定义配置运行,并连接到MySQL数据库,该数据库存储用户,密码...从Eclipse启动服务器工作正常。
My goal is to start Openfire "invisible" from another Java-Project (JavaFX in my case). 我的目标是从另一个Java项目(在我的情况下为JavaFX)启动“不可见”的Openfire。 If possible, i want to merge both projects into only one. 如果可能的话,我想将两个项目合并为一个。
The build Openfire project was added to classpath of my JavaFX-Application. 构建Openfire项目已添加到我的JavaFX-Application的类路径中。
1) First i tried to instantiate Openfires Startup.jar in my existing JavaFX-Stage-Controller with 1)首先,我尝试使用以下命令在我现有的JavaFX-Stage-Controller中实例化Openfires Startup.jar:
public void initialize(URL url, ResourceBundle rb) {
initListener();
initContents();
org.jivesoftware.openfire.starter.ServerStarter.main(null);
...
}
Like expected, the VM-parameters are missing: 如预期的那样,VM参数丢失:
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/C:/Users/knoop/Desktop/java/slf4j-1.7.13/slf4j-jdk14-1.7.13.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/C:/Users/knoop/Desktop/java/Openfire_git/build/lib/ant/slf4j-simple.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/C:/Users/knoop/Desktop/java/Openfire_git/build/lib/dist/slf4j-log4j12.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.slf4j.impl.JDK14LoggerFactory]
Jan 27, 2016 5:52:28 PM org.jivesoftware.util.Log warn
WARNUNG: Admin Lib Directory ../plugins/admin/webapp/WEB-INF/lib does not exist. Web admin console may not work.
Could not locate home
java.io.FileNotFoundException
at org.jivesoftware.openfire.XMPPServer.locateOpenfire(XMPPServer.java:827)
at org.jivesoftware.openfire.XMPPServer.initialize(XMPPServer.java:304)
at org.jivesoftware.openfire.XMPPServer.start(XMPPServer.java:440)
at org.jivesoftware.openfire.XMPPServer.<init>(XMPPServer.java:169)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at java.lang.Class.newInstance(Unknown Source)
at org.jivesoftware.openfire.starter.ServerStarter.start(ServerStarter.java:105)
at org.jivesoftware.openfire.starter.ServerStarter.main(ServerStarter.java:56)
at org.server_fx.GUI.controller.MainScreenController.initialize(MainScreenController.java:53)
at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
at javafx.fxml.FXMLLoader.load(Unknown Source)
at org.server_fx.GUI.controller.GUI_Shared.loadFXMLToStage(GUI_Shared.java:63)
at org.server_fx.GUI.fxml.Manager.start(Manager.java:24)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$163(Unknown Source)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$176(Unknown Source)
at com.sun.javafx.application.PlatformImpl.lambda$null$174(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$175(Unknown Source)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(Unknown Source)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$149(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Jan 27, 2016 5:52:28 PM org.jivesoftware.openfire.XMPPServer start
SCHWERWIEGEND: null
java.io.FileNotFoundException
at org.jivesoftware.openfire.XMPPServer.locateOpenfire(XMPPServer.java:827)
at org.jivesoftware.openfire.XMPPServer.initialize(XMPPServer.java:304)
at org.jivesoftware.openfire.XMPPServer.start(XMPPServer.java:440)
at org.jivesoftware.openfire.XMPPServer.<init>(XMPPServer.java:169)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at java.lang.Class.newInstance(Unknown Source)
at org.jivesoftware.openfire.starter.ServerStarter.start(ServerStarter.java:105)
at org.jivesoftware.openfire.starter.ServerStarter.main(ServerStarter.java:56)
at org.server_fx.GUI.controller.MainScreenController.initialize(MainScreenController.java:53)
at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
at javafx.fxml.FXMLLoader.load(Unknown Source)
at org.server_fx.GUI.controller.GUI_Shared.loadFXMLToStage(GUI_Shared.java:63)
at org.server_fx.GUI.fxml.Manager.start(Manager.java:24)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$163(Unknown Source)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$176(Unknown Source)
at com.sun.javafx.application.PlatformImpl.lambda$null$174(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$175(Unknown Source)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(Unknown Source)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$149(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Jan 27, 2016 5:52:28 PM org.jivesoftware.util.LocaleUtils getLocalizedString
SCHWERWIEGEND: Can't find bundle for base name openfire_i18n, locale de_DE
Critical Error! The home directory has not been configured,
which will prevent the application from working correctly.
startup.error
Which results in a missing Openfire-home-directory. 这将导致缺少Openfire主目录。
2) Openfire.bat contains specific parameters for launching the server (DopenfireHome="%OPENFIRE_HOME%"). 2)Openfire.bat包含用于启动服务器的特定参数(DopenfireHome =“%OPENFIRE_HOME%”)。
So I tried: 所以我尝试了:
public void initialize(URL url, ResourceBundle rb) {
initListener();
initContents();
try {
Process proc = Runtime.getRuntime().exec("java" -DopenfireHome=\"C:\\Users\\knoop\\Desktop\\java\\Openfire_git\\target\\openfire\" -jar C:\\Users\\knoop\\Desktop\\java\\Openfire_git\\target\\openfire\lib\startup.jar");
} catch (IOException e) { e.printStackTrace(); }
...
}
which results in nothing. 结果什么也没有。 No exception or else. 也不例外。
Is there another way to instantiate the OpenFire server from another Java-Project, or to "invisibly" launch the server in background with the correct launch parameters? 是否有另一种方法可以从另一个Java项目中实例化OpenFire服务器,或者使用正确的启动参数在后台“无形”启动服务器?
Ok it works now. 好的,现在可以使用。
JavaFX-Init: JavaFX的初始化:
private void initContents() {
System.setProperty("openfireHome", "C:/Users/knoop/Desktop/java/workspace/Openfire/target/openfire");
System.setProperty("openfire.lib.dir", "C:/Users/knoop/Desktop/java/workspace/Openfire/target/openfire/lib");
org.jivesoftware.openfire.starter.ServerStarter.main(null);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.