Unix 如何使用maven解压符号链接?
我有存储在zip文件中的符号链接 当使用Mac OS系统解压该文件时,符号链接将得到维护(也就是说,它们是符号链接和Apper本身) 但是,当使用maven(特别是mojo)解压它们时,它们显示为简单文件Unix 如何使用maven解压符号链接?,unix,maven,zip,symlink,Unix,Maven,Zip,Symlink,我有存储在zip文件中的符号链接 当使用Mac OS系统解压该文件时,符号链接将得到维护(也就是说,它们是符号链接和Apper本身) 但是,当使用maven(特别是mojo)解压它们时,它们显示为简单文件 那么,有没有保留该标志的maven插件呢?我建议尝试一下。符号链接并不是在所有操作系统上都实现的。事实上,在查看了之后,我认为SDK根本不支持这种zip条目——据我所知,它只是文件和目录。由于这个原因,我也不会说这是依赖插件的限制。根据其他答案,似乎很少有纯Java库允许解压缩符号链接 在这样
那么,有没有保留该标志的maven插件呢?我建议尝试一下。符号链接并不是在所有操作系统上都实现的。事实上,在查看了之后,我认为SDK根本不支持这种zip条目——据我所知,它只是文件和目录。由于这个原因,我也不会说这是依赖插件的限制。根据其他答案,似乎很少有纯Java库允许解压缩符号链接 在这样的解决方案中,要实现纯多平台构建,不能简单地为每个操作系统创建一个模块,因为这将导致经典的模块军备竞赛,更实际的是,它不适合这个模块生命周期 因此,我在maven解决方案中使用了我的经典脚本: 这导致了这个不太漂亮的剧本
<plugin>
<groupId>org.codehaus.gmaven</groupId>
<artifactId>gmaven-plugin</artifactId>
<executions>
<execution>
<id>unzip native code using Groovy</id>
<phase>prepare-package</phase>
<goals>
<goal>execute</goal>
</goals>
<configuration>
<providerSelection>${gmaven.provider.version}</providerSelection>
<source>
<![CDATA[
def ant = new AntBuilder()
def FOLDERS_TO_EXPLORE = [] /* put here the list of folders in which zip files will be recursively searched */
def unzip(File file) {
def RUN_ON_WINDOWS = System.getProperty("os.name").toLowerCase().indexOf("win")>=0
if(RUN_ON_WINDOWS) {
log.debug "unzipping windows style"
ant.unzip( src: file, dest:file.parentFile, overwrite:"true")
} else {
def result = ant.exec(outputproperty:"text",
errorproperty: "error",
resultproperty: "exitValue",
dir: file.parent,
failonerror: true,
executable: "unzip") {
arg(value:file.name)
}
if(Integer.parseInt(ant.project.properties.exitValue)!=0) {
log.error "unable to unzip "+file.name+" exit value is "+ant.project.properties.exitValue
log.error "=========================================================\noutput\n=========================================================\n"+ant.project.properties.text
log.error "=========================================================\nerror\n=========================================================\n"+ant.project.properties.error
fail("unable to unzip "+file)
} else {
log.info "unzipped "+file.name
}
}
file.delete()
}
def unzipContentOf(File file) {
file.eachFileRecurse {
if(it.name.toLowerCase().endsWith("zip")) {
unzip(it)
}
}
}
FOLDERS_TO_EXPLORE.each { unzipContentOf(new File(it)) }
]]>
org.codehaus.gmaven
gmaven插件
使用Groovy解压本机代码
准备包装
执行
${gmaven.provider.version}
=0
如果(在WINDOWS上运行){
log.debug“解压缩windows样式”
unzip(src:file,dest:file.parentFile,overwrite:“true”)
}否则{
def result=ant.exec(outputproperty:“text”,
errorproperty:“错误”,
resultproperty:“exitValue”,
dir:file.parent,
失败者:是的,
可执行文件:“解压”){
arg(值:file.name)
}
if(Integer.parseInt(ant.project.properties.exitValue)!=0){
log.error“无法解压缩”+文件名+“退出值为”+ant.project.properties.exitValue
log.error“===========================================================================================\n输出\n=======================================================================================================\n”+ant.project.properties.text
log.error“=======================================================================================\n=========\n错误\n======================================================================================================\n”+ant.project.properties.error
失败(“无法解压缩”+文件)
}否则{
log.info“unzip”+file.name
}
}
file.delete()
}
def unzipContentOf(文件){
file.eachFileRecurse{
if(it.name.toLowerCase().endsWith(“zip”)){
解压缩(it)
}
}
}
文件夹_TO_EXPLORE.each{unzipContentOf(新文件(it))}
]]>
出于好奇,您是如何创建zip的?Maven之外还是什么?@carlspring yeah zip是在Maven之外创建的,因为Maven也没有正确地压缩那些符号链接文件(将尝试向Maven报告错误)。好吧,问题是——Apache的员工如果使用Sun的内置API,将无法做很多事情。如果您使用的是GNUZIP,那么在zip文件中有处理符号链接的选项。