2017-08-16 71 views
2

我使用註釋處理來生成一些類......我有兩個模塊,處理器本身和使用它的「客戶端」模塊。我想通過客戶端向處理器傳遞參數,我可以這樣做將參數傳遞給註釋處理器

<build> 
     <plugins> 
      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-compiler-plugin</artifactId> 
       <version>3.5.1</version> 
       <configuration> 
        <source>1.8</source> 
        <target>1.8</target> 
        <encoding>UTF-8</encoding> 
        <generatedSourcesDirectory>${project.build.directory}/generated-sources/</generatedSourcesDirectory> 
        <annotationProcessors> 
         <annotationProcessor>org.rapster.xxx.xxx.xxComponentProcessor</annotationProcessor> 
        </annotationProcessors> 
        <compilerArgs> 
         <arg>-Awidget=something</arg> 
        </compilerArgs> 
       </configuration> 
      </plugin> 
     </plugins> 
    </build> 

以及如何在處理器端檢索此參數?

回答

0

你可以得到這樣的說法如下 -

processingEnvironment.getOptions().get("widget") 

請注意,只有以「-A」的論點將可通過這一手段。