我需要用我生成的 .jar
和我的项目所需的其他一些文件创建一个 zip 文件。谷歌搜索让我找到了 Apache Maven Invoker plugin (我使用 maven)。
但它似乎并没有像我希望的那样使用 windows 批处理(是的,这太容易创建和调试了)。相反,它通过要求 BeanShell 脚本来强制执行一些跨平台能力。这是一种看起来像 java 并且像 java 一样工作的脚本语言,这让我想知道它与 java 有何不同。
我的问题是,使用 Netbeans,我应该如何制作一个 bean shell 脚本 以及我应该把它放在哪个文件夹中。 “我应该如何制作”是指我应该如何制作任何执行并指示它执行的东西。
最佳答案
脚本的位置是通过 postBuildHookScript parameter 指定的
Relative path of a cleanup/verification hook script to run after executing the build. This script may be written with either BeanShell or Groovy (since 1.3).
我不知道如何在 BeanShell 中创建 zip 文件,但您也可以使用 Groovy 和 creating a zip file in Groovy is easy :
import java.util.zip.ZipOutputStream
import java.util.zip.ZipEntry
import java.nio.channels.FileChannel
String zipFileName = "file.zip"
String inputDir = "logs"
ZipOutputStream zipFile = new ZipOutputStream(new FileOutputStream(zipFileName))
new File(inputDir).eachFile() { file -> zipFile.putNextEntry(new ZipEntry(file.getName()))
def buffer = new byte[1024]
file.withInputStream { i ->
def l = i.read(buffer)
// check wether the file is empty
if (l > 0) {
zipFile.write(buffer, 0, l)
}
}
zipFile.closeEntry()
}
zipFile.close()
关于java - 如何为 Apache Maven Infoker 插件创建和放置 BeanShell 脚本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29113530/