我对JMagick库有一些奇怪的问题。我使用Debian,所以我安装了libjmagick6-java和libjmagick6-jni,这是我已经完成的步骤:
jmagick-6.6.9.jar
从/usr/share/java/
复制到$JAVA_HOME/jre/lib/ext/
。/usr/lib/jni
(其中libJMagick.so
)设置为本机库位置:
此外,我已经在简单的Java项目中测试了JMagick并且它可以工作,但是在Tomcat 6中运行的第二个项目是Web应用程序,它只是不起作用..
以下是我的代码 WORKS - 所以必须正确安装jmagick:
public class Main {
public static void main(String[] arg) {
MagickImage image = null;
ImageInfo imageInfo = null;
try {
imageInfo = new ImageInfo("/home/firzen/IMG_0120.JPG");
image = new MagickImage(imageInfo);
System.out.println(image.getDimension().width);
} catch (MagickException e) {
System.out.println(e);
}
image.destroyImages();
}
}
以下是webapp中的代码 NOT WORKING :
public void init() {
ServletContext sc = getServletContext();
cacheHandlers = (Map<String, CacheContext>) sc.getAttribute("handlers");
Boolean applicationReady = (Boolean) sc.getAttribute("ready");
isReady = cacheHandlers != null && Boolean.TRUE.equals(applicationReady);
System.out.println("zde");
MagickImage image = null;
ImageInfo imageInfo = null;
try {
imageInfo = new ImageInfo("/home/firzen/IMG_0120.JPG");
image = new MagickImage(imageInfo);
System.out.println(image.getDimension().width);
} catch (MagickException e) {
System.out.println(e);
}
image.destroyImages();
}
最后,这是所提到的代码抛出的异常:
java.lang.UnsatisfiedLinkError: no JMagick in java.library.path
at java.lang.ClassLoader.loadLibrary(Unknown Source)
at java.lang.Runtime.loadLibrary0(Unknown Source)
at java.lang.System.loadLibrary(Unknown Source)
at magick.Magick.<clinit>(Magick.java:18)
at cz.bach.mrimage.MrImageSrv.init(MrImageSrv.java:44)
at javax.servlet.GenericServlet.init(GenericServlet.java:212)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1173)
at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:809)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:129)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:563)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:554)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Unknown Source)
请告诉我如何解决这个问题的一些想法..提前致谢!
答案 0 :(得分:7)
我终于通过使用:
检查真正的java.library.path来解决这个问题System.out.println("java.library.path is: " + System.getProperty("java.library.path"));
这给了我这个烂摊子:
java.library.path is: /opt/jdk1.7.0_45/jre/lib/i386/server:/opt/jdk1.7.0_45/jre/lib/i386:/opt/jdk1.7.0_45/jre/../lib/i386:/usr/lib/jvm/java-6-openjdk-i386/jre/lib/i386/client:/usr/lib/jvm/java-6-openjdk-i386/jre/lib/i386::/usr/java/packages/lib/i386:/lib:/usr/lib
最后你可以看到/ usr / lib,所以我在/ usr / lib中创建了libJMagick.so的链接:
ln -s /usr/lib/jni/libJMagick.so /usr/lib/libJMagick.so
享受! : - )