简体   繁体   English

如何构造Java项目?

[英]How to structure a java project?

After two year of learning, I realize that my school didn't teach us any project structuring ... 经过两年的学习,我意识到我的学校没有教我们任何项目结构...

I want to make games for a living, so I tried to start a little project on my own for self-learning. 我想以玩游戏为生,所以我尝试自己做一个小项目以进行自学。 But I'm stuck on a little problem : I can't find the relative Path to my background's .gif file for my test-project. 但是我遇到了一个小问题:我找不到我的测试项目的背景.gif文件的相对路径。

Here 's how I've structured my project so far : 到目前为止,这是我组织项目的方式:
项目结构

Is that a "proper" way to structure a project ? 这是构造项目的“正确”方法吗? Even If this one is a small one, once I'll start a "real" big project, should I re-structure like that ? 即使这个项目很小,一旦我开始一个“真正的”大项目,我是否应该像这样重组?

For my path problem, here's some of the thing I've tried (I work with javaFx) : 对于我的路径问题,这是我尝试过的一些事情(我使用javaFx):

Image bg = new Image("../assets/sprite/Backgrounds/farback.gif");
Image bg = new Image("/assets/sprite/Backgrounds/farback.gif");
Image bg = new Image("assets/sprite/Backgrounds/farback.gif");
Image bg = new Image("farback.gif");
Image bg = new Image("..\\assets\\sprite\\Backgrounds\\farback.gif");
Image bg = new Image("assets\\sprite\\Backgrounds\\farback.gif");
...

And so on, but none of them have work. 依此类推,但他们都没有工作。
Also this is the first time I use a recursive URL on windows, so the problem may come from here ... I've look that up on google but didn't find anything useful ... 这也是我第一次在Windows上使用递归URL,所以问题可能出在这里……我在google上进行了查找,但没有发现任何有用的信息……

I believe Maven has become a standard for most open source projects. 我相信Maven已成为大多数开源项目的标准。 I'd recommend that you follow their directory structure and naming standards. 我建议您遵循它们的目录结构和命名标准。

The other standard you need to be aware of is web app packaging in WARs. 您需要了解的另一个标准是WAR中的Web应用程序打包。 You'll see a /web folder with that represents the root of your WAR context, with a /WEB-INF child. 您将看到一个/ web文件夹,该文件夹代表您的WAR上下文的根,带有/ WEB-INF子级。 You usually put your web asserts at the root of the WAR context. 通常,您将Web断言放在WAR上下文的根目录下。

The Maven convention will have you put your web stuff under /main/resources/static. Maven约定将让您将Web内容放在/ main / resources / static下。 When you have it build your WAR file it'll put them in the right spot. 建立好WAR文件后,它将放置在正确的位置。

Another great recommendation would be Spring Boot . 另一个很好的建议是Spring Boot It might be a little advanced for you, but they also have good recommendations about how to structure applications. 它可能对您来说有点高级,但是他们也对如何构建应用程序提供了很好的建议。

Take a look at the following link, the author goes into more detail on structuring: Java project structural best practices 看一下下面的链接,作者将详细介绍结构化: Java项目结构最佳实践

 basic-maven-project/ 
 |-- pom.xml
 |-- src
 |   |-- main
 |   |   |-- java
 |   |   |-- resources
 |   |       `-- webapp

 |   |       `-- WEB-INF
 |        `-- test

 |       |-- java

 |       `-- resources
        `-- target
 |-- classes
       `-- test-classes

See chosen answer in this post 看到这篇文章中选择的答案

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

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