2016-07-31 133 views
1

我是JOOQ和Maven的新手。按照JOOQ的文档说,我想通过提供架构来生成Pojo。我尝试了命令行方式,并且完美地工作。我在Eclipse java项目中添加了相同的配置。下面是我的pom.mxlJOOQ:在Eclipse中使用maven生成源代码不会生成任何文件

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 
    <modelVersion>4.0.0</modelVersion> 
    <groupId>PojoGenerator</groupId> 
    <artifactId>PojoGenerator</artifactId> 
    <version>0.0.1-SNAPSHOT</version> 
    <name>rutherford.pojo</name> 
    <build> 
     <sourceDirectory>src</sourceDirectory> 
     <pluginManagement> 

      <plugins> 
       <plugin> 
        <!-- <artifactId>maven-compiler-plugin</artifactId> 
        <version>3.5.1</version> 
        <configuration> 
         <source>1.8</source> 
         <target>1.8</target> 
        </configuration> 
       </plugin> 

       <plugin> --> 

        <!-- Specify the maven code generator plugin --> 
        <!-- Use org.jooq for the Open Source edition org.jooq.pro for commercial 
         editions, org.jooq.pro-java-6 for commercial editions with Java 6 support, 
         org.jooq.trial for the free trial edition --> 
        <groupId>org.jooq</groupId> 
        <artifactId>jooq-codegen-maven</artifactId> 
        <version>3.8.4</version> 

        <!-- The plugin should hook into the generate goal --> 
        <executions> 
         <execution> 
          <goals> 
           <goal>generate</goal> 
          </goals> 
         </execution> 
        </executions> 

        <!-- Manage the plugin's dependency. In this example, we'll use a PostgreSQL 
         database --> 
        <dependencies> 
         <dependency> 
          <groupId>org.postgresql</groupId> 
          <artifactId>postgresql</artifactId> 
          <version>9.4-1201-jdbc41</version> 
         </dependency> 
        </dependencies> 

        <!-- Specify the plugin configuration. The configuration format is the 
         same as for the standalone code generator --> 
        <configuration> 

         <!-- JDBC connection parameters --> 
         <jdbc> 
          <driver>org.postgresql.Driver</driver> 
          <url>jdbc:postgresql://localhost:5432/test</url> 
          <user>postgres</user> 
          <password>test</password> 
         </jdbc> 

         <!-- Generator parameters --> 
         <generator> 
          <database> 
           <name>org.jooq.util.postgres.PostgresDatabase</name> 
           <includes>.*</includes> 
           <excludes></excludes> 
           <inputSchema>public</inputSchema> 
          </database> 
          <target> 
           <packageName>com.generated.pojo</packageName> 
           <directory>${project.build.directory}/src</directory> 

          </target> 
         </generator> 
        </configuration> 
       </plugin> 
      </plugins> 
     </pluginManagement> 
    </build> 

</project> 

我试过生成资源。它说BUILD BUILD SUCCESS,但我无法在任何地方看到我生成的Pojos。请让我知道我错过了什么。

+0

是否有任何理由将您的jOOQ代码生成器插件放在''中,而不是直接放入''中? –

+0

如果我删除这个标签,我得到这个错误'插件执行没有覆盖生命周期配置:org.jooq:jooq-codegen-maven:3.8.4:generate(execution:default,phase:generate-sources)' –

+0

Aha,我懂了。有这个众所周知的Eclipse m2e错误,并且[人们建议引入''标签来“修复”它。](http://stackoverflow.com/q/6352208/521799),但是这会改变你的语义Maven构建。 –

回答

1

您仍然需要将插件添加到您的版本,因为<pluginManagement>只能帮助您声明常用配置以供重用。

<build> 
    <pluginManagement>...</pluginManagement> 
    <plugins> 
     <plugin> 
      <groupId>org.jooq</groupId> 
      <artifactId>jooq-codegen-maven</artifactId> 
      <execution>...</execution> 
     </plugin> 
    </plugins> 
</build> 

也看到这个问题在这里:Maven: What is pluginManagement?

在这种情况下,它可能简单到只是ignore this well-known issue in Eclipse and avoid the <pluginManagement> element