我对JMagick库有奇怪的问题。我使用 Debian,所以我安装了 libjmagick6-java 和 libjmagick6-jni,以下是我完成的步骤:
- 我已经将
jmagick-6.6.9.jar
从/usr/share/java/
复制到$JAVA_HOME/jre/lib/ext/
. - 我已将
/usr/lib/jni
(libJMagick.so
)设置为本机库位置:- JRE 系统库(在日食中)
- JMick-6.6.9.jar(在Eclipse中)
我也在简单的Java项目中测试了JMagick,它可以工作,但是在Tomcat 6中运行的Web应用程序的第二个项目中,它不起作用。
这是我的代码,它有效 - 所以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();
}
}
这是网络应用程序中不起作用的代码:
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)
请告诉我一些如何解决这个问题的想法。提前感谢!
我终于通过检查真实的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
享受! :-)