I want to create a single page webapp front-end using Maven.
My goal here is quite simple: I have some dependencies expressed as webjars and I want to be able to reference them from my HTML page.
I also want to have them served through a simple HTTP server.
What is the best way to do that ?
I didn't use webjars yet, but it looks like a nice project which i had to take a closer look into it. I like it and will port my hobby-project to use it :)
Take a look into the documentation to the servlet 3 section, it's really straight forward.
If you are not familiar with maven, here the necessary part:
Create a maven project
mvn archetype:generate -DgroupId=com.domain.app -DartifactId=my-webapp -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false
You are done!
As a last step, add maven-dependency-plugin to your pom.xml, and use the unpack-dependencies goal to unpack all the jar resources to a folder. The web-build folder can be deployed to your http server.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>resource-dependencies</id>
<phase>process-resources</phase>
<goals>
<goal>unpack-dependencies</goal>
</goals>
<configuration>
<includeGroupIds>org.webjars</includeArtifactIds>
<outputDirectory>${project.build.directory}/web-build</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
Unfortunatly, I haven't done this yet, but this answer should contain all the instructions to build your project. And also, you should be able to host the jar on a servlet 3 application server.
I've created an example project and published it on my github account: https://github.com/baumgartner/maven-webjars-plain-webproject
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With