我有许多NIFI处理器,它们被构建到一个NAR文件中。项目的结构是这样定义的 org.apache.nifi:nifi-processor-bundle-archetype
. 其中一些处理器依赖于mainresources目录下的数据文件,我需要在运行时加载这些文件,而不是在数据库或外部资源中。由于资源在classpath上,所以所有工作都能在本地进行,单元测试也能通过。
通常,我会使用maven-assembly-plugin来创建一个带有依赖关系的jar,这样资源就会和JAT捆绑在一起。但我无法在最终的NAR中得到同样的结果。
我应该在父pom.xml(或模块pom.xml)中包含什么正确的构建配置以确保资源被捆绑到最终的NAR中?
主父 pom.xml
<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>
<parent>
<groupId>org.apache.nifi</groupId>
<artifactId>nifi-nar-bundles</artifactId>
<version>1.9.2</version>
</parent>
<groupId>com.example.nifi</groupId>
<artifactId>nifiprocessors</artifactId>
<version>1.9.2</version>
<packaging>pom</packaging>
<modules>
<module>nifi-processors</module>
<module>nifi-nar</module>
</modules>
</project>
nifi处理器.pom
<?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>
<parent>
<groupId>com.example.nifi</groupId>
<artifactId>nifiprocessors</artifactId>
<version>1.9.2</version>
</parent>
<artifactId>nifi-processors</artifactId>
<packaging>jar</packaging>
<dependencies>
...
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
nifi-nar.pom
<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>
<parent>
<groupId>com.example.nifi</groupId>
<artifactId>nifiprocessors</artifactId>
<version>1.9.2</version>
</parent>
<artifactId>nifi-nar</artifactId>
<version>1.9.2</version>
<packaging>nar</packaging>
<properties>
<maven.javadoc.skip>true</maven.javadoc.skip>
<source.skip>true</source.skip>
</properties>
<dependencies>
<dependency>
<groupId>com.example.nifi</groupId>
<artifactId>nifi-processors</artifactId>
<version>1.9.2</version>
</dependency>
</dependencies>
</project>
任何在 srcmainresources 中的文件都会自动进入 Maven 生成的 Jar 中,而不需要使用任何额外的插件。如果你有一个文件srcmainresourcesfoo.txt,并建立了一个jar,foo.txt将在jar的根部,旁边是srcmainjava的任何包。