简体   繁体   English

指导构建我的NetBeans Java项目

[英]Guidance on structuring my NetBeans Java project

To date, I have always coded using a text editor, and compiling using CLI (Windows and Mac). 迄今为止,我一直使用文本编辑器进行编码,并使用CLI(Windows和Mac)进行编译。 This is the first time I've used an IDE, and I have chosen NetBeans. 这是我第一次使用IDE,并且选择了NetBeans。 It is also the first time I have come across packages. 这也是我第一次遇到软件包。

Would appreciate some guidance/direction on how to setup my project. 希望对如何设置项目有一些指导/指导。

My project consists of: - a Server app - a Client app - common objects 我的项目包括:-服务器应用程序-客户端应用程序-常见对象

This is what I have done: 这是我所做的:

  1. Create a Project 建立专案
  2. Under this project, I created three packages: 在这个项目下,我创建了三个包:
    • Server - source files specific only to my Server application 服务器-仅适用于我的服务器应用程序的源文件
    • Client - source files specific only to my Client application 客户端-仅针对我的客户端应用程序的源文件
    • Common - common files shared by both Server and Client applications, such as RMISSLClientSocketFactory, remote interface and implementation, keystore files etc 公用-服务器和客户端应用程序共享的公用文件,例如RMISSLClientSocketFactory,远程接口和实现,密钥库文件等

Is this the right approach? 这是正确的方法吗?

And also, what do I need to do to enable the Server all and Client app can call/access the classes in the Common package? 而且,我需要做些什么来启用全部服务器,并且客户端应用程序可以调用/访问Common包中的类?

Many thanks in advance. 提前谢谢了。

General convention would suggestion your top level package name should be the reverse of you companies web address (ie com.stackoverflow ). 一般约定建议您的顶级软件包名称应与您公司的网址相反(即com.stackoverflow )。

Now not everybody has a company (or web address), in these cases you want to choice something that will (as well as possible) uniquely identify you package (the purpose of packages is to provide name space, so you can have more the one class with the same name and be able to differentiate between them, amongst other things). 现在,并不是每个人都拥有公司(或网址),在这种情况下,您想选择一种能够(尽可能)唯一标识您的包裹的包裹(包裹的目的是提供名称空间,因此您可以拥有更多具有相同名称的课程,并且能够区分(其中包括其他内容)。

In may case I might choose to use mad.programmer for example... 在某些情况下,我可能会选择使用mad.programmer例如...

The next level should identify the application or library (I personally use things like .core and .core.ui for my core libraries, but you can make you own choices) 下一级别应标识应用程序或库(我个人将.core.core.ui用于我的核心库,但您可以自行选择)

At this point, you're basically free to group as you see fit. 此时,您基本上可以自由地按自己的意愿分组。

Now, to the question at hand. 现在,到手头的问题。

In your case, I would create three projects. 在您的情况下,我将创建三个项目。 One being for the server code, one being for the client code and one for you common classes (which would be shared between the server and client). 一种用于服务器代码,一种用于客户端代码,一种用于您的通用类(将在服务器和客户端之间共享)。

I would link the common project to your server and client projects (right click the Libraries node of the project (client and/or server) and select Add Project ). 我会将普通项目链接到您的服务器和客户端项目(右键单击项目(客户端和/或服务器)的Libraries节点,然后选择Add Project )。

Personally, I would use the .client , .server , .common suffixes to you package names just to separate the code but the only really requirement is to provide your common library with it's own name space, separate from the server and client. 就我个人而言,我会使用.client.server.common后缀作为包名来分隔代码,但唯一的真正要求是为您的公共库提供其自己的名称空间,与服务器和客户端分开。

So long as you haven't changed any code that the sever and client rely-on to communicate (objects that might be passed between them at runtime), you can rebuild either project without affecting the other. 只要您没有更改服务器和客户端依赖进行通信的任何代码(在运行时可能在它们之间传递的对象),就可以重建任何一个项目而不会影响另一个项目。

That's my take on it any way. 那是我的看法。

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

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