JAVA 新手警报:尝试运行 Java 类并收到 ClassNotFoundException
Java新手。我正在尝试从cmd行运行一个java主类并返回ClassNotFoundException
:
java -cp class c:\development\eclipse\workspace\Library-Manager-Server\bin\demo\rmi\librarymanager\server\LibraryManagerServer
-Djava.security.policy="C:\Development\Eclipse\Workspace\Library-Manager-Server\security.policy"
-Djava.rmi.server.codebase="file:/C:/Development/Eclipse/Workspace/Library-Manager-Server/bin/ file:/C:/Development/Eclipse/Workspace/Library-Manager-Common/bin/"
该类肯定存在于bin中(eclipse将其删除的位置),但由于某种原因(可能是微不足道的)它无法找到当我运行上面的命令行时。
任何帮助表示赞赏!
EDIT#1:你们中的一些人可能已经猜到类名是 demo.rmi.librarymanager.server.LibraryManagerServer
EDIT#2:好的 - 谢谢对于人们的建议,我认为这次我的语法是正确的,但我仍然收到 ClassNotFoundException
但在公共包中的不同类上:
demo.rmi.librarymanager.common.Library
这是新的 cmd 行:
java -cp c:/development/eclipse/workspace/Library-Manager-Server/bin demo.rmi.librarymanager.server.LibraryManagerServer
-Djava.security.policy="C:/Development/Eclipse/Workspace/Library-Manager-Server/security.policy"
-Djava.rmi.server.codebase="file:/C:/Development/Eclipse/Workspace/Library-Manager-Server/bin file:/C:/Development/Eclipse/Workspace/Library-Manager-Common/bin"
我应该添加 c: /development/eclipse/workspace/Library-Manager-Common/bin
路径(其中 demo.rmi.librarymanager.common.Library
所在)与 c:/development/eclipse -cp 之后的 /workspace/Library-Manager-Server/bin
作为命令行参数?
感谢大家的帮助和耐心 - 我正在开发一个 RMI 应用程序,一切都很好,直到我使用 RMI 插件 但现在我遇到了一些困难,因为我对 java 相当陌生(正如你从我的问题中看到的!)。
编辑#3:好的,我成功了:
java -cp c:/development/eclipse/workspace/Library-Manager-Server/bin;c:/development/eclipse/workspace/Library-Manager-Common/bin
demo.rmi.librarymanager.server.LibraryManagerServer
-Djava.security.policy="C:/Development/Eclipse/Workspace/Library-Manager-Server/security.policy"
-Djava.rmi.server.codebase="file:/C:/Development/Eclipse/Workspace/Library-Manager-Server/bin file:/C:/Development/Eclipse/Workspace/Library-Manager-Common/bin"
感谢大家的谦逊。
Java newbie. I am trying to run a java main class from cmd line and getting back ClassNotFoundException
:
java -cp class c:\development\eclipse\workspace\Library-Manager-Server\bin\demo\rmi\librarymanager\server\LibraryManagerServer
-Djava.security.policy="C:\Development\Eclipse\Workspace\Library-Manager-Server\security.policy"
-Djava.rmi.server.codebase="file:/C:/Development/Eclipse/Workspace/Library-Manager-Server/bin/ file:/C:/Development/Eclipse/Workspace/Library-Manager-Common/bin/"
The class is definitely there in the bin (where eclipse drops it) but for some reason (probably trivial) it cannot be found when I run the cmd line above.
Any help appreciated!
EDIT#1: as some of you may have guessed classname is demo.rmi.librarymanager.server.LibraryManagerServer
EDIT#2: OK - thanks to people suggestions I think I got the syntax right this time but I am still getting ClassNotFoundException
but on a different class in the common package:
demo.rmi.librarymanager.common.Library
Here's the new cmd line:
java -cp c:/development/eclipse/workspace/Library-Manager-Server/bin demo.rmi.librarymanager.server.LibraryManagerServer
-Djava.security.policy="C:/Development/Eclipse/Workspace/Library-Manager-Server/security.policy"
-Djava.rmi.server.codebase="file:/C:/Development/Eclipse/Workspace/Library-Manager-Server/bin file:/C:/Development/Eclipse/Workspace/Library-Manager-Common/bin"
Shall I add the c:/development/eclipse/workspace/Library-Manager-Common/bin
path (where demo.rmi.librarymanager.common.Library
lives) together with c:/development/eclipse/workspace/Library-Manager-Server/bin
after -cp as a command line argument?
Thanks to everyone for their help and patience - I am working on an RMI application and everything was good till I was working inside eclipse using the RMI plugin but now I am having a bit of an hard time as I am fairly new to java (as you cas see from my question!).
EDIT#3: Ok I got it working:
java -cp c:/development/eclipse/workspace/Library-Manager-Server/bin;c:/development/eclipse/workspace/Library-Manager-Common/bin
demo.rmi.librarymanager.server.LibraryManagerServer
-Djava.security.policy="C:/Development/Eclipse/Workspace/Library-Manager-Server/security.policy"
-Djava.rmi.server.codebase="file:/C:/Development/Eclipse/Workspace/Library-Manager-Server/bin file:/C:/Development/Eclipse/Workspace/Library-Manager-Common/bin"
Thanks to everyone for the shower of humbleness.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
java 命令行是:
我想我看到了你的问题 - 'class' 不是关键字;它是您必须替换的完全限定的类名。
如果您的类文件位于 bin 中,则命令可能如下所示:
命令可能如下所示
如果您位于 Eclipse 项目的目录中,那么
。请注意,Eclipse 有类所在位置的设置(您可以覆盖这些设置)。我发现不同版本的Eclipse默认有不同的。所以我看到了
bin
、classes
或(因为我使用的是 maven)target/classes
。The java commandline is:
I think I see your problem - 'class' is not a keyword; it is the fullyQualified classname that you have to replace it with.
If your class files are in bin then the command might look like:
so perhaps
if you are in the directory of your Eclipse project.
Note that Eclipse has settings (which you can override) for where the classes are. I have found that different versions of Eclipse have different ones by default. So I have seen
bin
,classes
or (as I am using maven)target/classes
.这可能会起作用:
假设您要运行
demo.rmi.librarymanager.server
包中的LibraryManagerServer
类。请注意,如果您在包中使用类(除了简短的测试或学习代码之外,建议这样做),您必须
This will probably work:
This assumes that you want to run the class
LibraryManagerServer
in the packagedemo.rmi.librarymanager.server
.Note that if you use classes in packages (which is advisable except for short test or learning code), you have to
从你的命令行我猜想:
Java路径使用/作为分隔符,即使在widnows上,类路径也应该指向包层次结构的根,并且要运行的类以相对于类路径的包表示法给出。
From your commandline I would guess:
Java paths use / as separators, even on widnows, the classpath should point to the root of your package hierarchy and the class to run is given in package notation relative to the classpath.