Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/346.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在不破坏Maven发布插件的情况下,传递javac多个命令行参数(其中一些包括冒号)?_Java_Maven_Javac_Maven Release Plugin_Maven Compiler Plugin - Fatal编程技术网

如何在不破坏Maven发布插件的情况下,传递javac多个命令行参数(其中一些包括冒号)?

如何在不破坏Maven发布插件的情况下,传递javac多个命令行参数(其中一些包括冒号)?,java,maven,javac,maven-release-plugin,maven-compiler-plugin,Java,Maven,Javac,Maven Release Plugin,Maven Compiler Plugin,当我忘记在Serializable类中声明serialVersionUID时,我想让我的Maven构建失败。使用javac,这很简单: $ javac -Xlint:serial -Werror Source.java 直接将其转换为Maven是行不通的: <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>

当我忘记在
Serializable
类中声明serialVersionUID时,我想让我的Maven构建失败。使用
javac
,这很简单:

$ javac -Xlint:serial -Werror Source.java
直接将其转换为Maven是行不通的:

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>2.5.1</version>
            <configuration>
                <compilerArgument>-Xlint:serial -Werror</compilerArgument>
            </configuration>
        </plugin>
这看起来很奇怪-冒号在
Xlint
名称空间中生成
serial
元素,该元素没有在任何地方声明-但它可以工作。。。在您想要发布之前:

$mvn发布:准备

org.apache.maven.lifecycle.LifecycleExecutionException:未能执行目标org.apache.maven.plugins:maven发布插件:2.3.2:project上的prepare(默认cli)我的项目:读取POM时出错:第58行出错:元素“Xlint:serial”的前缀“Xlint”未绑定。

显然,常规POM阅读器处理XML名称空间的方式不同于发布插件所使用的方式


那么,当一些命令行开关包含对普通XML元素无效的字符时,如何传递
javac
多个命令行开关,而不破坏发布插件?

似乎在
compilerArgument
中转义空格,而对引号则不一样。因此,如果用引号括住参数中的空格,则会得到两个参数:

<compilerArgument>-Xlint:serial" "-Werror</compilerArgument>
-Xlint:serial'-Werror
这将调用
javac“-Xlint:serial”“-Werror”
,而不是
javac“-Xlint:serial-Werror”


我在文档中找不到与此相关的内容。

我认为这是maven编译器插件中的一个错误,我向开发人员提交了一个问题:

请参阅

Maven 3.1或更高版本

                        <source>1.6</source>
                        <target>1.6</target>
                        <showDeprecation>true</showDeprecation>
                        <showWarnings>true</showWarnings>
                        </processors>
                        <compilerArgs>
                          <arg>-verbose</arg>
                          <arg>-Aeclipselink.persistencexml=src/main/resources/META-INF/persistence.xml</arg>
                        </compilerArgs>
1.6
1.6
真的
真的
-冗长的
-Aeclipselink.persistencexml=src/main/resources/META-INF/persistence.xml
或Maven 3.0或更高版本

      <compilerArguments>
        <verbose />
      </compilerArguments>
      <compilerArgument>-Aeclipselink.persistencexml=src/main/resources/META-INF/persistence.xml</compilerArgument>

-Aeclipselink.persistencexml=src/main/resources/META-INF/persistence.xml
关于:

注:对于Maven 3.1或更高版本,根据以下示例:


那很有趣。这是一个bug还是行为上的预期改变?我尝试了-classpath:classes”“-d:classes这也是关于maven编译器插件的。它是
,而不是
。它们的工作方式非常不同。编译器RGS直到3.1a版才可用。它在2年前推出。b)我有一个“或”部分。天哪,谢谢你发布这个答案。我花了3个小时用bootclasspath追查这个错误。真是一团糟
      <compilerArguments>
        <verbose />
      </compilerArguments>
      <compilerArgument>-Aeclipselink.persistencexml=src/main/resources/META-INF/persistence.xml</compilerArgument>
<compilerArgs>
    <arg>-verbose</arg>
    <arg>-Xlint:all,-options,-path</arg>
</compilerArgs>
<compilerArgs>
    <arg>-verbose</arg>
    <arg>-Xlint:all,-options,-path</arg>
    <arg>-bootclasspath</arg><arg>/path/to/custom/rt.jar</arg>
</compilerArgs>