我正在尝试设置一个自定义启动器以连接到 Apache ACE 服务器,但我似乎找不到任何涵盖该过程的文档。我能找到的唯一一件事是我显然需要使用 Apache ACE 代理,这要感谢这里的一个线程。但是,尝试在该线程中使用提供的代码似乎不起作用。在启动启动器时,它甚至不尝试连接到服务器,或者返回一个错误,指出它正在尝试连接到错误的端口(默认端口而不是我告诉它的端口)并且找不到服务器。
我还看到一些帖子表明使用了 ace-launcher.jar 文件,但没有说明如何使用它,并且 Apache wiki 上的文档表明它是一个独立文件。尝试按照他们在此处显示的方式运行它似乎不起作用,因为它没有读取识别/发现/等的参数。当按照他们的示例显示的方式使用时。
我仍然不知道如何通过自定义启动器连接到 Apache ACE 服务器。Apache ACE server-allinone 对我的服务器来说很好,但是 target.jar 不允许我(至少我见过)指定要暴露给 OSGi 框架的系统包。谁能帮我弄清楚如何设置我的启动器以连接到 Apache Ace 服务器?
import java.io.File;
import java.net.MalformedURLException;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.ServiceLoader;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.BundleException;
import org.osgi.framework.Constants;
import org.osgi.framework.launch.Framework;
import org.osgi.framework.launch.FrameworkFactory;
public class Main {
public static void main(String[] args) throws BundleException {
File bundlesDir = new File(new File("").getAbsolutePath() + "/bundles/");
FrameworkFactory frameworkFactory = ServiceLoader.load(FrameworkFactory.class).iterator().next();
Map<String, String> config = new HashMap<String, String>();
config.put(Constants.FRAMEWORK_STORAGE, bundlesDir.getAbsolutePath());
config.put(Constants.FRAMEWORK_SYSTEMPACKAGES_EXTRA, "org.w3c.dom.html,..."); // Truncated for readability
Framework framework = frameworkFactory.newFramework(config);
framework.start();
BundleContext context = framework.getBundleContext();
List<Bundle> installedBundles = new LinkedList<Bundle>();
for (File file : bundlesDir.listFiles()) {
if (file.getAbsolutePath().contains(".jar")) {
try {
installedBundles.add(context.installBundle(file.toURI().toURL().toString()));
} catch (MalformedURLException e) {
e.printStackTrace();
continue;
}
System.out.println(file.getName() + " installed.");
}
}
for (Bundle bundle : installedBundles) {
System.out.println("Starting: " + bundle.getSymbolicName());
bundle.start();
}
}
}
尝试运行代理启动器时收到的输出消息:
...\test>java -jar org.apache.ace.agent.launcher.felix.jar -v --agent Test --serverurl localhost:9000
Launching OSGi framework
- factory: org.apache.felix.framework.FrameworkFactory
- properties: {agent.logging.level=DEBUG, agent.identification.agentid=Test, verbose=true, agent.discovery.serverurls=localhost:9000}
- providers: [AgentBundleProvider, BundleDirBundleProvider]
- installing: file:/.../test/org.apache.ace.agent.launcher.felix.jar!/org.apache.ace.agent.jar
[DEBUG] 10:32:53 (controller) Config initialized: update: true, fixPkg: true, syncDelay: 5, syncInterval: 60, maxRetries: 1
[DEBUG] 10:32:53 (controller) Scheduling controller to run in 5 seconds...
Startup complete...[DEBUG] 10:32:58 (controller) Controller syncing...
[DEBUG] 10:32:58 (controller) Synchronizing feedback channels: [auditlog]
[WARNING] 10:32:59 (discovery) Blacklisting unavailable serverURL: http://localhost:8080
[WARNING] 10:32:59 (discovery) No valid server URL discovered?!
[WARNING] 10:32:59 (feedbackChannel(auditlog)) No identification or server URL present, cannot send feedback!
[DEBUG] 10:32:59 (controller) Feedback send succesfully for channel: auditlog
[DEBUG] 10:32:59 (controller) Checking for agent updates...
[DEBUG] 10:32:59 (discovery) Ignoring blacklisted serverURL: http://localhost:8080
[WARNING] 10:32:59 (discovery) No valid server URL discovered?!
[WARNING] 10:32:59 (controller) Sync received retry exception from server. Rescheduled in 10 seconds...
[DEBUG] 10:32:59 (controller) Scheduling controller to run in 10 seconds...