How to configure generated Sources in e clipse - java

Hello When I use mapper annotations my code automaticly generated codes under;
mappers -->target->generated-source->annotations->net->worl->car->agencyportal->service->mappers->UserMapperImp.java
So how can I generated just under the folder which I created mapper folder my own
Thank you in advanced

in your plugins in your pom.xml add this for example, configure your source as you want:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<executions>
<execution>
<id>add-source</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>target/generated-sources/swagger/src/main/java</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>

Related

How do I add additional source directories to maven to generate javadoc?

I used this in my pom.xml to recognize the second source directory I have in my project:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>3.2.0</version>
<executions>
<execution>
<id>add-source</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>src/main/java-extra/</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
But generating javadoc fails saying it can't find the classes in the java-extra directory. How can I make maven javadoc see the second directory?
There is a sourcepath parameter for maven-javadoc-plugin. There you provide list of your source folders, separated by : or ;. See https://maven.apache.org/plugins/maven-javadoc-plugin/javadoc-mojo.html#sourcepath
For example:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.3.2</version>
<configuration>
<sourcepath>src/main/java;${defines.dir}</sourcepath>
</configuration>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>

How to generate java classes into source folder using jaxb2-maven-plugin?

I use jaxb2-maven-plugin to generate java classes.
There is plugin properties:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxb2-maven-plugin</artifactId>
<version>2.3</version>
<executions>
<execution>
<id>xjc</id>
<goals>
<goal>xjc</goal>
</goals>
</execution>
</executions>
<configuration>
<!-- The package of your generated sources -->
<packageName>com.bcap.me.JaxB</packageName>
<sources>
<source>src/main/resources/xsds/pos.xsd</source>
</sources>
</configuration>
</plugin>
After running mvn clean compile the plugin creates classes in the target\classes\com\bcap\me\JaxB directory.
But i need to have classes in the source folder (package): src\main\java\com\bcap\me\JaxB
How to do this?
UPDATE
I add outputDirectory property, but i am not sure about the correctness of this approach:
<!--<packageName>com.bcap.me.JaxB</packageName>-->
<outputDirectory>src/main/java/com/bcap/me/JaxB</outputDirectory>
UPDATE
I solved my case like:
<execution>
<id>xjc_pos</id>
<goals>
<goal>xjc</goal>
</goals>
<configuration>
<!-- The package of your generated sources -->
<packageName>com.bcap.me.JaxB</packageName>
<outputDirectory>src/main/java</outputDirectory>
<sources>
<source>src/main/resources/xsds/pos.xsd</source>
</sources>
<generateEpisode>false</generateEpisode>
<clearOutputDir>false</clearOutputDir>
</configuration>
</execution>
Thanks to #ulab
You could use following maven plugin
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.1</version>
<executions>
<execution>
<id>add-source</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>target/generated-sources/xjc</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>

Can I generate JPA metamodels and QueryDSL models in same project

I have a project where we have code implemented using JPA and we use metamodels. To generate hibernate metamodels we use following as a maven plaugin
<plugin>
<groupId>org.bsc.maven</groupId>
<artifactId>maven-processor-plugin</artifactId>
<executions>
<execution>
<id>process</id>
<goals>
<goal>process</goal>
</goals>
<phase>process-sources</phase>
<configuration>
<outputDirectory>${project.build.directory}/generated-sources/annotations/</outputDirectory>
<processors>
<processor>org.hibernate.jpamodelgen.JPAMetaModelEntityProcessor</processor>
</processors>
</configuration>
</execution>
</executions>
</plugin>
Now we like to try out QueryDSL, and I added the maven configuration to generate QueryDSL-models. It looks like following.
<plugin>
<groupId>com.mysema.maven</groupId>
<artifactId>apt-maven-plugin</artifactId>
<version>1.1.3</version>
<executions>
<execution>
<goals>
<goal>process</goal>
</goals>
<configuration>
<outputDirectory>target/generated-sources/java</outputDirectory>
<processor>com.querydsl.apt.jpa.JPAAnnotationProcessor</processor>
</configuration>
</execution>
</executions>
</plugin>
But now when I run maven clean test it complains that JPA Hibernate metamodels are missing. But if I switch the order then it complaints that other metamodels are missing. So is there a way to use both of them in same porject?
I guess your problem is not the generation itself, but that you have classes in your codebase that depend on the generated classes.
Have you tried to add the generation output directories as source directories like this?
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.3</version>
<executions>
<execution>
<id>add-source</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>${project.build.directory}/generated-sources/annotations</source>
<source>${project.build.directory}/generated-sources/java</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
Should work for mvn on CLI as well for m2e in Eclipse.

After adding #XmlRootElement annotation for generated classes i can't access them in my source classes

As i've already described in title i have a problem in accessing generated classes from my source classes when i add #XmlRootElement annotation on resource -generation step.
My jaxb2-maven-plugin config:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxb2-maven-plugin</artifactId>
<version>1.6</version>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>xjc</goal>
</goals>
</execution>
</executions>
<configuration>
<schemaDirectory>src/main/resources/schemas</schemaDirectory>
<packageName>my.classses</packageName>
<bindingDirectory>${project.basedir}/src/main/resources/xjb</bindingDirectory>
<extension>true</extension>
</configuration>
</plugin>
Any help will be useful, thanks in advance!
The generated source files are probably located under generated-sources which is not added as a source directory by default, try using something like:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<executions>
<execution>
<id>add-source</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>${project.build.directory}/generated-sources/DIRNAME</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
Just replace DIRNAME with the name of the directory the generated files are in.

Maven: How to handle generated sources for test(only)?

Usually generated sources should be created in the target dir. But how do I handle classes that are only used for test? I dont want that these classes get packaged in my jar. Is there a common way to deal with this situation?
Use maven build helper plugin's add-test-source goal to add your generated test source files to the build -> http://mojo.codehaus.org/build-helper-maven-plugin/add-test-source-mojo.html
It ensures that the directories added by this goal will be picked up automatically by the compiler plugin during test-compile phase of the build.
EDIT
Here is the example of how to generate code for testign with cxf-codegen-plugin
<build>
<plugins>
...
<plugin>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-codegen-plugin</artifactId>
<version>${cxf.version}</version>
<executions>
<execution>
<id>generate-test-sources</id>
<phase>generate-test-sources</phase>
<configuration>
<sourceRoot>${project.build.directory}/generated/cxf</sourceRoot>
<wsdlOptions>
<wsdlOption>
<wsdl>${basedir}/src/main/wsdl/myService.wsdl</wsdl>
</wsdlOption>
</wsdlOptions>
</configuration>
<goals>
<goal>wsdl2java</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>${build-helper-maven-plugin.version}</version>
<executions>
<execution>
<id>add-test-sources</id>
<phase>generate-test-sources</phase>
<goals>
<goal>add-test-source</goal>
</goals>
<configuration>
<sources>
<source>${project.build.directory}/generated/cxf</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
...
</plugins>
</build>

Categories