无法使用 maven 传递 java 编译器参数 [英] Unable to pass java compiler parameters using maven

查看:78
本文介绍了无法使用 maven 传递 java 编译器参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

正如标题所说,我无法使用 maven 将命令行参数传递给 java 编译器,我使用的是 maven-compiler-plugin 来做,并相应地 this(专门用于插件的 compilerArgs 选项)我正在使用最新方式" 来指定传递给编译器的参数.说得够多了,更多的代码,这是我对插件的 maven 配置,我不确定我做错了什么:

As the title says I am unable to pass command line parameters to the java compiler using maven, I am using the maven-compiler-plugin to do it, and accordingly to this (specifically for the compilerArgs option of the pluging) I am using the "latest way" to speficy the arguments passed to the compiler. Well enough talk, more code, this is my maven configuration for the plug-in and I am not sure what am I doing wrong:

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.3</version>
            <configuration>
                <source>1.8</source>
                <target>1.8</target>
                <fork>true</fork>
                <compilerArgs>
                    <arg>-parameters</arg>
                </compilerArgs>
            </configuration>
        </plugin>
    </plugins>
</build>

我正在按照该工具的使用说明进行操作,其中说<fork> 必须设置为true,但我不知道我错过了什么...一点点请帮忙?

I am following the instructions for the usage of the tool which says that <fork> have to be set to true, and I do not know what am I missing... a little bit of help please?

提到这一点可能有帮助也可能没有帮助:我需要指定的 parameters 参数 这里 因为我想在运行时使用反射获取方法中参数的名称;我在调用 maven 来查看调试时使用 -X 参数,我向我展示了它所做的fork"调用,但我无法在任何地方看到我传递的参数(也许我需要启用插件;但我认为在这个案例是自动启用的,因为它不是任何配置文件的一部分,我不是 Maven 专家,所以如果我错了,请纠正我).

May or may not be helpful to mention that: I need the parameters argument as specified here because I want to get the name of the arguments in my methods in runtime using reflection; I use the -X argument when calling maven to see the debug and I shows me the "fork" call that it does and I cannot se ANYWHERE the arguments I am passing (maybe I need to enable the plug-in; but I think In this case is automatically enabled since it is not part of any profile, I am not a maven expert so please correct me if I am wrong).

我尝试了多种方式,有没有破折号我什至尝试过旧方法"来做到这一点:

I have tried in several ways with and without the dash I have even tried the "old way" to do it:

<compilerArguments>
  <parameters />
</compilerArguments>

还有:

<compilerArgument>-parameters</compilerArgument>

推荐答案

PFFF 伙计们忘记了,很抱歉打扰您 :(

PFFF Guys forget it, and sorry for bothering you :(

我的错误:我首先创建了代码来修改我的 pom 文件,然后运行它使用 MAVEN 来检查它是否确实有效,然后 我修改了我的 pom 以包含 -parameters 标志,以便在我的方法中打印我的参数的名称,以查看它是否确实有效.代码已经编译一次没有设置标志并且代码在此之后从未修改因此maven said" '好吧,没有更改此文件,我不需要重新编译它,我只使用之前已经编译的那个'(这通常是一件好事,它减少了编译时间)但在这种情况下不是因为 -parameters 标志编译代码的方式是胖类"(或者至少更重,因为它包含参数的名称)但 maven 不知道这一点.T.T

My mistake: I created the code first previous to modify my pom file, and run it USING MAVEN to check that is was actually working, after that I modified my pom to include the -parameters flag to print the name of my my parameters in my method to see that it was actually working. The code had already been compiled once WITHOUT the flag being set and THE CODE WAS NEVER MODIFIED AFTER therefor maven "said" 'well there are no changes on this file, I do not need to re-compile it, I'll just use the one already compiled before' (which usually is a good thing, it reduces compilation time) but not in this case because the -parameters flag compiles the code in a way that is a "fat class" (or at least heavier since it includes the name of the parameters) but maven did not know about that. T.T

解决方案 执行 mvn clean 或删除已编译的类或删除/target 文件夹(总而言之做任何必要的事情以确保再次编译文件)

SOLUTION execute a mvn clean or delete the compiled classes or deleate the /target folder (in summary DO WHAT EVER IS NECESSARY TO ENSURE THAT THE FILES ARE COMPILED AGAIN)

这篇关于无法使用 maven 传递 java 编译器参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆