Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a pure JavaScript project using Maven?

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 ?

like image 264
Riduidel Avatar asked Mar 02 '15 10:03

Riduidel


1 Answers

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

like image 53
Martin Baumgartner Avatar answered Sep 29 '22 22:09

Martin Baumgartner