1

我正在使用 Restlet 框架。

我正在尝试通过执行以下操作从使用 Eclipse 创建的 jar 文件运行我的项目:Export->Runnable JAR File,然后选择选项将所需的库打包到生成的 jar 中。

但是,当我尝试在命令行中执行 jar 文件时,键入:

java -Djava.security.policy=Client.Policy -jar identiscopeRunnable.jar 

我得到以下信息:

Exception in thread "main" java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoader.java:58)
Caused by: java.lang.NoClassDefFoundError: org/restlet/service/TunnelService
at rest.IdentiscopeServer.main(IdentiscopeServer.java:24)
... 5 more
Caused by: java.lang.ClassNotFoundException: org.restlet.service.TunnelService
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
... 6 more

我已将所有从 Restlet Framework 下载的 jar 文件添加到我的项目中,所以我认为它们没有问题。有人对此有任何线索吗?

万一有人问,第 24 行IdentiscopeServer.java是:

IdentiscopeServerApplication identiscopeServerApp = new IdentiscopeServerApplication();

该类IdentiscopeServerApplication基本上是这样做的:

@Override
public Restlet createInboundRoot() {
    Router router = new Router(getContext());

    //attaches the /tweet path to the TweetRest class
    router.attach("/collectionPublic", CollectionPublicREST.class);
    router.attach("/collectionPrivate", CollectionPrivateREST.class);
    router.attach("/analysis", AnalysisREST.class);
    return router;
}
4

1 回答 1

2

将 jars 添加到 eclipse 项目不会将 jars 添加到命令行类路径。

java -cp <add your jars here separated by ';'(win) or ':'(linux) > -Djava.security.policy=Client.Policy -jar identiscopeRunnable.jar 

看看这是否有帮助。

于 2013-09-19T16:29:03.227 回答