4

我正在编写一些 Java 代码作为使用 Install4j 创建的安装程序的一部分。我的脚本的一部分看起来像这样 -

     String result = (String)context.runElevated(new RemoteCallable() {
            public Serializable execute() {
            try {
                File dir = new File ((String)context.getVariable("sys.installationDir"));
                File [] files = dir.listFiles();
                for (File file : files)
                {
                    if (file.isFile())
                    {
                        file.delete();
                    }
                    else if (file.isDirectory())
                    {
                        File subDir = new File(file.getAbsolutePath());
                        File [] subFiles = subDir.listFiles();
                        for (File subFile : subFiles)
                        {
                            subFile.delete();
                        }
                        subDir.delete();
                    }                        
                }
                }
                catch(Exception e)
                {
                    Util.showWarningMessage("asdasdasdasd");
                }
                return "The computed value";
            }
        }, true);

现在,如果我以管理员身份运行创建的安装程序,我不会收到任何错误,但作为普通用户,我会得到一个java.io.NotSerializableException.

作为一名 C++ 程序员,我真的不知道这意味着什么或为什么会发生。如果有人能为我阐明这一点,我将不胜感激

谢谢

这是日志文件

    Exception:

In form component "Button" (screen "Configurable form"), property "Action script":
java.io.NotSerializableException: com.install4j.runtime.installer.InstallerContextImpl
    at java.io.ObjectOutputStream.writeObject0(Unknown Source)
    at java.io.ObjectOutputStream.defaultWriteFields(Unknown Source)
    at java.io.ObjectOutputStream.writeSerialData(Unknown Source)
    at java.io.ObjectOutputStream.writeOrdinaryObject(Unknown Source)
    at java.io.ObjectOutputStream.writeObject0(Unknown Source)
    at java.io.ObjectOutputStream.defaultWriteFields(Unknown Source)
    at java.io.ObjectOutputStream.writeSerialData(Unknown Source)
    at java.io.ObjectOutputStream.writeOrdinaryObject(Unknown Source)
    at java.io.ObjectOutputStream.writeObject0(Unknown Source)
    at java.io.ObjectOutputStream.defaultWriteFields(Unknown Source)
    at java.io.ObjectOutputStream.writeSerialData(Unknown Source)
    at java.io.ObjectOutputStream.writeOrdinaryObject(Unknown Source)
    at java.io.ObjectOutputStream.writeObject0(Unknown Source)
    at java.io.ObjectOutputStream.writeObject(Unknown Source)
    at com.install4j.runtime.installer.helper.comm.HelperCommunication.sendObject(Unknown Source)
    at com.install4j.runtime.installer.helper.comm.HelperCommunication.executeOther(Unknown Source)
    at com.install4j.runtime.installer.helper.comm.HelperCommunication.executeActionInt(Unknown Source)
    at com.install4j.runtime.installer.helper.comm.HelperCommunication.executeAction(Unknown Source)
    at com.install4j.runtime.installer.ContextImpl.runElevatedInt(Unknown Source)
    at com.install4j.runtime.installer.ContextImpl.runElevated(Unknown Source)
    at I4jScript_Internal_876.eval(I4jScript_Internal_876.java:28)
    at I4jScript_Internal_876.evaluate(I4jScript_Internal_876.java:91)
    at com.install4j.runtime.installer.helper.Script.evaluate(Unknown Source)
    at com.install4j.runtime.installer.ContextImpl.runScript(Unknown Source)
    at com.install4j.runtime.installer.ContextImpl.runScript(Unknown Source)
    at com.install4j.runtime.beans.formcomponents.ButtonComponent.doButtonClicked(Unknown Source)
    at com.install4j.runtime.beans.formcomponents.ButtonComponent.access$000(Unknown Source)
    at com.install4j.runtime.beans.formcomponents.ButtonComponent$1.actionPerformed(Unknown Source)
    at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
    at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
    at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
    at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
    at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
    at java.awt.Component.processMouseEvent(Unknown Source)
    at javax.swing.JComponent.processMouseEvent(Unknown Source)
    at java.awt.Component.processEvent(Unknown Source)
    at java.awt.Container.processEvent(Unknown Source)
    at java.awt.Component.dispatchEventImpl(Unknown Source)
    at java.awt.Container.dispatchEventImpl(Unknown Source)
    at java.awt.Component.dispatchEvent(Unknown Source)
    at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
    at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
    at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
    at java.awt.Container.dispatchEventImpl(Unknown Source)
    at java.awt.Window.dispatchEventImpl(Unknown Source)
    at java.awt.Component.dispatchEvent(Unknown Source)
    at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
    at java.awt.EventQueue.access$200(Unknown Source)
    at java.awt.EventQueue$3.run(Unknown Source)
    at java.awt.EventQueue$3.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
    at java.awt.EventQueue$4.run(Unknown Source)
    at java.awt.EventQueue$4.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
    at java.awt.EventQueue.dispatchEvent(Unknown Source)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.run(Unknown Source)

System properties:

java.runtime.name=Java(TM) SE Runtime Environment
exe4j.moduleName=C:\SoftwareDevelopment\AcqDevelopment\Installer\Install4j\Media\ASLSuite_2_13.exe
exe4j.semaphoreName=Local\c:_softwaredevelopment_acqdevelopment_installer_install4j_media_aslsuite_2_13.exe
sun.boot.library.path=c:\program files (x86)\java\jre7\bin
java.vm.version=23.25-b01
java.vm.vendor=Oracle Corporation
java.vendor.url=http://java.oracle.com/
exe4j.consoleCodepage=cp0
path.separator=;
java.vm.name=Java HotSpot(TM) Client VM
file.encoding.pkg=sun.io
user.country=GB
user.script=
sun.os.patch.level=Service Pack 1
install4j.exeDir=C:\SoftwareDevelopment\AcqDevelopment\Installer\Install4j\Media\
java.vm.specification.name=Java Virtual Machine Specification
user.dir=C:\Users\GRAHAM~1.LAB\AppData\Local\Temp\e4j54F6.tmp_dir1374155435
java.runtime.version=1.7.0_25-b17
java.awt.graphicsenv=sun.awt.Win32GraphicsEnvironment
java.endorsed.dirs=c:\program files (x86)\java\jre7\lib\endorsed
os.arch=x86
java.io.tmpdir=C:\Users\GRAHAM~1.LAB\AppData\Local\Temp\
line.separator=

java.vm.specification.vendor=Oracle Corporation
user.variant=
exe4j.tempDir=C:\Users\GRAHAM~1.LAB\AppData\Local\Temp\e4j54F6.tmp_dir1374155435
os.name=Windows 7
sun.java2d.noddraw=true
sun.jnu.encoding=Cp1252
java.library.path=C:\Program Files (x86)\install4j5\bin\..\lib;C:\MinGW\bin;C:\Qt\5.0.2\qtbase\bin;C:\Qt\quazip-0.4.4\quazip\release;C:\Program Files\Common Files\Microsoft Shared\Windows Live;C:\Program Files (x86)\Common Files\Microsoft Shared\Windows Live;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\Windows Live\Shared;c:\Program Files (x86)\Microsoft SQL Server\90\Tools\binn\;c:\Program Files (x86)\Microsoft SQL Server\100\Tools\Binn\VSShell\Common7\IDE\;c:\Program Files\Microsoft SQL Server\100\Tools\Binn\;c:\Program Files (x86)\Microsoft SQL Server\100\DTS\Binn\;C:\Program Files (x86)\Java\jre7\bin;C:\strawberry\c\bin;C:\strawberry\perl\site\bin;C:\strawberry\perl\bin;C:\Python27;C:\Libs;C:\Qt\qwt-6.0.1\lib;C:\Program Files (x86)\Cppcheck\;C:\Acquisition2\ApplicationCode\ASLCommon\debug;C:\Program Files (x86)\Microsoft DirectX SDK (June 2010)\Include;C:\cmake-2.8.11.1-win32-x86\bin;C:\Program Files (x86)\GammaRay\bin;C:\SoftwareDevelopment\Shared\Libs;c:\program files (x86)\java\jre7\bin;c:\program files (x86)\java\jre7\bin
sun.awt.enableExtraMouseButtons=true
java.specification.name=Java Platform API Specification
java.class.version=51.0
sun.management.compiler=HotSpot Client Compiler
exe4j.isInstall4j=true
os.version=6.1
user.home=C:\Users\Graham.Labdon
user.timezone=Europe/London
java.awt.printerjob=sun.awt.windows.WPrinterJob
file.encoding=Cp1252
java.specification.version=1.7
java.class.path=C:\Users\GRAHAM~1.LAB\AppData\Local\Temp\e4j54F6.tmp_dir1374155435\i4jruntime.jar;C:\Users\GRAHAM~1.LAB\AppData\Local\Temp\e4j54F6.tmp_dir1374155435\user.jar;C:\Users\GRAHAM~1.LAB\AppData\Local\Temp\e4j54F6.tmp_dir1374155435\platform.zip;;C:\Program Files (x86)\Java\jre7\lib\deploy.jar;C:\Program Files (x86)\Java\jre7\lib\plugin.jar
user.name=graham.labdon
java.vm.specification.version=1.7
sun.java.command=C:\SoftwareDevelopment\AcqDevelopment\Installer\Install4j\Media\ASLSuite_2_13.exe
java.home=c:\program files (x86)\java\jre7
sun.arch.data.model=32
exe4j.launchName=C:\SOFTWA~1\ACQDEV~1\INSTAL~2\INSTAL~1\Media\ASLSUI~1.EXE
user.language=en
java.specification.vendor=Oracle Corporation
awt.toolkit=sun.awt.windows.WToolkit
java.vm.info=mixed mode, sharing
exe4j.unextractedPosition=40963549
java.version=1.7.0_25
java.ext.dirs=c:\program files (x86)\java\jre7\lib\ext;C:\Windows\Sun\Java\lib\ext
sun.boot.class.path=c:\program files (x86)\java\jre7\lib\resources.jar;c:\program files (x86)\java\jre7\lib\rt.jar;c:\program files (x86)\java\jre7\lib\sunrsasign.jar;c:\program files (x86)\java\jre7\lib\jsse.jar;c:\program files (x86)\java\jre7\lib\jce.jar;c:\program files (x86)\java\jre7\lib\charsets.jar;c:\program files (x86)\java\jre7\lib\jfr.jar;c:\program files (x86)\java\jre7\classes
install4j.appDir=C:\Users\Graham.Labdon\AppData\Local\Temp\
java.vendor=Oracle Corporation
file.separator=\
java.vendor.url.bug=http://bugreport.sun.com/bugreport/
sun.io.unicode.encoding=UnicodeLittle
sun.cpu.endian=little
install4j.systemLanguage=en
sun.desktop=windows
sun.cpu.isalist=pentium_pro+mmx pentium_pro pentium+mmx pentium i486 i386 i86
4

1 回答 1

1

您不能将上下文带到远程帮助程序进程。将此行放在顶部之外Runnable

final File dir = new File ((String)context.getVariable("sys.installationDir"));

然后它应该工作。

于 2013-07-18T20:22:48.330 回答