java.lang.ClassNotFoundException:org.restlet.service.TunnelService命令行

时间:2013-09-19 16:22:06

标签: java jar classnotfoundexception restlet

我正在使用Restlet框架。

我正在尝试从使用Eclipse创建的jar文件中运行我的项目,方法是: Export-> Runnable JAR File ,并选择选项Package required libraries into generated 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文件添加到我的项目中,所以我认为它们不是问题。有没有人对此有任何线索?

如果有人要求,IdentiscopeServer.java的第24行是:

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;
}

1 个答案:

答案 0 :(得分:2)

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

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

看看这是否有帮助。