我曾经使用过Apache Commons Cli 1.2.我希望解析器忽略参数,如果它们是未知的(不添加到Options-Object).
示例(伪代码):
Options specialOptions;
specialOptions.addOption(null, "help", false, "shows help");
specialOptions.addOption(null, "version", false, "show version");
CommandLineParser parser = new DefaultParser();
CommandLine cmd = parser.parse(options, args); //no third argument, since i dont want the program to stop parsing.
// run program with args: --help --unknown --version
// program shall parse --help AND --version, but ignore --unknown
Run Code Online (Sandbox Code Playgroud)
我使用了PascalSchäfer的解决方案: Apache Commons CLI选项解析器可以忽略未知的命令行选项吗?
这对我来说在1.2上工作正常,它在1.3.1上也可以正常工作.但它被弃用了.我使用的解析器被替换为DefaultParser.我查看了功能,但没有这样的方法processOptions.
我真的想使用在以后的版本中不会被删除的代码.有谁知道如何解决这个问题?
如果有两个文件具有不同的内容但在两个不同的maven模块中具有相同的名称,那么它们都与maven assembly-plugin放在一个jar文件中,只有一个文件最终成为.jar文件的一部分.
问题:有没有办法确保在构建jar文件时将文件的内容组合到一个文件中?
我显然不想手动将信息放在一起,因为这是我试图通过在不同模块中拆分项目来避免的.
编辑:我有一个自定义的Assembly-Descriptor,我想保留,即使我开始使用另一个插件.这个描述符基本上排除了所有语言,但英语排除了资源和错误文本.
<id>jar-with-dependencies</id>
<formats>
<format>jar</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<dependencySets>
<dependencySet>
<outputDirectory>/</outputDirectory>
<useProjectArtifact>true</useProjectArtifact>
<unpack>true</unpack>
<scope>runtime</scope>
<unpackOptions>
<excludes>
<exclude>**/*Resources_*</exclude>
<exclude>**/*ErrorsText_*</exclude>
</excludes>
</unpackOptions>
</dependencySet>
</dependencySets>
Run Code Online (Sandbox Code Playgroud) 我有很多方法如下所示:
switch(myEnum) {
case a :
case b :
case c :
case d :
modifier = 1.1;
break;
default :
break;
}
Run Code Online (Sandbox Code Playgroud)
如果我有机会制作每个案例和修饰符变量,那将是完美的,所以我可以有一个方法有6个参数,4个用于案例,2个用于修饰符.类似下面的内容(伪):
public void setModifier(case1, case2, case3, case4, modifier, value) {
switch(myEnum) {
case case1 :
case case2 :
case case3 :
case case4 :
modifier = value;
break;
default :
break;
}
}
Run Code Online (Sandbox Code Playgroud)
修饰符和值不应该是一个问题,但我如何解决变量开关案例?这在带有switch语句的java中是否可能?
我有以下 xml 文件:
<Book description="for beginners" name="IT Book">
<Available>yes</Available>
<Info pages="500.</Info>
</Book>
Run Code Online (Sandbox Code Playgroud)
我希望它看起来像这样:
<Book description="for pros" name="IT Book">
<Available>yes</Available>
<Info pages="500.</Info>
</Book>
Run Code Online (Sandbox Code Playgroud)
我在互联网上查找了如何正确修改 xml 文档。我发现首先我应该声明一个模板来复制所有内容:
<xsl:template match="node() | @*">
<xsl:copy>
<xsl:apply-templates select="node() | @*"/>
</xsl:copy>
</xsl:template>
Run Code Online (Sandbox Code Playgroud)
但是,我不知道如何编写实际修改的模板。感谢您帮助初学者。
编辑:到目前为止,这是我的样式表(根据 uL1 的要求):
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:sig="http://www.w3.org/2000/09/xmldsig#">
<xsl:output indent="yes" method="xml" omit-xml-declaration="yes"/>
<xsl:template match="node() | @*">
<xsl:copy>
<xsl:apply-templates select="node() | @*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="@description='for beginners'">
<xsl:attribute name="{name()}">
<xsl:text>for pros</xsl:text>
</xsl:attribute>
</xsl:template>
</xsl:stylesheet>
Run Code Online (Sandbox Code Playgroud)