简体   繁体   English

Java在多个包中编译RMI服务器/客户端应用程序

[英]Java Compiling RMI Server/Client Application in Multiple Packages

I'm having a bit of trouble with compiling a Java RMI assignment in packages with the command line interface on Windows 10 (can't use Eclipse or any other IDE). 我在使用Windows 10上的命令行界面编译Java RMI分配时遇到了一些麻烦(不能使用Eclipse或任何其他IDE)。 I need to compile and run two .java files - RemoteBankServer.java, and RemoteBankClient.java. 我需要编译并运行两个.java文件 - RemoteBankServer.java和RemoteBankClient.java。 Both of these files use other .java classes (Bank.java, RemoteBankImpl.java, RemoteBank.java, Account.java and subclasses of Account.java). 这两个文件都使用其他.java类(Bank.java,RemoteBankImpl.java,RemoteBank.java,Account.java和Account.java的子类)。 Previously, with all of my files in one folder, I could easily compile and run my server and client with two command line windows, with: 以前,我的所有文件都在一个文件夹中,我可以使用两个命令行窗口轻松编译和运行我的服务器和客户端,其中:

 javac RemoteBankServer.java
 java RemoteBankServer

and the same for RemoteBankClient. 和RemoteBankClient相同。 Now that I've tested that my code works fine, I need to organize them into java packages, following this structure: 现在我已经测试了我的代码工作正常,我需要按照以下结构将它们组织成java包:

- package name: edu.btp400.w2017.client
  class name: RemoteBankClient

- package name: edu.bt400.w2017.server
  class names: RemoteBankImpl, RemoteBankServer

- package name: edu.btp400.w2017.common
  class name: RemoteBank (and all other classes, like Bank, Account, etc.)

I've created those folders (edu/btp400/w2017/) and have placed the appropriate classes in each folder, but I can't get it to compile. 我已经创建了这些文件夹(edu / btp400 / w2017 /)并在每个文件夹中放置了相应的类,但我无法编译它。 For now, I have these two lines at the top of each .java file: 现在,我在每个.java文件的顶部都有这两行:

package edu.btp400.w2017.server;   //or .common or .client
import edu.btp400.w2017.*;

But I'm still getting compilation errors when trying to compile RemoteBankServer.java (in the server folder), such as this (which is weird, because RemoteBankImpl is in the same folder and RemoteBankServer: 但是当我尝试编译RemoteBankServer.java(在服务器文件夹中)时,我仍然遇到编译错误,这很奇怪(这很奇怪,因为RemoteBankImpl在同一个文件夹和RemoteBankServer中:

RemoteBankServer.java:40: error: cannot find symbol
                    RemoteBankImpl b1 = new RemoteBankImpl();
                                            ^
 symbol:   class RemoteBankImpl
 location: class RemoteBankServer

as well as similar errors saying that Account and other classes cannot be found. 以及类似的错误,说无法找到帐户和其他类。 I've looked at various posts on how to compile with Java packages using the command line interface, but I haven't gotten it working. 我已经查看了有关如何使用命令行界面编译Java包的各种帖子,但我还没有得到它的工作。 Any help would be greatly appreciated. 任何帮助将不胜感激。 Sorry for the long post. 对不起,很长的帖子。

Edit: this is the command I used to compile above (after storing the files in various packages): I tried this in the folder containing edu, and got 27 compilation errors: 编辑:这是我上面编译的命令(在各种包中存储文件后):我在包含edu的文件夹中尝试了这个,并得到了27个编译错误:

javac -cp . edu/btp400/w2017/server/RemoteBankServer.java

and this inside the server folder, and got 15 compilation errors: 这在服务器文件夹中,有15个编译错误:

javac RemoteBankServer.java

Edit: Thanks to user EJP, I found out that I needed to include the subfolders in my import statements: instead of just import edu.btp400.w2017.*; 编辑:感谢用户EJP,我发现我需要在我的import语句中包含子文件夹:而不是只import edu.btp400.w2017.*; I needed to do: 我需要这样做:

import edu.btp400.w2017.common.*;
import edu.btp400.w2017.server.*;
import edu.btp400.w2017.client.*;
import edu.btp400.w2017.*;

That doesn't import all the classes in the subpackages indicated by * . 这不会导入*指示的子包中的所有类。 The asterisk only refers to classes. 星号仅指类。

You need to import all the packages individually. 您需要单独导入所有包。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM