4.1、Maven配置更改

首先,我们需要在我们的项目中添加以下2个依赖项。 显然我们需要使用vertx-service-proxy API:

<dependency>
  <groupId>io.vertx</groupId>
  <artifactId>vertx-service-proxy</artifactId>
</dependency>

我们仅在编译期间需要Vert.x代码生成模块依赖(因此 是provided范围):

<dependency>
  <groupId>io.vertx</groupId>
  <artifactId>vertx-codegen</artifactId>
  <scope>provided</scope>
</dependency>

接下来,我们必须调整maven-compiler-plugin配置以使用代码生成功能, 这个功能是通过javac注释处理器完成的:

<plugin>
  <artifactId>maven-compiler-plugin</artifactId>
  <version>3.5.1</version>
  <configuration>
    <source>1.8</source>
    <target>1.8</target>
    <useIncrementalCompilation>false</useIncrementalCompilation>

    <annotationProcessors>
      <annotationProcessor>io.vertx.codegen.CodeGenProcessor</annotationProcessor>
    </annotationProcessors>
    <generatedSourcesDirectory>${project.basedir}/src/main/generated</generatedSourcesDirectory>
    <compilerArgs>
      <arg>-AoutputDirectory=${project.basedir}/src/main</arg>
    </compilerArgs>

  </configuration>
</plugin>

请注意,生成的代码放在src/main/generated中,一些集成的开发环境(如IntelliJ IDEA)将自动在类路径上拾取。

更新maven-clean-plugin以删除生成的文件也是一个好主意:

<plugin>
  <artifactId>maven-clean-plugin</artifactId>
  <version>3.0.0</version>
  <configuration>
    <filesets>
      <fileset>
        <directory>${project.basedir}/src/main/generated</directory>
      </fileset>
    </filesets>
  </configuration>
</plugin>

关于Vert.x服务的完整文档,可查阅:http://vertx.io/docs/vertx-service-proxy/java/

results matching ""

    No results matching ""