我正在对JTwain库进行一些测试。我需要将扫描功能附加到Django应用程序。我有一些将在本地运行的代码,但我无法在applet中运行。
我回来了,试图让demo applet运行。我已经创建了一个eclipse'可运行的jar'(我必须在其中一个类中添加一个虚拟Main)。当我在浏览器中加载页面时,我从插件控制台获得以下输出 -
java.security.AccessControlException: access denied (java.lang.RuntimePermission loadLibrary.AspriseJTwain)
at java.security.AccessControlContext.checkPermission(Unknown Source)
at java.security.AccessController.checkPermission(Unknown Source)
at java.lang.SecurityManager.checkPermission(Unknown Source)
at java.lang.SecurityManager.checkLink(Unknown Source)
at java.lang.Runtime.loadLibrary0(Unknown Source)
at java.lang.System.loadLibrary(Unknown Source)
at com.asprise.util.jtwain.SourceManager.init(SourceManager.java:222)
at com.asprise.util.jtwain.SourceManager.<init>(SourceManager.java:36)
at com.asprise.util.jtwain.SourceManager.instance(SourceManager.java:28)
at JTwainApplet.scan(JTwainApplet.java:39)
at JTwainApplet.init(JTwainApplet.java:69)
at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
java.lang.UnsatisfiedLinkError: com.asprise.util.jtwain.lowlevel.Control.performAction(ILjava/lang/Object;)Z
at com.asprise.util.jtwain.lowlevel.Control.performAction(Native Method)
at com.asprise.util.jtwain.lowlevel.Control.unloadSourceManager(Control.java:93)
at com.asprise.util.jtwain.SourceManager.closeSourceManager(SourceManager.java:120)
at JTwainApplet.scan(JTwainApplet.java:57)
at JTwainApplet.init(JTwainApplet.java:69)
at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Scan
以下是我创建的Jar的结构。
C:\PythonProjects\CacheProject\media\java>jar tf demo.jar
META-INF/MANIFEST.MF
JTwainApplet.class
ImageDisplayer$1.class
ImageDisplayer.class
META-INF/
META-INF/ASPRISE.DSA
com/
com/asprise/
com/asprise/util/
com/asprise/util/jtwain/
com/asprise/util/jtwain/ImageGenerator.class
com/asprise/util/jtwain/InvalidStateException.class
com/asprise/util/jtwain/JTwainConstants.class
com/asprise/util/jtwain/JTwainException.class
com/asprise/util/jtwain/OperationException.class
com/asprise/util/jtwain/Source.class
com/asprise/util/jtwain/SourceManager.class
com/asprise/util/jtwain/lowlevel/
com/asprise/util/jtwain/lowlevel/Capability.class
com/asprise/util/jtwain/lowlevel/Control.class
com/asprise/util/jtwain/lowlevel/DataType.class
com/asprise/util/jtwain/lowlevel/DataTypeIdentity.class
com/asprise/util/jtwain/lowlevel/DataTypeImageInfo.class
com/asprise/util/jtwain/lowlevel/DataTypeImageLayout.class
com/asprise/util/jtwain/lowlevel/DataTypeVersion.class
com/asprise/util/jtwain/lowlevel/ItemType.class
com/asprise/util/jtwain/lowlevel/ItemTypeFix32.class
com/asprise/util/jtwain/lowlevel/ItemTypeFrame.class
com/asprise/util/jtwain/lowlevel/ItemTypeInteger.class
com/asprise/util/jtwain/lowlevel/ItemTypeString.class
com/asprise/util/jtwain/lowlevel/OperationResult.class
com/asprise/util/jtwain/lowlevel/ValueContainer.class
com/asprise/util/jtwain/lowlevel/ValueContainerArray.class
com/asprise/util/jtwain/lowlevel/ValueContainerEnumeration.class
com/asprise/util/jtwain/lowlevel/ValueContainerOneValue.class
com/asprise/util/jtwain/lowlevel/ValueContainerRange.class
com/asprise/util/jtwain/web/
com/asprise/util/jtwain/web/FileUploader.class
com/asprise/util/jtwain/web/ImageDisplayPanel.class
com/asprise/util/jtwain/web/UploadApplet.class
com/asprise/util/jtwain/web/UploadApplet_buttonCheckJTwain_actionAdapter.class
com/asprise/util/jtwain/web/UploadApplet_buttonInstallJVM_actionAdapter.class
com/asprise/util/jtwain/web/UploadApplet_buttonScan_actionAdapter.class
com/asprise/util/jtwain/web/UploadApplet_buttonUpload_actionAdapter.class
com/asprise/util/jtwain/web/UploadApplet_labelURL_mouseAdapter.class
com/asprise/util/jtwain/web/UploadApplet_useProxy_actionAdapter.class
这是JTwainApplet的代码
import java.applet.Applet;
import java.awt.HeadlessException;
import java.awt.Image;
import com.asprise.util.jtwain.Source;
import com.asprise.util.jtwain.SourceManager;
/*
* $Id$
*
*/
/**
* @author JACK (Jan 19, 2004)
*/
public class JTwainApplet extends Applet {
/**
* @throws java.awt.HeadlessException
*/
public JTwainApplet() throws HeadlessException {
super();
// TODO Auto-generated constructor stub
}
public static void main(String[] args) {
}
/* (non-Javadoc)
* @see java.applet.Applet#destroy()
*/
public void destroy() {
// TODO Auto-generated method stub
super.destroy();
}
public void scan() {
try {
// SourceManager.setLibraryPath("E:\\Twain\\Asprise\\JT\\Debug\\JT.dll");
Source source = SourceManager.instance().getDefaultSource();
if(source == null) {
System.err.println("There is no (default) source on the system!");
return;
}
source.open();
Image image = source.acquireImage();
new ImageDisplayer("DemoSimple", image);
source.close();
}catch(Exception e) {
e.printStackTrace();
}finally{
SourceManager.closeSourceManager();
}
}
/* (non-Javadoc)
* @see java.applet.Applet#init()
*/
public void init() {
super.init();
System.out.println("Init.");
scan();
System.out.println("Scan");
}
/* (non-Javadoc)
* @see java.applet.Applet#start()
*/
public void start() {
// TODO Auto-generated method stub
super.start();
}
/* (non-Javadoc)
* @see java.applet.Applet#stop()
*/
public void stop() {
// TODO Auto-generated method stub
super.stop();
}
}
最后我的jnpl和html源
<?xml version="1.0" encoding="UTF-8"?>
<jnlp spec="1.0+" codebase="" href="">
<information>
<title>Cache Scanning</title>
<vendor>Altcom</vendor>
</information>
<resources>
<!-- Application Resources -->
<j2se version="1.6+"
href="http://java.sun.com/products/autodl/j2se" />
<jar href="http://127.0.0.1:18123/media/java/demo.jar" main="true" />
</resources>
<applet-desc
name="JTwain Applet Demo"
main-class="JTwainApplet"
width="500"
height="200">
</applet-desc>
<update check="background"/>
</jnlp>
**javascript** -
<script src="http://java.com/js/deployJava.js"></script>
<script>
var attributes = { code: "http://127.0.0.1:18123/media/java/demo.jar", width:500, height:200} ;
var parameters = {jnlp_href: "http://127.0.0.1:18123/media/java/demo.jnlp"} ;
deployJava.runApplet(attributes, parameters, '1.6');
</script>
任何建议都会得到很好的回复。这让我疯了。
答案 0 :(得分:1)
好的,这就是我的工作方式。我在eclipse中停止使用'create runnable jar'选项,只使用了'create jar'选项。然后我引用了其他罐子(JTwain等),使用清单(而不是让eclipse尝试将它们包含在我的罐子里)。
MANIFEST.MF
Manifest-Version: 1.0
Class-Path: JTwain.jar plugin.jar AspriseJavaPDF.jar
我将其他罐子添加到我的媒体文件夹中并使用jnpl -
提供它们<resources>
<!-- Application Resources -->
<j2se version="1.6+"
href="http://java.sun.com/products/autodl/j2se" />
<jar href="http://127.0.0.1:18123/media/java/CacheScan.jar" main="true" />
<jar href="http://127.0.0.1:18123/media/java/JTwain.jar" />
<jar href="http://127.0.0.1:18123/media/java/AspriseJavaPDF.jar" />
<jar href="http://127.0.0.1:18123/media/java/plugin.jar" />
</resources>
最后,我签署了所有未签名的罐子(我的和AspriseJavaPDF.jar)。我是在Eclipse之外做的。见http://download.oracle.com/javase/tutorial/deployment/jar/signindex.html
因为Perception&amp; Paulo Ebermann对上述评论。希望这对某人有用。