我正在尝试读取其中一个包中的图像并将其放在我的pdf中(使用iText)。当我在RAD-WAS中部署应用程序时,它成功地使用图像创建PDF。但是,当我通过maven生成EAR并在WAS中部署时,它显示错误。
一段代码
InputStream inStream = this.getClass().getClassLoader().getResourceAsStream("com/myComp/pdf/logo/image.tif");
LOGGER.error("inStream = " +inStream);
Image img = null;
try{
img = Image.getInstance(IOUtils.toByteArray(inStream));
LOGGER.error("img =" + img);
}catch(IOException ex) {
LOGGER.error("Caught IOException ="+ex);
}
输出:
1)在本地部署时
inStream = java.io.BufferedInputStream@10f910f9
并且成功运行
2)当通过maven生成EAR时
inStream = com.ibm.ws.classloader.Handler$ZipEntryInputStream@489e489e
Caught IOException =java.io.IOException: The byte array is not a recognized imageformat.
在我的POM中,我保留了
<dependencies>
<dependency>
<groupId>com.ibm.websphere</groupId>
<artifactId>bootstrap</artifactId>
<version>7.0.0.19</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.ibm.websphere</groupId>
<artifactId>com.ibm.jaxb.tools</artifactId>
<version>7.0.0.19</version>
<scope>provided</scope>
</dependency>
....
<dependencies>
在我的POM中,我保留了过滤器属性,如下所示
<resource>
<directory>${project.basedir}/${rad.sourcedir}
</directory>
<filtering>true</filtering>
<excludes>
<exclude>**/*.java</exclude>
<exclude>*.classpath</exclude>
<exclude>*.project</exclude>
</excludes>
</resource>
</resources>
还保留了像
这样的属性<properties>
<application.systemletters>IRI</application.systemletters>
<project.build.sourceEncoding>Cp1252</project.build.sourceEncoding>
.....
</properties>
我想通过将其作为新文件(“..”)读取来删除“this.getClass()。getClassLoader()。getResourceAsStream”,但仍然不成功。
File file1 = new File("com/myComp/pdf/logo/image.tif");
InputStream fIn = new FileInputStream(file1);
LOGGER.error("fIn="+fIn);
BufferedInputStream bIn = new BufferedInputStream(fIn);
LOGGER.error("bIn="+bIn);
Image img = null;
try{
img = Image.getInstance(IOUtils.toByteArray(inStream));
LOGGER.error("img =" + img);
}catch(IOException ex) {
LOGGER.error("Caught IOException ="+ex);
}
OutPut:
fIn=java.io.FileInputStream@3dac3dac
bIn=java.io.BufferedInputStream@c420c42
Caught IOException =java.io.IOException: The byte array is not a recognized imageformat.
现在,如何让我的图像通过maven获得PDF格式。