最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

How to create a pure JavaScript project using Maven? - Stack Overflow

programmeradmin14浏览0评论

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 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 ?

Share Improve this question edited May 28, 2017 at 18:46 Badacadabra 8,5277 gold badges31 silver badges54 bronze badges asked Mar 2, 2015 at 10:29 RiduidelRiduidel 22.3k15 gold badges90 silver badges191 bronze badges 1
  • Did you have success setting up the project, if not i would try to create an example. – Martin Baumgartner Commented Mar 2, 2015 at 15:26
Add a ment  | 

1 Answer 1

Reset to default 5

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=.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./baumgartner/maven-webjars-plain-webproject

发布评论

评论列表(0)

  1. 暂无评论