繁体   English   中英

通过Adobe AIR的本机进程运行带有.dll的Java程序

[英]Running a Java program with a .dll from Adobe AIR's native process

我希望能够从AIR应用程序中操作扫描仪。 由于本机不支持此功能,因此我尝试使用NativeProcess类来启动可以运行扫描程序的jar文件。 Java代码正在使用JTwain库来操作扫描仪。 Java应用程序本身运行良好,并且AIR应用程序可以启动并与Java应用程序通信。 问题似乎是,每当我尝试使用JTwain的功能(依赖于JTwain.dll)时,如果AIR STARTIT IT,该应用程序就会死亡。

我不确定从本地进程引用dll文件是否存在限制。 我在下面包含了我的代码

Java代码

    while(true)
    {
        try {
            System.out.println("Start");
            text = in.readLine();
            Source source = SourceManager.instance().getCurrentSource();
            System.out.println("Java says: "+ text);
        }
        catch (IOException e)
        {
            System.err.println("Exception while reading the input. " + e);
        }
        catch (Exception e) {
            System.out.println("Other exception occured: " + e.toString());
        }
        finally {
        }
    }   
}

空气应用

        import mx.events.FlexEvent;

        private var nativeProcess:NativeProcess;
        private var npInfo:NativeProcessStartupInfo;
        private var processBuffer:ByteArray;
        private var bLength:int = 0;

        protected function windowedapplication1_applicationCompleteHandler(event:FlexEvent):void
        {
            var arg:Vector.<String> = new Vector.<String>;
            arg.push("-jar");
            arg.push(File.applicationDirectory.resolvePath("Hello2.jar").nativePath);

            processBuffer = new ByteArray;

            npInfo = new NativeProcessStartupInfo;
            npInfo.executable = new File("C:/Program Files/Java/jre6/bin/javaw.exe");
            npInfo.arguments = arg;

            nativeProcess = new NativeProcess;
            nativeProcess.addEventListener(ProgressEvent.STANDARD_OUTPUT_DATA, onStandardOutputData);
            nativeProcess.start(npInfo);
        }

        private function onStandardOutputData(e:ProgressEvent):void
        {
            tArea.text += nativeProcess.standardOutput.readUTFBytes(nativeProcess.standardOutput.bytesAvailable);
        }


        protected function button1_clickHandler(event:MouseEvent):void
        {
            tArea.text += 'AIR app: '+tInput.text + '\n';
            nativeProcess.standardInput.writeMultiByte(tInput.text + "\n", 'utf-8');
            tInput.text = '';
        }


        protected function windowedapplication1_closeHandler(event:Event):void
        {
            nativeProcess.closeInput();
        }

    ]]>
</fx:Script>
<s:Button label="Send" x="221" y="11" click="button1_clickHandler(event)"/>
<s:TextInput id="tInput" x="10" y="10" width="203"/>
<s:TextArea id="tArea" x="10" width="282" height="88" top="40"/>

我很想解释一下为什么这种情况即将消失。 我已经进行了足够的测试,我绝对知道杀死它的行是SourceManager.instance()。getCurrentSource()。 我希望有任何建议。 谢谢。

调用Java时,将此-Djava.library.path = location_of_dll添加到命令行

我对Air的使用经验为0,但这使我想起了我曾经花了一些时间弄清楚的Java问题。 对于扫描为何不起作用,我没有任何建议,但是我认为堆栈跟踪现在是您最好的朋友。

我猜您是依靠此行来捕获和显示它吗?

nativeProcess.standardOutput.readUTFBytes(nativeProcess.standardOutput.bytesAvailable);

但是,您正在将IOExceptions写入System.err是否可以在Air中读取nativeProcess.standardError 或者,将所有内容输出到System.out

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM