I have a simple web app with following structure:
I need to pack it into a jar
. Here's my pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>L1.1</groupId>
<artifactId>L1.1</artifactId>
<version>1.0</version>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<outputDirectory>${basedir}</outputDirectory>
<finalName>server</finalName>
<appendAssemblyId>false</appendAssemblyId>
<archive>
<manifest>
<mainClass>main.Main</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
<resources>
<resource>
<directory>templates</directory>
<includes>
<include>page.html</include>
</includes>
</resource>
</resources>
</build>
<dependencies>
<dependency>
<groupId>org.freemarker</groupId>
<artifactId>freemarker</artifactId>
<version>2.3.20</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-server</artifactId>
<version>9.3.0.M0</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-webapp</artifactId>
<version>9.3.0.M0</version>
</dependency>
</dependencies>
</project>
I pack it with Maven
's assembly:single
option:
But when I run my app with java -jar server.jar
and pass a request in browser I get:
java.io.FileNotFoundException: Template "templates/page.html" not found.
This happens because a folder templates
with page.html
in it is not added to jar
- I unpacked server.jar
searched for it, but didn't find.
I googled a lot something like "maven pack resources into jar" or "maven pack html into jar". And the most close article to my issue was: https://maven.apache.org/plugins/maven-resources-plugin/examples/include-exclude.html
I followed instructions in that article - added <resources>
and rest tags where I outlined my folder and a file that I want to include in jar
(please see it in pom.xml
that I wrote above).
But still this folder and page.html
aren't added.
Please guide me, what I'm doing wrong and how to add templates
folder with page.html
in it in jar
.
在我的情况下,spring框架在SRC下具有资源文件夹...。并且该资源文件夹包含模板文件夹。
Src->resource -> template
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.