添加 jai 作为 wildfly 模块
Add jai as wildfly module
我有一个javabean项目,需要用到jai,所以加了一个maven依赖
<dependency>
<groupId>com.github.jai-imageio</groupId>
<artifactId>jai-imageio-core</artifactId>
<version>1.3.1</version>
</dependency>
我尝试向 wildfly 9 添加新模块,例如
module.xml
<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.3" name="com.github.jaiimageio">
<resources>
<resource-root path="jai-imageio-core-1.3.1.jar"/>
</resources>
</module>
然后我从 mvnrepo 添加一个 jar
并将 jar+module.xml 放入
wildfly-9.0.2.Final\modules\system\layers\base\com\github\jaiimageio\main
然后在我的Java项目中
jboss-部署-structure.xml
<jboss-deployment-structure>
<deployment>
<dependencies>
<module name="org.jboss.ejb3"/>
<module name="org.jboss.ws.api"/>
<module name="org.apache.cxf"/>
<module name="org.jboss.ws.cxf.jbossws-cxf-server"/>
<module name="com.github.jaiimageio"/>
</dependencies>
</deployment>
</jboss-deployment-structure>
但是当我尝试调用我的 java bean 时出现异常
Caused by: java.util.NoSuchElementException
at javax.imageio.spi.FilterIterator.next(ServiceRegistry.java:836)
at javax.imageio.ImageIO$ImageWriterIterator.next(ImageIO.java:842)
at javax.imageio.ImageIO$ImageWriterIterator.next(ImageIO.java:827)
at ru.shop.createFile.CreateFileBean.write_tiff(CreateFileBean.java:541)
at ru.shop.createFile.CreateFileBean.testAdd(CreateFileBean.java:77)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.jboss.as.ee.component.ManagedReferenceMethodInterceptor.processInvocation(ManagedReferenceMethodInterceptor.java:52)
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)
at org.jboss.invocation.InterceptorContext$Invocation.proceed(InterceptorContext.java:437)
at org.jboss.as.weld.ejb.Jsr299BindingsInterceptor.doMethodInterception(Jsr299BindingsInterceptor.java:82)
at org.jboss.as.weld.ejb.Jsr299BindingsInterceptor.processInvocation(Jsr299BindingsInterceptor.java:93)
at org.jboss.as.ee.component.interceptors.UserInterceptorFactory.processInvocation(UserInterceptorFactory.java:63)
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)
at org.jboss.as.ejb3.component.invocationmetrics.ExecutionTimeInterceptor.processInvocation(ExecutionTimeInterceptor.java:43)
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)
at org.jboss.as.jpa.interceptor.SBInvocationInterceptor.processInvocation(SBInvocationInterceptor.java:47)
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)
at org.jboss.invocation.InterceptorContext$Invocation.proceed(InterceptorContext.java:437)
at org.jboss.weld.ejb.AbstractEJBRequestScopeActivationInterceptor.aroundInvoke(AbstractEJBRequestScopeActivationInterceptor.java:73)
at org.jboss.as.weld.ejb.EjbRequestScopeActivationInterceptor.processInvocation(EjbRequestScopeActivationInterceptor.java:83)
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)
at org.jboss.as.ee.concurrent.ConcurrentContextInterceptor.processInvocation(ConcurrentContextInterceptor.java:45)
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)
at org.jboss.invocation.InitialInterceptor.processInvocation(InitialInterceptor.java:21)
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)
at org.jboss.invocation.ChainedInterceptor.processInvocation(ChainedInterceptor.java:61)
at org.jboss.as.ee.component.interceptors.ComponentDispatcherInterceptor.processInvocation(ComponentDispatcherInterceptor.java:52)
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)
at org.jboss.as.ejb3.component.interceptors.NonPooledEJBComponentInstanceAssociatingInterceptor.processInvocation(NonPooledEJBComponentInstanceAssociatingInterceptor.java:59)
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)
at org.jboss.as.ejb3.tx.CMTTxInterceptor.invokeInOurTx(CMTTxInterceptor.java:275)
... 79 more
我的代码:
private void write_tiff() throws IOException
{
RenderedImage image=javax.imageio.ImageIO.read(new File("C:\users\user\Desktop\examples\srts.jpg"));
RenderedImage image1=javax.imageio.ImageIO.read(new File("C:\users\user\Desktop\examples\passport.jpg"));
Iterator<ImageWriter> iterator=ImageIO.getImageWritersByFormatName("TIFF");
System.out.println(iterator.hasNext());
ImageWriter writer=iterator.next();
}
ImageIO.getImageWritersByFormatName("TIFF") returns 空。
但是如果我从 java 应用程序调用此方法,而不是在 java bean 中,一切正常。
我尝试将模块名称更改为 com.github.jai-imageio,但没有更改。
有人可以帮我吗?
我可以在不向jvm的ext添加jar的情况下解决这个问题
代码:
ImageIO.scanForPlugins();
ByteArrayOutputStream output_stream=new ByteArrayOutputStream();
try
{
ImageOutputStream output = ImageIO.createImageOutputStream(output_stream);
ImageWriter writer = new TIFFImageWriterSpi().createWriterInstance();
writer.setOutput(output);
writer.prepareWriteSequence(null);
writeToSequence(new IIOImage(ImageIO.read(new ByteArrayInputStream(bytes)),null,null),null);
writer.endWriteSequence();
writer.dispose();
output.flush();
output.close();
pom 依赖:
<dependency>
<groupId>com.sun.media</groupId>
<artifactId>jai_imageio</artifactId>
<version>1.2-pre-dr-b04</version>
</dependency>
module.xml (wildfly\modules\system\layers\base\com\sun\media\imageio\main)
<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.1" name="com.sun.media.imageio">
<resources>
<resource-root path="jai_imageio-1.2-pre-dr-b04.jar"/>
<resource-root path="clibwrapper_jiio-1.2-pre-dr-b04.jar"/>
</resources>
<dependencies>
<module name="javax.api"/>
</dependencies>
</module>
我有一个javabean项目,需要用到jai,所以加了一个maven依赖
<dependency>
<groupId>com.github.jai-imageio</groupId>
<artifactId>jai-imageio-core</artifactId>
<version>1.3.1</version>
</dependency>
我尝试向 wildfly 9 添加新模块,例如
module.xml
<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.3" name="com.github.jaiimageio">
<resources>
<resource-root path="jai-imageio-core-1.3.1.jar"/>
</resources>
</module>
然后我从 mvnrepo 添加一个 jar 并将 jar+module.xml 放入
wildfly-9.0.2.Final\modules\system\layers\base\com\github\jaiimageio\main
然后在我的Java项目中
jboss-部署-structure.xml
<jboss-deployment-structure>
<deployment>
<dependencies>
<module name="org.jboss.ejb3"/>
<module name="org.jboss.ws.api"/>
<module name="org.apache.cxf"/>
<module name="org.jboss.ws.cxf.jbossws-cxf-server"/>
<module name="com.github.jaiimageio"/>
</dependencies>
</deployment>
</jboss-deployment-structure>
但是当我尝试调用我的 java bean 时出现异常
Caused by: java.util.NoSuchElementException
at javax.imageio.spi.FilterIterator.next(ServiceRegistry.java:836)
at javax.imageio.ImageIO$ImageWriterIterator.next(ImageIO.java:842)
at javax.imageio.ImageIO$ImageWriterIterator.next(ImageIO.java:827)
at ru.shop.createFile.CreateFileBean.write_tiff(CreateFileBean.java:541)
at ru.shop.createFile.CreateFileBean.testAdd(CreateFileBean.java:77)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.jboss.as.ee.component.ManagedReferenceMethodInterceptor.processInvocation(ManagedReferenceMethodInterceptor.java:52)
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)
at org.jboss.invocation.InterceptorContext$Invocation.proceed(InterceptorContext.java:437)
at org.jboss.as.weld.ejb.Jsr299BindingsInterceptor.doMethodInterception(Jsr299BindingsInterceptor.java:82)
at org.jboss.as.weld.ejb.Jsr299BindingsInterceptor.processInvocation(Jsr299BindingsInterceptor.java:93)
at org.jboss.as.ee.component.interceptors.UserInterceptorFactory.processInvocation(UserInterceptorFactory.java:63)
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)
at org.jboss.as.ejb3.component.invocationmetrics.ExecutionTimeInterceptor.processInvocation(ExecutionTimeInterceptor.java:43)
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)
at org.jboss.as.jpa.interceptor.SBInvocationInterceptor.processInvocation(SBInvocationInterceptor.java:47)
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)
at org.jboss.invocation.InterceptorContext$Invocation.proceed(InterceptorContext.java:437)
at org.jboss.weld.ejb.AbstractEJBRequestScopeActivationInterceptor.aroundInvoke(AbstractEJBRequestScopeActivationInterceptor.java:73)
at org.jboss.as.weld.ejb.EjbRequestScopeActivationInterceptor.processInvocation(EjbRequestScopeActivationInterceptor.java:83)
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)
at org.jboss.as.ee.concurrent.ConcurrentContextInterceptor.processInvocation(ConcurrentContextInterceptor.java:45)
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)
at org.jboss.invocation.InitialInterceptor.processInvocation(InitialInterceptor.java:21)
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)
at org.jboss.invocation.ChainedInterceptor.processInvocation(ChainedInterceptor.java:61)
at org.jboss.as.ee.component.interceptors.ComponentDispatcherInterceptor.processInvocation(ComponentDispatcherInterceptor.java:52)
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)
at org.jboss.as.ejb3.component.interceptors.NonPooledEJBComponentInstanceAssociatingInterceptor.processInvocation(NonPooledEJBComponentInstanceAssociatingInterceptor.java:59)
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)
at org.jboss.as.ejb3.tx.CMTTxInterceptor.invokeInOurTx(CMTTxInterceptor.java:275)
... 79 more
我的代码:
private void write_tiff() throws IOException
{
RenderedImage image=javax.imageio.ImageIO.read(new File("C:\users\user\Desktop\examples\srts.jpg"));
RenderedImage image1=javax.imageio.ImageIO.read(new File("C:\users\user\Desktop\examples\passport.jpg"));
Iterator<ImageWriter> iterator=ImageIO.getImageWritersByFormatName("TIFF");
System.out.println(iterator.hasNext());
ImageWriter writer=iterator.next();
}
ImageIO.getImageWritersByFormatName("TIFF") returns 空。
但是如果我从 java 应用程序调用此方法,而不是在 java bean 中,一切正常。
我尝试将模块名称更改为 com.github.jai-imageio,但没有更改。
有人可以帮我吗?
我可以在不向jvm的ext添加jar的情况下解决这个问题
代码:
ImageIO.scanForPlugins();
ByteArrayOutputStream output_stream=new ByteArrayOutputStream();
try
{
ImageOutputStream output = ImageIO.createImageOutputStream(output_stream);
ImageWriter writer = new TIFFImageWriterSpi().createWriterInstance();
writer.setOutput(output);
writer.prepareWriteSequence(null);
writeToSequence(new IIOImage(ImageIO.read(new ByteArrayInputStream(bytes)),null,null),null);
writer.endWriteSequence();
writer.dispose();
output.flush();
output.close();
pom 依赖:
<dependency>
<groupId>com.sun.media</groupId>
<artifactId>jai_imageio</artifactId>
<version>1.2-pre-dr-b04</version>
</dependency>
module.xml (wildfly\modules\system\layers\base\com\sun\media\imageio\main)
<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.1" name="com.sun.media.imageio">
<resources>
<resource-root path="jai_imageio-1.2-pre-dr-b04.jar"/>
<resource-root path="clibwrapper_jiio-1.2-pre-dr-b04.jar"/>
</resources>
<dependencies>
<module name="javax.api"/>
</dependencies>
</module>