我已经设法从netbeans中的maven项目创建了一个jar文件。但是,我的代码引用了我的项目中的txt文件,所以当我试图在命令提示符上执行Jar file时,我得到一个错误,指出找不到txt文件。
这是我的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>com.mycompany</groupId>
<artifactId>mavenproject3</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<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-assembly-plugin</artifactId>
<version>2.4.1</version>
<configuration>
<!-- get all project dependencies -->
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<!-- MainClass in mainfest make a executable jar -->
<archive>
<manifest>
<mainClass>com.mycompany.mavenproject3.SSBStub</mainClass>
</manifest>
</archive>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<!-- bind to the packaging phase -->
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>com.github.tomakehurst</groupId>
<artifactId>wiremock-standalone</artifactId>
<version>2.17.0</version>
</dependency>
</dependencies>
</project>我可以对pom.xml文件做些什么来消除这个错误吗?
目前我的txt文件在以下目录下: src/text/__ files /
发布于 2018-05-11 06:48:22
要将文件包含到JAR中,可以使用Maven Resource Plugin。它基本上从一个目录(默认情况下是src/main/resources)获取所有文件,并将它们放入您的输出JAR中。
From the examples page of the Resources plugin:
默认情况下,
将在
src/main/resources下查找项目的资源。但是,并不是所有的资源都在src/main/resources中。因此,您必须通过将以下内容添加到POM来指定这些目录。
<project>
...
<build>
...
<resources>
<resource>
<directory>[your folder here]</directory>
</resource>
</resources>
...
</build>
...
</project>https://stackoverflow.com/questions/50282457
复制相似问题