jar 파일에 주 응용 프로그램이 있고 별도의 jar 파일 인 '플러그인'이 동적으로로드됩니다.JAR에 Grizzly/Jersey 서버로드
저는이 플러그인 중 하나를 REST 서버로 만들고 싶습니다. 저지를 사용하고 있습니다. 문제는 저지와 함께 플러그인을로드 할 때 http 서버를 실행할 수 있지만 ../myapp/myresource에 갈 때 아무 것도 얻을 수 없다는 것입니다. 브라우저가 멈 춥니 다.
플러그인 방법으로 메인 도구를 삽입하고 플러그인을 직접 실행하면 작동합니다. 이 페이지는 브라우저에 정적 텍스트를 보여줍니다.
다음은 플러그인을로드하는 main.jar의 코드입니다. 그런 다음 각 플러그인에서 시작을 호출합니다.
Vector<IPlugin> plugins = new Vector<IPlugin>();
// Get all files in directory "plugins"
File pluginDir = new File("plugins");
File [] pluginFiles = pluginDir.listFiles();
for(File file: pluginFiles)
{
// Load the file
URL url = null;
try
{
url = file.toURI().toURL();
} catch (MalformedURLException e)
{
System.out.println("Failed to get URL of .jar file");
continue;
}
ClassLoader loader = URLClassLoader.newInstance(
new URL[]{url},
Main.class.getClassLoader());
// Load the plug-in interface
try
{
Class cPluginClass = Class.forName("com.company.plugin_test.Plugin", true, loader);
IPlugin plugin = (IPlugin) cPluginClass.newInstance();
// Success, add the plugin to the plugin list
plugins.add(plugin);
}
catch (Exception e)
{
System.out.println(e.toString());
}
}
다음은 플러그인 코드입니다.
public class Plugin
implements IPlugin
{
private IServer m_server;
public void Start()
{
System.out.println("Loaded the http_plugin");
String BASE_URI = "http://localhost:8080/myapp/";
final ResourceConfig rc = new ResourceConfig().packages ("com.company.plugin_test");
HttpServer httpServer = GrizzlyHttpServerFactory.createHttpServer(URI.create(BASE_URI), rc);
this.start();
}
public void SetServerInterface(IServer server)
{
this.m_server = server;
}
public void Stop()
{
}
}
나는 클래스 로더 문제라고 생각하지만 자바 (네이티브 C++ 배경)를 처음 사용합니다. 어떤 아이디어? 나는 그것을 계속 치핑 할 것이다.
EDIT // ---------------------------- 위의 저지 코드를 다음과 같이 변경하면 ...
final ResourceConfig rc = new ResourceConfig().register (MyResource.class);
질문은 어떻게 자원 구성을 현재 jar 컨텍스트로 설정합니까? 또한 현재 모든 패키지 이름 (com.company.plugin_test)이 동일합니다.