How to create a JavaScript project using Maven?

I want to create a single-page webapp interface using Maven.

My goal here is quite simple: I have some dependencies expressed as webjars and I want to be able to link to them from my HTML page.

I also want them to be served through a simple HTTP server.

What is the best way to do this?

+5
source share
1 answer

I have not used webjars yet, but it looks like a good project that I needed to study more closely. I like it and I will send his hobby project to use it.

Take a look at the documentation for the servlet 3 section, it's really straightforward.

If you are not familiar with maven, here is 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 final step, add the maven-dependency-plugin to your pom.xml and use the unpack-dependencies target to unzip all the jar resources in the folder. The web assembly 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> 

Unfortunately, I have not done this yet, but this answer should contain all the instructions for creating your project. In addition, you should be able to host the jar on the servlet 3 application server.

I created an example project and posted it on my github account: https://github.com/baumgartner/maven-webjars-plain-webproject

+2
source

Source: https://habr.com/ru/post/1214464/


All Articles