[英]How to create a pure JavaScript project using Maven?
I want to create a single page webapp front-end using Maven. 我想使用Maven创建单页webapp前端。
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. 我的目标非常简单:我有一些表示为webjars的依赖项 ,我希望能够从我的HTML页面引用它们。
I also want to have them served through a simple HTTP server. 我也希望通过简单的HTTP服务器提供服务。
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. 我还没有使用webjars,但它看起来像一个很好的项目,我不得不仔细研究它。 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. 看一下servlet 3部分的文档,它非常简单。
If you are not familiar with maven, here the necessary part: 如果你不熟悉maven,这里有必要的部分:
Create a maven project 创建一个maven项目
mvn archetype:generate -DgroupId=com.domain.app -DartifactId=my-webapp -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false 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. 最后一步,将maven-dependency-plugin添加到pom.xml中,并使用unpack-dependencies目标将所有jar资源解压缩到一个文件夹。 The web-build folder can be deployed to your http server.
web-build文件夹可以部署到您的http服务器。
<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.
而且,您应该能够在servlet 3应用程序服务器上托管jar。
I've created an example project and published it on my github account: https://github.com/baumgartner/maven-webjars-plain-webproject 我创建了一个示例项目并将其发布在我的github帐户上: https : //github.com/baumgartner/maven-webjars-plain-webproject
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.