Install4j常量导致构建失败

时间:2016-09-16 20:46:45

标签: java install4j

不确定是否有其他人遇到此错误,但我正在更新现有的Install4j安装项目。我注意到每当使用install4j的上下文时,直接使用字符串。 例如:

context.setVariable("somekey", "Some value");

我认为将“somekey”移动到java类中是很棒的,其中常量可以在install4j和java代码中共享。

我创建了一个类似的类:

public class InstallerContextConstants {
    public static String KEY = "STRING_KEY";
}

所以我将其添加到屏幕的预启动脚本中,如下所示:

import com.somepackage.InstallerContextConstants;
Util.showMessage(InstallerContextConstants.APPLICATION_ONLY_INSTALL);

然而这不会编译......?它给了我:

install4j: compilation failed. Reason: com.ejt.a.c.g: Failed to compile script
----------
In application "Installer", property "Help customizer script":
1. WARNING in /private/var/folders/n7/vjsf1vp56s13hzpgypthp2_h0000gp/T/script4119340027951579520.java.dir/com/install4j/script/I4jScript_Internal_1.java (at line *19)
        private void eval(final com.install4j.api.context.InstallerContext context, final java.util.List options) throws Exception {
                                                                                          ^^^^^^^^^^^^^^
List is a raw type. References to generic type List<E> should be parameterized
----------
In application "Installer", property "Help customizer script":
2. WARNING in /private/var/folders/n7/vjsf1vp56s13hzpgypthp2_h0000gp/T/script4119340027951579520.java.dir/com/install4j/script/I4jScript_Internal_1.java (at line 1)
        if (Util.isLinux()) options.add(new String[] { "--skip-precheck", "Bypasses Installer precheck checks. Note this must be the *first* argument."});
                            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Type safety: The method add(Object) belongs to the raw type List. References to generic type List<E> should be parameterized
----------
In application "Installer", property "Help customizer script":
3. WARNING in /private/var/folders/n7/vjsf1vp56s13hzpgypthp2_h0000gp/T/script4119340027951579520.java.dir/com/install4j/script/I4jScript_Internal_1.java (at line *24)
        eval((com.install4j.api.context.InstallerContext)parameters[0], (java.util.List)parameters[1]);
                                                                         ^^^^^^^^^^^^^^
List is a raw type. References to generic type List<E> should be parameterized
----------
----------
In screen "[Additional confirmations]", property "Pre-activation expression":
4. ERROR in /private/var/folders/n7/vjsf1vp56s13hzpgypthp2_h0000gp/T/script4119340027951579520.java.dir/com/install4j/script/I4jScript_Internal_35.java (at line 5)
        Util.showMessage(InstallerContextConstants.KEY);
                                          ^^^^^^^^^^^^^^^^^^^^^^^^
KEY cannot be resolved or is not a field
----------
4 problems (1 error, 3 warnings)

然而,如果我使用任何install4j字符串常量,它的工作原理。 http://resources.ej-technologies.com/install4j/help/javadoc/constant-values.html

有关如何执行此操作的任何建议吗?

1 个答案:

答案 0 :(得分:0)

原则上,你的方法应该有效,我猜想在Installer-&gt; Custom Code&amp;资源。

然而,点击安装程序 - &gt;自定义代码&amp;上的“编辑代码”要容易得多。在资源步骤中,这将为所有脚本提供静态定义的编辑器。

如果你添加

import sys
from tkinter import *
from tkinter import ttk
import time
from datetime import datetime
now= datetime.now()
x = []
d = dict()
def quit():
    print("Have a great day! Goodbye :)")
    sys.exit(0)
def display():
    x_var.set(list(d))
def add(*args): 
    global stock
    global d
    global Quantity
    stock = stock_Entry.get()
    Quantity = int(Quantity_Entry.get())
    if stock not in d:
        d[stock] = Quantity
    else:
        d[stock] += Quantity

root = Tk()
root.title("Homework 5 216020088")

x_var = StringVar()
x_var.set(x)

mainframe = ttk.Frame(root, padding="6 6 20 20")
mainframe.grid(column=0, row=0, sticky=(N, W, E, S))

ttk.Label(mainframe, text="you are accesing this on day %s of month %s of %s" % (now.day,now.month,now.year)+" at exactly %s:%s:%s" % (now.hour,now.minute,now.second), foreground="yellow", background="Black").grid(column=0, row = 0)

stock_Entry= ttk.Entry(mainframe, width = 60, textvariable="stock")
stock_Entry.grid(column=0, row = 1, sticky=W)
ttk.Label(mainframe, text="Please enter the stock name").grid(column=1, row = 1, sticky=(N, W, E, S))

Quantity_Entry= ttk.Entry(mainframe, width = 60, textvariable="Quantity")
Quantity_Entry.grid(column=0, row = 2, sticky=W)
ttk.Label(mainframe, text="Please enter the quantity").grid(column=1, row = 2, sticky=(N, W, E, S))

ttk.Button(mainframe, text="Add", command=add).grid(column=0, row=3, sticky=W)
ttk.Button(mainframe, text="Display", command=display).grid(column=0, row=3, sticky=S)
ttk.Button(mainframe, text="Exit", command=quit).grid(column=0, row=3, sticky=E)

ttk.Label(mainframe, textvariable= x_var).grid(column=0, row= 4, sticky=W)

for child in mainframe.winfo_children(): child.grid_configure(padx=5, pady=5)
root.mainloop()

那里,您可以在任何脚本中使用static String KEY = "STRING_KEY"; 而无需任何导入:

KEY