9

Hello I've been looking for a step by step guide on how to create a webjar of an existing project. My Front-End project is currently using Angular 2 + webpack, I understand the files need to go in a specific directory META-INF/resources/webjars and that there should be a starter Maven pom file somewhere in the project. The thing is I'm not sure where or how to start implementing this inside my project and so I'm asking here if anyone could help me out or knows where I can find a step by step guide for this.

I plan to use the webjar as a dependency for another project built using Spring Boot. Any help is greatly appreciated.

Tuco
  • 712
  • 1
  • 14
  • 31

1 Answers1

7

WebJars is really just a packaging of JS / CSS libs that can easily be used as dependencies in Java builds. By putting the contents of these libraries in the META-INF/resources they are automatically available as static resources in most Java web servers. So to create your own JAR that has static resources in the META-INF/resources you can create a JAR however you like. This is usually done with a build tool like Maven or Gradle. If you want to publish that JAR somewhere that anyone can consume as a dependency then most people use Maven Central.

James Ward
  • 28,966
  • 9
  • 47
  • 79
  • Just a few more questions: I've been using [this](http://www.webjars.org/contributing) to kind of get an idea of the requirements, and need to know a few things about that `pom.xml`. When and where should i generate it? (can it just be a file in the root of my angular app?) And would all I have to do is make sure the angular app compiles all files into a `META-INF/resources` directory? – Tuco Feb 10 '17 at 21:54
  • You can find more info on the `pom.xml` stuff at: https://maven.apache.org/guides/mini/guide-central-repository-upload.html When you say "angular app compiles" what are you using to do that? – James Ward Feb 10 '17 at 22:04
  • Well I'm using webpack with angular so I have a few scripts in my `package.json`: `"start": "npm run server:dev"` -> `"server:dev": "webpack-dev-server --config config/webpack.dev.js --progress --profile --watch --content-base src/"` – Tuco Feb 10 '17 at 22:17
  • So you need a way to then consume that package from a Java app and not a Node app? – James Ward Feb 11 '17 at 13:34
  • Well I planned to upload the webjar to an artifactory so I could then use it from a Java app adding it as a gradle dependency, my current problem is that I have no idea how to generate that webjar. – Tuco Feb 13 '17 at 16:32
  • Here is a WebJar that uses Node to build the contents of the WebJar: https://github.com/webjars/diff/blob/master/pom.xml You could do something similar. – James Ward Feb 13 '17 at 16:48
  • Thanks, I guess I'll try this out and see how everything turns out. – Tuco Feb 13 '17 at 17:14