java - 不再找到属性文件/无效的块类型
问题描述
以下代码正在(正确地)读取我的 Eclipse 项目中 src/main/resources 下的 jar 中的属性文件:
public static void getClassPathProperties() {
LOGGER.debug("getClassPathProperties Enter");
try (final InputStream input = Utils.class.getClassLoader().getResourceAsStream("environment.properties")) {
properties.load(input);
} catch (Exception e) {
LOGGER.error("Unable to find environment.properties on classpath to Utils.class");
e.printStackTrace();
}
}
此代码是 JBPM WorkItemHandler 的一部分,以使特定容器(jar 文件)能够使用特定于环境的属性。作为WorkItemHandler 的一个jar,这个jar 是另一个jar 的依赖,这个jar 是JBPM 调用的容器。我添加了一行,为从 JBPM 到外部服务的 REST 调用的连接添加了一个额外的属性:
connection.setRequestProperty("EDIPI_NUM", edipi);
connection.setRequestProperty("NPKE_SUBJECT", npkeSubject);
connection.setRequestProperty("NPKE_UPN", npkeSubject); // Line added
做了一个干净的重建,现在得到错误:
^[[0m^[[31m16:07:56,247 ERROR [com.goprecise.ams.handlers.utils.Utils] (default task-1000) Unable to find environment.properties on classpath to Utils.class
^[[0m^[[31m16:07:56,247 ERROR [stderr] (default task-1000) java.util.zip.ZipException: invalid block type
^[[0m^[[31m16:07:56,247 ERROR [stderr] (default task-1000) at java.util.zip.InflaterInputStream.read(InflaterInputStream.java:164)
^[[0m^[[31m16:07:56,247 ERROR [stderr] (default task-1000) at java.io.FilterInputStream.read(FilterInputStream.java:133)
^[[0m^[[31m16:07:56,247 ERROR [stderr] (default task-1000) at java.io.FilterInputStream.read(FilterInputStream.java:107)
^[[0m^[[31m16:07:56,247 ERROR [stderr] (default task-1000) at java.util.Properties$LineReader.readLine(Properties.java:435)
^[[0m^[[31m16:07:56,247 ERROR [stderr] (default task-1000) at java.util.Properties.load0(Properties.java:353)
^[[0m^[[31m16:07:56,247 ERROR [stderr] (default task-1000) at java.util.Properties.load(Properties.java:341)
^[[0m^[[31m16:07:56,247 ERROR [stderr] (default task-1000) at com.goprecise.ams.handlers.utils.Utils.getClassPathProperties(Utils.java:55)
environment.properties 文件放在构建的 jar 的根目录下。因为我有一个复杂的 pom.xml,我想知道 pom.xml 中的某些内容是否会导致代码不再工作?如果不是,还有什么可能导致错误?
<build>
<sourceDirectory>${project.build.directory}/generated-sources/java</sourceDirectory>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>false</filtering>
<includes>
<include>*.*</include>
</includes>
</resource>
<resource>
<directory>${project.build.directory}/maven-shared-archive-resources</directory>
<filtering>true</filtering>
<includes>
<include>*.part</include>
</includes>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>templating-maven-plugin</artifactId>
<version>1.0.0</version>
<executions>
<execution>
<id>filter-src</id>
<goals>
<goal>filter-sources</goal>
</goals>
<configuration>
<sourceDirectory>${basedir}/src/main/java</sourceDirectory>
<outputDirectory>${project.build.directory}/generated-sources/java</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>3.1.0</version>
<executions>
<execution>
<id>copy-repository-resources</id>
<phase>compile</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<encoding>UTF-8</encoding>
<resources>
<resource>
<directory>target/generated-sources/annotations</directory>
<includes>
<include>repoindex.html</include>
<include>*.wid</include>
</includes>
<filtering>true</filtering>
</resource>
</resources>
<outputDirectory>target/classes</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<annotationProcessors>
<annotationProcessor>org.jbpm.process.workitem.core.util.WidProcessor</annotationProcessor>
</annotationProcessors>
<compilerArgs>
<arg>-AwidName=${project.artifactId}</arg>
<arg>-AgenerateTemplates=true</arg>
<arg>-AgenerateWids=true</arg>
<arg>-AwidsResources=${project.artifactId}.wid:widtemplate.st</arg>
<arg>-AtemplateResources=kie-deployment-descriptor.xml:kie-ddtemplate.st,serviceinfo.json:serviceinfo.st,repoindex.html:repoindex.part,index.html:indextemplate.st,${project.artifactId}.bpmn2:defaultprocess.st</arg>
</compilerArgs>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.3.0</version>
<configuration>
<!-- root module has no assembly so ignore it -->
<ignoreMissingDescriptor>true</ignoreMissingDescriptor>
<descriptors>
<descriptor>${project.basedir}/assembly/assembly.xml</descriptor>
</descriptors>
<archive>
<addMavenDescriptor>false</addMavenDescriptor>
</archive>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<appendAssemblyId>false</appendAssemblyId>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.22.2</version>
<executions>
<execution>
<id>integration-test-execution</id>
<phase>verify</phase>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
<configuration>
<systemPropertyVariables>
<groupId>${project.groupId}</groupId>
<artifactId>${project.artifactId}</artifactId>
<version>${project.version}</version>
<builddir>${project.build.directory}</builddir>
</systemPropertyVariables>
<failIfNoTests>false</failIfNoTests>
<test>${it.test}</test>
<includes>
<include>**/*IntegrationTest.java</include>
</includes>
<argLine>${failsafe.arg.line}</argLine>
</configuration>
</plugin>
<plugin>
<groupId>org.commonjava.maven.plugins</groupId>
<artifactId>project-sources-maven-plugin</artifactId>
<version>1.1</version>
<executions>
<execution>
<id>project-sources</id>
<goals>
<goal>archive</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
<configuration>
<includes>
<include>**/*Test.java</include>
</includes>
<excludes>
<exclude>**/*IntegrationTest.java</exclude>
</excludes>
<argLine>-Xmx1024m -Dfile.encoding=UTF-8</argLine>
<systemPropertyVariables>
<apple.awt.UIElement>true</apple.awt.UIElement>
<org.uberfire.nio.git.daemon.enabled>false</org.uberfire.nio.git.daemon.enabled>
<org.uberfire.nio.git.ssh.enabled>false</org.uberfire.nio.git.ssh.enabled>
<org.uberfire.sys.repo.monitor.disabled>true</org.uberfire.sys.repo.monitor.disabled>
</systemPropertyVariables>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.2.0</version>
<executions>
<execution>
<id>default-jar</id>
</execution>
<!-- No OSGi manifestEntries for <goal>jar</goal>: if it supported, then felix has already added them -->
<execution>
<id>test-jar</id>
<goals>
<goal>test-jar</goal>
</goals>
<configuration>
<skipIfEmpty>true</skipIfEmpty>
<excludes>
<exclude>**/logback-test.xml</exclude>
<exclude>**/jndi.properties</exclude>
</excludes>
<archive>
<manifestEntries>
<Bundle-SymbolicName>${java.module.name}.tests</Bundle-SymbolicName>
<Bundle-Version>
${parsedVersion.majorVersion}.${parsedVersion.minorVersion}.${parsedVersion.incrementalVersion}.${osgi.snapshot.qualifier}
</Bundle-Version>
<Bundle-Name>${project.name}</Bundle-Name>
<Bundle-Vendor>${project.organization.name}</Bundle-Vendor>
</manifestEntries>
</archive>
</configuration>
</execution>
</executions>
<configuration>
<archive>
<manifest>
<addDefaultSpecificationEntries>true</addDefaultSpecificationEntries>
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-remote-resources-plugin</artifactId>
<version>1.5</version>
<configuration>
<resourceBundles>
<resourceBundle>org.jbpm.contrib:template-resources:${version.org.kie}</resourceBundle>
</resourceBundles>
</configuration>
<executions>
<execution>
<goals>
<goal>process</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
解决方案
推荐阅读
- r - 如何创建一个循环来更改数据框中的部分列名
- c - 为什么我的 Visual Studio 在我 pthread_kill(runTheGame,SIGQUIT); 时说“SIGQUIT”未定义?
- amazon-s3 - 从 S3 存储桶读取多个文件并使用 Lambda 触发器处理它们
- python - with_entities 指的是别名为
- flutter - 如何在父小部件上为孩子设置图标大小
- javascript - 为什么 switch 语句只运行默认值而忽略其余条件?
- antlr - 在 xtext 中使用 int 和字符串编写规则的正确方法是什么?
- laravel - 使用 laravel 搜索日期不在查询之间
- angular - 使用地图填充对象时出现角度错误
- image - 图像的线性分类如何等同于模板匹配?