简体   繁体   中英

querydsl generate Q classes in src/main/java

I am using querydsl in my spring project and want to generate Q classes at src/main/java/xxx/xxx/model/here . When I write except for src/main/java at my pom.xml, it will work. But, When I write src/main/java, it will not work.(doesn't generate q classes.) Do you know why? In src/main/java, there are another classes I wrote. Is it impossible to generate Q classes at existing place?

Here is my pom.xml

<plugin>
    <groupId>com.mysema.maven</groupId>
    <artifactId>apt-maven-plugin</artifactId>
    <version>1.1.3</version>
    <executions>
        <execution>
            <phase>generate-sources</phase>
            <goals>
                <goal>process</goal>
            </goals>
            <configuration>
                <outputDirectory>src/main/java</outputDirectory>
                <processor>
                    com.querydsl.apt.jpa.JPAAnnotationProcessor
                </processor>
            </configuration>
        </execution>
    </executions>
    <dependencies>
        <dependency>
            <groupId>com.querydsl</groupId>
            <artifactId>querydsl-apt</artifactId>
            <version>${querydsl.version}</version>
        </dependency>
    </dependencies>
</plugin>

You should add the directory path in target like this:

target/generated-sources/java

First of all why do you think of generating them in source folder. That way you are complicating your actual codebase. They are auto generated files. They are supposed to be as given below

<configuration>
    <outputDirectory>target/generated-sources/querydsl</outputDirectory>
    <processor>com.querydsl.apt.jpa.JPAAnnotationProcessor</processor>
</configuration>

But if you still need them in src folder , follow steps below.

  1. Disable Project › Build Automatically…
  2. Run Maven goal 'generate-sources', which runs apt-maven-plugin
  3. Refresh the project in Eclipse, the generated source files are present as expected
  4. Project › Build Project

The folder with generated sources is created.

You may look at the class path setting for the project. Now you can use all Q classes wherever you need.

项目建设路径

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM