Maven wsdl import. How to use the generated files? - java

i have a problem and I'm not able to solve or understand the hole workflow behind this process.
I use eclipse with maven.
This is my simple test pom.xml
...
<dependencies>
<dependency>
<groupId>com.sun.xml.ws</groupId>
<artifactId>jaxws-rt</artifactId>
<version>2.2.8</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.jvnet.jax-ws-commons</groupId>
<artifactId>jaxws-maven-plugin</artifactId>
<version>2.2</version>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>wsimport</goal>
</goals>
<configuration>
<xdebug>true</xdebug>
<verbose>true</verbose>
<keep>true</keep>
<packageName>abc.model</packageName>
<sourceDestDir>${project.build.directory}/generated-sources/wsimport/</sourceDestDir>
</configuration>
</execution>
</executions>
</plugin>
<plugin> <groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.9.1</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/wsimport/</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
...
The jaxws-maven-plugin generate the files in the sourceDestDir. The build-helper-maven-plugin add the files during the maven install process the to the correct folder and also into the resulting jar file. So far so good.
But I'm not able to use the generated files/classes in eclipse. So in eclipse maven does not recognize the files as source or does not but this in the source path. Did I make an mistake or did I miss something?
Thanks for your help.
Update:
I observer a strange behavior. Same test project same pom file. If I import this existing Maven Project in eclipse it works like expected. I can directly use the generated files as source.
But if I delete this source folder, I'm still not able to restore this with maven.

Related

How to package spring boot project with multiple JAR dependencies?

I have a spring boot project that has a few local jar files dependencies like
mssql-jdbc-6.2.1.jre8.jar
internal-commons.jar
internal-db.jar
etc.
How do I package the project into a WAR file? Thanks in advance!
You can use existing libraries to achieve this.
If you use maven, you can use the maven-dependency-plugin
For example, in your pom.xml file, add the following to your dependencies:
<dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.2.0</version>
</dependency>
And then, use it as a plugin in your pom.xml:
<plugin>
<!-- http://jonathangraham.github.io/2016/01/05/Local_Jar_Dependency_With_Maven -->
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/lib</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
The entire process is explained here in more detail.

Add generated Apache Avro source with build-helper-maven-plugin

I'm using Apache avro to generate some pojos, all work very well in run, expect that the generated source is marked as inexistent in imports on IDE (intellij) .
I tried to use build-helper-maven-plugin to add source, but it doesn't work
this is my maven configuration for apache avro and build helper plugins :
<plugin>
<groupId>org.apache.avro</groupId>
<artifactId>avro-maven-plugin</artifactId>
<version>${avro.version}</version>
<configuration>
<stringType>String</stringType>
</configuration>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>schema</goal>
</goals>
<configuration>
<sourceDirectory>${project.basedir}/src/main/avro/</sourceDirectory>
<outputDirectory>${project.build.directory}/generated-sources/</outputDirectory>
<imports>
<import>${project.basedir}/src/main/avro/errorkind.avsc</import>
</imports>
</configuration>
</execution>
</executions>
</plugin>
<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>${project.build.directory}/generated-sources</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
Try changing your pom with following and run clean install and then you should be able to import.
<configuration>
<sourceDirectory>${project.basedir}/src/main/resources/</sourceDirectory>
<source>${project.build.directory}/generated-sources</source>
</configuration>
In POM InteliJ may give you a fake error after adding this but your build will success.
"generated-sources" reside under ${project.build.directory}/target folder
Also, try marking "generated-sources" as source directory. You can do that by:
Project Structure → Modules → Click the generated-sources folder and make it a sources folder.

Can I make an executable jar with "build-info" by "Spring Boot Maven Plugin"?

I am trying to make an executable jar file with "Spring Boot Maven Plugin".
Usually, I can do this by setting "repackage". goal in my pom.xml file was set like this.
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.2.6.RELEASE</version>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
And my build command is like this:
mvn clean package spring-boot:repackage
This works, but I want to have META-INF/build-info.properties in the jar file.
By having this file, I can check build info in my springboot application, so I want to have it.
To generate "META-INF/build-info.properties" file, I need to set "build-info" goal.
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.2.6.RELEASE</version>
<executions>
<execution>
<goals>
<goal>build-info</goal>
</goals>
</execution>
</executions>
</plugin>
Well now I am in a dilemma because
Setting "repackage" goal -> an executable jar without "META-INF/build-info.properties"
Setting "build-info" goal -> an inexecutable jar with "META-INF/build-info.properties"
I want to have an executable jar with "META-INF/build-info.properties".
I am pretty new to this maven process. Is there anyone who can help me?
SOLVED
I solved this issue. The problem was spring-boot-maven-plugin was in the wrong place. It was inside <pluginManagement>. I moved this plugin to <plugins>
Like #Mark Bramnik answered, I can set both goal settings in pom.xml, and mvn clean package command is enough!
You can run multiple goals of the same plugin.
So you can probably do something like this:
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.2.6.RELEASE</version>
<executions>
<execution>
<goals>
<goal>build-info</goal>
</goals>
</execution>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>

Generating jar of a maven project with all sources

I want to generate a jar which contains all the source files,test classes, resources, dependencies, extra source directories of a maven project.
Can anyone please help me, thanks in advance.
You can use the maven-source-plugin. This will create a sources.jar during mvn install:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

No JAXB Classes Generated from xsd using Maven Plugin

am not able see any of jaxb classes generated from my xsd using jaxb2-maven-plugin
<bulid>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxb2-maven-plugin</artifactId>
<version>1.5</version>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
<configuration>
<schemaDirectory>src/main/xsd</schemaDirectory>
<sourceGenerationDirectory>target/sources</sourceGenerationDirectory>
<classGenerationDirectory>target/classes</classGenerationDirectory>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</bulid>
<dependencies>
<dependency>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxb2-maven-plugin</artifactId>
<version>1.5</version>
</dependency>
and i ran my pom by giving
clean install generate:generate is that a correct way ? please suggest a way to generate jaxb classes
i even tried to run by mvn generate-sources nothing is getting generated
This has worked for me at some point in time; you can work from there:
<plugin>
<groupId>com.sun.tools.xjc.maven2</groupId>
<artifactId>maven-jaxb-plugin</artifactId>
<version>1.1</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
<configuration>
<removeOldOutput>false</removeOldOutput>
<schemaDirectory>src/main/resources/xsd</schemaDirectory>
<includeBindings>
<includeBinding>*.xjb</includeBinding>
</includeBindings>
</configuration>
</plugin>
The plugin is bound to the generate-sources phase.
Cheers,
i just changed my goal to xjc and mvn jaxb2:xjc it worked i was able to get the jxb classes generated

Categories