2

I just made the move from Angular 1 to 2, and now I am going to create a spring mvc maven webapp with angular2 for the front-end side of it.

But everywhere on the internet I see people using node.js for the necessary libraries & plugins. Is there a way I can just use maven dependencies for this?

App structure:

_ main
   _ java
   _ resources
   _ webapp
       _ components
            _ app.component.ts
       _ img
       _ WEB-INF
       _ index.html
       _ main.ts

main.ts

//getting an error on the bootstrap import 
//because the angular2 folders aren't there because there is no node
import {bootstrap} from 'angular2/platform/browser'

import {AppComponent} from './components/app.component.ts'

bootstrap(AppComponent);
2
  • stackoverflow.com/a/17104456/755183 Commented Feb 17, 2016 at 13:31
  • If you want to manage front-end dependencies with Maven, you should check WebJars project. Also there are ways how to invoke Node based tools (such as NPM, Bower or JSPM) from Maven - check maven-frontend-plugin (this is what I would prefer). Commented Feb 17, 2016 at 13:46

1 Answer 1

3

I personaly use Angular2 with a backend in Java, the whole packaged in a .war file.

Backend libraries are managed with Maven, and front end with NPM. My project structure is like this :

_ backend
  _ src
    _ main
      _ java
      _resources
_ frontend
  <angular-cli project>
  _ package.json ...

Note that NPM manage all my front dependencies, for now, I don't bundle anything because my application run in debug for now.

I have a deployement script wich copy the bundled version of my frontend in resources/static (or webapp) folder of the backend.

If you want some help to manage your webapp folder for Angular2, you can try AngularCLI. The project is at a very early stage, but you can do some interesting thing with it, and it will help you to create the boilerplate, it will download for you all the dependencies.

Sign up to request clarification or add additional context in comments.

4 Comments

thx, gonna use npm then, thought there would be another way :) but it's fine
Maybe there is another way, but I don't know him. If your project is quite simple, AngularCLI, is a very good tool. For now there is still some bug when you have a complex project.
@AdrienBARRAL Hi Adrien, I'm in a similar situation (spring, Angular2 to .war) and I was wondering if there's a way to automatically detect changes and reload them in the browser? Do you have a sample project by any chance? Thanks
Hi, @Androidicus. When I am in a developping phase I use live-server, or the HTTP server embedded in Angular-cli. In a developping phase, this is not my backend which serve my application.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.