Вопрос

I'm doing an app that has jee6 backend (json-based api only) and a lot of client side code. It looks like Single Page Application (this cool buzzword these days).

I'm not sure how to structure my codebase. There are ways I consider

  • have separate projects for backend and frontend - this means having backend part in pure java, with maven and all that stuff and have separate frontend with all the js-specific build tools etc.
  • have everything in one project, so that I can get one archive (war) to deploy on server with all the frontend stuff inside. I don't really like that approach...

What about the deployment if I go with the first one? I'd have to build another "war" archive from this frontend part and drop it on the server?

I couldn't find any practices people use.

Это было полезно?

Решение

I would leave your Javascript and CSS package with the WAR and use something like Wro4J (I have my own asset pipeline code I can share at some point).

Heres why:

  1. To ease development you'll want the Javascript/CSS to refresh when you edit them while you run your servlet container. Maven, Eclipse (and/or JRebel) resource refresher will not work with weird package management.
  2. There isn't really any thing like a WAR/JAR for Javascript/CSS only minification (Require.js and JAM are more for dependency loading).

The reason you have separate Java code in separate projects/jars is to avoid coupling, improve reuse, and increase cohesion. What your trying to do for separation is mainly for cohesion. In large part you don't need to separate the Javascript from your Web App because its already probably very separate from the Java and is a completely different language/runtime.

However I can understand if you say wanted to CDN your JS/CSS and why separating the code might be easier for experimenting.

Here are two options:

  1. Git's submodules and have the Javascripts and CSS as separate projects that are submodules to your WAR project.
  2. Have two WAR projects. One with your backend Java code and another with your frontend code. You'll need a container that supports multiple WARS and you will have worry about managing the dreaded servlet container context path.

I have actually done number #2 (laugh at that one) at a previous company I worked for. It worked pretty well. However now days I prefer #1 for its quickness and ease (laugh at that one).

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top