Java project structure explained for newbies?

前端 未结 10 1062
攒了一身酷
攒了一身酷 2020-12-07 13:15

I come from a .NET background and am completely new to Java and am trying to get my head around the Java project structure.

My typical .NET solution structure conta

10条回答
  •  无人及你
    2020-12-07 14:01

    A package is much like a .Net namespace. The general convention in Java is to use your reversed domain name as a package prefix so if your company is example.com your packages will probably be:

    com.example.projectname.etc...
    

    It can be broken down to many levels rather than just one (projectname) but usually one is sufficient.

    Inside your project structure classes are usually divided into logical areas: controllers, models, views, etc. It depends on the type of project.

    There are two dominant build systems in Java: Ant and Maven.

    Ant is basically a domain-specific scripting language and quite flexible but you end up writing a lot of boilerplate stuff yourself (build, deploy, test, etc tasks). It's quick and convenient though.

    Maven is more modern and more complete and is worth using (imho). Maven is different to Ant in that Maven declares that this project is a "Web application project" (called an archetype). Once that is declared the directory structure is mandated once you specify your groupId (com.example) and artifactId (project name).

    You get a lot of stuff for free this way. The real bonus of Maven is that it manages your project dependencies for you so with a pom.xml (Maven project file) and correctly configured Maven you can give that to someone else (with your source code) and they can build, deploy, test and run your project with libraries being downloaded automatically.

    Ant gets something like this with Ivy.

提交回复
热议问题