简体   繁体   English

使用InstallAnywhere生成批处理文件而不是可执行文件

[英]Generate a batch file instead of executable using InstallAnywhere

I am using InstallAnywhere to create executables for my jars for multiple platforms. 我正在使用InstallAnywhere为多个平台的jar创建可执行文件。 So install anywhere generates .sh for Unix and .exe for Windows. 因此,在任何地方安装都会为Unix和Windows生成.sh。

But for 1 jar, I want to create batch file instead of exe for Windows. 但是对于1个jar,我想为Windows创建批处理文件而不是exe。 I still want .sh for Unix. 我仍然需要.sh用于Unix。

I cannot find any lax property to achieve this. 我找不到任何松懈的属性来实现这一目标。 How can I do this? 我怎样才能做到这一点?

There's no way to do that in InstallAnywhere. 在InstallAnywhere中无法做到这一点。 InstallAnywhere wants to create native execution targets during the installation. InstallAnywhere希望在安装期间创建本机执行目标。 The closest you can get is to create a console-only executable. 您可以获得的最接近的结果是创建仅控制台可执行文件。

However, you can write your own batch files and ship them as part of the installation. 但是,您可以编写自己的批处理文件并将其作为安装的一部分进行运送。 If you need to include path information (or other install-time information), you can add InstallAnywhere variables like $IA_CLASSPATH$ and replace them at installation time. 如果需要包括路径信息(或其他安装时信息),则可以添加InstallAnywhere变量,例如$IA_CLASSPATH$ ,并在安装时替换它们。

Use the "Modify Text File - Single File" Action to modify your batch files (or other text files) at installation. 使用“修改文本文件-单个文件”操作在安装时修改批处理文件(或其他文本文件)。

So that we can test our batch files, we insert positional arguments that get assigned to script variables. 为了测试批处理文件,我们插入位置参数,这些参数被分配给脚本变量。 During development, we manually supply the positional arguments. 在开发过程中,我们手动提供位置参数。 At installation time, we replace the positional arguments with values from InstallAnywhere. 在安装时,我们将位置参数替换为InstallAnywhere中的值。

For instance: 例如:

@echo off
set APP_USER=%1
set APP_PASSWORD=%2
set APP_DIR=%3
set CLASSPATH=%CLASSPATH%;$IA_CLASSPATH$;./lib/myapp.jar

cd %APP_DIR%

java -cp %CLASSPATH% com.example.myapp.Main %APP_USER% %APP_PASSWORD%

We add the "Modify Text File - Single File" Action to our project. 我们将“修改文本文件-单个文件”操作添加到我们的项目中。 We use the "Search and replace strings: " option to replace the positional arguments. 我们使用“搜索并替换字符串:”选项来替换位置参数。 In this example, we'd replace %1 and %2 with values collected during the installation and replace %3 with $USER_INSTALL_DIR$ . 在此示例中,我们将%1和%2替换为安装期间收集的值,并将%3替换为$USER_INSTALL_DIR$ To replace any InstallAnywhere variables (in this case, $IA_CLASSPATH$ ), check the "Substitute InstallAnywhere variables in file" checkbox. 要替换所有InstallAnywhere变量(在本例中$IA_CLASSPATH$ ),请选中“在文件中替换InstallAnywhere变量”复选框。

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

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