Compile Jasper reports from Maven with ant task? - maven-2

How can I compile jrxml jasper files using Maven and JRAntCompileTask ant task? I tried using a maven plugin for compiling jasper reports files but it's still in beta, and it caused me many problems. I'd like to see the configuration in pom.xml.

How can I compile jrxml jasper files using Maven and JRAntCompileTask ant task?
You can use the custom Ant Tasks with the Maven AntRun Plugin. See the example provided in Using tasks not included in Ant's default jar.

You can try jasperreports-maven-plugin, that way you don't have to use ant, Here is an example.

Here's a complete example that solves problems with Eclipse m2e reporting errors with maven configuration, has reports neatly set in a separate folder and has classpath configured.
Just be sure to put your .jrxml files in src/main/jasperreports folder and you're set - every time you change the report, .jasper files will be regenerated.
pom.xml:
<properties>
<jasperreports.version>5.0.0</jasperreports.version>
</properties>
<build>
<pluginManagement>
<plugins>
<!--This plugin's configuration is used to store Eclipse m2e settings only. It has no influence on the Maven build itself. -->
<plugin>
<groupId>org.eclipse.m2e</groupId>
<artifactId>lifecycle-mapping</artifactId>
<version>1.0.0</version>
<configuration>
<lifecycleMappingMetadata>
<pluginExecutions>
<pluginExecution>
<pluginExecutionFilter>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jasperreports-maven-plugin</artifactId>
<versionRange>[1.0-beta-2,)</versionRange>
<goals>
<goal>compile-reports</goal>
</goals>
</pluginExecutionFilter>
<action>
<execute />
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
</plugins>
</pluginManagement>
<sourceDirectory>src/main/java</sourceDirectory>
<resources>
<resource>
<directory>src/main/java</directory>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
</resource>
<resource>
<directory>src/main/resources</directory>
</resource>
<resource>
<!-- Include the generated reports in classpath -->
<directory>target/jasper</directory>
</resource>
<resource>
<!--Folder with .jrxml report files -->
<directory>src/main/jasperreports</directory>
</resource>
</resources>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jasperreports-maven-plugin</artifactId>
<configuration>
<!-- Folder where compiled reports will be generated -->
<outputDirectory>${project.build.directory}/jasper</outputDirectory>
</configuration>
<executions>
<execution>
<goals>
<goal>compile-reports</goal>
</goals>
<phase>generate-sources</phase>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jasperreports-maven-plugin</artifactId>
<version>1.0-beta-2</version>
<exclusions>
<exclusion>
<groupId>net.sf.jasperreports</groupId>
<artifactId>jasperreports</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>net.sf.jasperreports</groupId>
<artifactId>jasperreports</artifactId>
<version>${jasperreports.version}</version>
</dependency>
<dependency>
<groupId>com.lowagie</groupId>
<artifactId>itext</artifactId>
<version>4.2.0</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
...

Related

How to install TestNG in Visual studio code

Can someone please suggest me how to install testng in visual studio code?
Things i have done so far :
1. Added below xml in POM
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.10</version>
<scope>test</scope>
</dependency>
#Sowjanya H M try adding the Java Test Runner extension. it supports running both junit and testng tests. If you have your pom setup correctly, you can execute all tests in your project by selecting your pom.xml and in the command dropdown selecting Run Code. I have a later version of testng in my pom dependencies section:
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.14.3</version>
</dependency>
then in your build section, you should have configuration plugins for maven-surefire and your testng xml files. something like:
<build>
<resources>
<resource>
<directory>src/test/resources</directory> #not required
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.0</version>
<configuration>
<!-- testng xml files for test execution -->
<suiteXmlFiles>
<suiteXmlFile>resources/sample.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
</plugins>
</build>

Intellij + Ajc + Lombok/Mapstruct

I want to enable AspectJ compiler in my IntelliJ Idea as I have several aspects that I'd like to be woven during compile time.
At the same time, I am using Lombok and Mapstruct in my codebase.
Those 2 require additional annotations processing, that must happen before ajc kicks in.
I have both plugins installed for Lombok and Mapstruct. Independently they work fine, source code is being generated. But when I enable ajc and tick Enable annotation processing options, and then build a project, I get:
Error:(9, 0) ajc: Internal error in the mapping processor: java.lang.NullPointerException at org.aspectj.org.eclipse.jdt.internal.compiler.lookup.FieldBinding.sourceField(FieldBinding.java:425) at org.aspectj.org.eclipse.jdt.internal.compiler.apt.model.TypeElementImpl$SourceLocationComparator.determineSourceStart(TypeElementImpl.java:108) at org.aspectj.org.eclipse.jdt.internal.compiler.apt.model.TypeElementImpl$SourceLocationComparator.getSourceStart(TypeElementImpl.java:72) at org.aspectj.org.eclipse.jdt.internal.compiler.apt.model.TypeElementImpl$SourceLocationComparator.compare(TypeElementImpl.java:65) at org.aspectj.org.eclipse.jdt.internal.compiler.apt.model.TypeElementImpl$SourceLocationComparator.compare(TypeElementImpl.java:1) at java.util.TimSort.countRunAndMakeAscending(TimSort.java:360) at java.util.TimSort.sort(TimSort.java:234) at java.util.Arrays.sort(Arrays.java:1512) at java.util.ArrayList.sort(ArrayList.java:1462) at java.util.Collections.sort(Collections.java:175) at org.aspectj.org.eclipse.jdt.internal.compiler.apt.model.TypeElementImpl.getEnclosedElements(TypeElementImpl.java:166) at org.mapstruct.ap.internal.util.workarounds.SpecificCompilerWorkarounds.replaceTypeElementIfNecessary(SpecificCompilerWorkarounds.java:99) at org.mapstruct.ap.internal.util.Executables.getAllEnclosedExecutableElements(Executables.java:99) at org.mapstruct.ap.internal.model.common.Type.getAllMethods(Type.java:633) at org.mapstruct.ap.internal.model.common.Type.getPropertyReadAccessors(Type.java:496) at org.mapstruct.ap.internal.model.BeanMappingMethod$Builder.build(BeanMappingMethod.java:168) at org.mapstruct.ap.internal.processor.MapperCreationProcessor.getMappingMethods(MapperCreationProcessor.java:376) at org.mapstruct.ap.internal.processor.MapperCreationProcessor.getMapper(MapperCreationProcessor.java:151) at org.mapstruct.ap.internal.processor.MapperCreationProcessor.process(MapperCreationProcessor.java:122) at org.mapstruct.ap.internal.processor.MapperCreationProcessor.process(MapperCreationProcessor.java:76) at org.mapstruct.ap.MappingProcessor.process(MappingProcessor.java:283) at org.mapstruct.ap.MappingProcessor.processMapperTypeElement(MappingProcessor.java:263) at org.mapstruct.ap.MappingProcessor.processMapperElements(MappingProcessor.java:221) at org.mapstruct.ap.MappingProcessor.process(MappingProcessor.java:156) at org.aspectj.org.eclipse.jdt.internal.compiler.apt.dispatch.RoundDispatcher.handleProcessor(RoundDispatcher.java:139) at org.aspectj.org.eclipse.jdt.internal.compiler.apt.dispatch.RoundDispatcher.round(RoundDispatcher.java:121) at org.aspectj.org.eclipse.jdt.internal.compiler.apt.dispatch.BaseAnnotationProcessorManager.processAnnotations(BaseAnnotationProcessorManager.java:159) at org.aspectj.org.eclipse.jdt.internal.compiler.Compiler.processAnnotations(Compiler.java:931) at org.aspectj.org.eclipse.jdt.internal.compiler.Compiler.compile(Compiler.java:437) at org.aspectj.org.eclipse.jdt.internal.compiler.Compiler.compile(Compiler.java:417) at org.aspectj.ajdt.internal.core.builder.AjBuildManager.performCompilation(AjBuildManager.java:1036) at org.aspectj.ajdt.internal.core.builder.AjBuildManager.performBuild(AjBuildManager.java:272) at org.aspectj.ajdt.internal.core.builder.AjBuildManager.batchBuild(AjBuildManager.java:185) at com.intellij.lang.aspectj.build.AjJpsCompiler.doBuild(AjJpsCompiler.java:249) at com.intellij.lang.aspectj.build.AjJpsCompiler.build(AjJpsCompiler.java:119) at com.intellij.lang.aspectj.build.AjTranslatingBuilder.doBuild(AjTranslatingBuilder.java:114) at com.intellij.lang.aspectj.build.AjBuilderBase.build(AjBuilderBase.java:74) at org.jetbrains.jps.incremental.IncProjectBuilder.runModuleLevelBuilders(IncProjectBuilder.java:1328) at org.jetbrains.jps.incremental.IncProjectBuilder.runBuildersForChunk(IncProjectBuilder.java:1008) at org.jetbrains.jps.incremental.IncProjectBuilder.buildTargetsChunk(IncProjectBuilder.java:1075) at org.jetbrains.jps.incremental.IncProjectBuilder.buildChunkIfAffected(IncProjectBuilder.java:969) at org.jetbrains.jps.incremental.IncProjectBuilder.buildChunks(IncProjectBuilder.java:798) at org.jetbrains.jps.incremental.IncProjectBuilder.runBuild(IncProjectBuilder.java:380) at org.jetbrains.jps.incremental.IncProjectBuilder.build(IncProjectBuilder.java:178) at org.jetbrains.jps.cmdline.BuildRunner.runBuild(BuildRunner.java:139) at org.jetbrains.jps.cmdline.BuildSession.runBuild(BuildSession.java:302) at org.jetbrains.jps.cmdline.BuildSession.run(BuildSession.java:135) at org.jetbrains.jps.cmdline.BuildMain$MyMessageHandler.lambda$channelRead0$0(BuildMain.java:228) at org.jetbrains.jps.service.impl.SharedThreadPoolImpl.lambda$executeOnPooledThread$0(SharedThreadPoolImpl.java:42) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) at java.lang.Thread.run(Thread.java:748)
Also, I see a bunch of other ajc compilation errors as it is not able to locate methods that should've been generated by the Lombok.
How do I solve these issues?
Hi I had similar issue.
The fix was to let aspectj-maven-plugin to only start weaving after classes are compiled.
It describes in more detail here https://www.mojohaus.org/aspectj-maven-plugin/examples/weaveDirectories.html
I needed to:
(1) Specify folder where already compiled classes will be via <weaveDirectories >
(2) Change the phase of maven-compiler-plugin lifecycle to be run "process-classes" or later.
This is how my pom looked like.
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<annotationProcessorPaths>
<path>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-processor</artifactId>
<version>${mapstruct.version}</version>
</path>
<path>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${org.projectlombok.version}</version>
</path>
</annotationProcessorPaths>
<compilerArgs>
<compilerArg>-Amapstruct.defaultComponentModel="spring"</compilerArg>
<compilerArg>-Amapstruct.unmappedTargetPolicy=ERROR</compilerArg>
<compilerArg>-Amapstruct.suppressGeneratorTimestamp=true</compilerArg>
<compilerArg>-Amapstruct.suppressGeneratorVersionInfoComment=true</compilerArg>
</compilerArgs>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<configuration>
<showWeaveInfo>${showWeaveInfo}</showWeaveInfo>
<showWeaveInfo>true</showWeaveInfo>
<Xlint>ignore</Xlint>
<complianceLevel>${java.compiler.version}</complianceLevel>
<encoding>UTF-8</encoding>
<verbose>false</verbose>
<verbose>true</verbose>
<forceAjcCompile>true</forceAjcCompile>
<sources/>
<weaveDirectories>
<weaveDirectory>${project.build.directory}/classes</weaveDirectory>
</weaveDirectories>
<aspectLibraries>
<aspectLibrary>
<groupId>com.lib.test</groupId>
<artifactId>test1</artifactId>
</aspectLibrary>
<aspectLibrary>
<groupId>com.lib.test2</groupId>
<artifactId>test2</artifactId>
</aspectLibrary>
</aspectLibraries>
</configuration>
<executions>
<execution>
<phase>process-classes</phase>
<goals>
<goal>compile</goal>
<goal>test-compile</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjtools</artifactId>
<version>${aspectj.version}</version>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>${aspectj.version}</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
Enabling Post-compile weave mode in IntelliJ solved it for me (https://www.jetbrains.com/help/idea/using-the-aspectj-ajc-compiler.html).
if you have aspect sources with the same project then you should add a few line codes to the #jun-huh answers and delete <aspectLibraries>. The below pom.xml is for if you use your aspects with the same project.
<?xml version="1.0" encoding="UTF-8"?>
<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>az.sanco</groupId>
<artifactId>aspect</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>1.9.7</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.22</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<version>1.14.0</version>
<configuration>
<forceAjcCompile>true</forceAjcCompile>
<weaveDirectories>
<weaveDirectory>${project.build.outputDirectory}</weaveDirectory>
</weaveDirectories>
<complianceLevel>1.8</complianceLevel>
<source>1.8</source>
<target>1.8</target>
<proc>none</proc><!-- annotation process already finished, so we don't need to run again-->
</configuration>
<executions>
<execution>
<id>copy-only-aspect-files</id>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
<configuration>
<!--when `javac` compile works it does not copy *.aj files to the
output directory. We need to run `ajc` compile during `compile` phase and
copy only *.aj files to weave our classes-->
<includes>
<include>**/*.aj</include><!--IMPORTANT-->
</includes>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

Run tests from maven zip assembly

I have finally succeeded in getting Maven to zip together a bunch of jars using an assembly file and install it to my local repository. That was difficult enough...
Now my goal is to configure another maven project so that when I do "mvn test", it will pull in that zip, unpack it, and run tests from the jars within that zip file. Does anyone know how to do this?
Here is the POM for the assembly project:
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.pason</groupId>
<artifactId>RigFocusOnDataHub</artifactId>
<name>RigFocusOnDataHub</name>
<version>12.2.0-SNAPSHOT</version>
<packaging>pom</packaging>
<dependencies>
...
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.3</version>
<configuration>
<descriptors>
<descriptor>RigFocusOnDH.xml</descriptor>
</descriptors>
</configuration>
<executions>
<execution>
<id>zip</id>
<!-- this is used for inheritance merges -->
<phase>package</phase>
<!-- append to the packaging phase. -->
<goals>
<goal>single</goal>
<!-- goals == mojos -->
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
Here is the POM for the second project. Unfortunately, instead of downloading the zip file for RigFocusOnDataHub, it just fetches the jars for all of RigFocusOnDataHub's dependencies from the local repo.
<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>com.pason</groupId>
<artifactId>RigFocusDHSystemTest</artifactId>
<version>12.2.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>com.pason</groupId>
<artifactId>MurphyRigFocus</artifactId>
<version>2.0.0-SNAPSHOT</version>
<type>test-jar</type>
</dependency>
<dependency>
<groupId>com.pason</groupId>
<artifactId>RigFocusOnDataHub</artifactId>
<version>12.2.0-SNAPSHOT</version>
<type>pom</type>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.2</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>unpack</id>
<phase>process-test-classes</phase>
<goals>
<goal>unpack</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>com.pason</groupId>
<artifactId>MurphyRigFocus</artifactId>
<version>2.0.0-SNAPSHOT</version>
<type>test-jar</type>
<outputDirectory>${project.build.directory}/tests/MurphyRigFocus</outputDirectory>
</artifactItem>
<artifactItem>
<groupId>com.pason</groupId>
<artifactId>RigFocusOnDataHub</artifactId>
<version>12.2.0-SNAPSHOT</version>
<type>zip</type>
<outputDirectory>${project.build.directory}/tests/MurphyRigFocus</outputDirectory>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.6</version>
<configuration>
<testClassesDirectory>${project.build.directory}/tests/MurphyRigFocus</testClassesDirectory>
<reportsDirectory>${project.build.directory}/surefire-reports/MurphyRigFocus</reportsDirectory>
<includes>
<include>**/*IT.*</include>
</includes>
<argLine>-Djava.library.path=${basedir}/target/classes/</argLine>
<forkMode>pertest</forkMode>
</configuration>
</plugin>
</plugins>
</build>
You would need to:
extract the jars from the zip - this is easy enough with maven-dependency-plugin
cut transitive dependencies so your jars don't end up in the path twice - you can do that at the source with maven-shade-plugin or in the test project itself with dependencies exclusions
add the jars to your test classpath, there are many ways to do that, I would try to use additional parameters in surefire configuration first

Referring exploded war dependency in maven antrun plugin

I have a dependency declared as follows
<dependency>
<groupId>com.abc.webapp</groupId>
<artifactId>mywebapp</artifactId>
<version>1.3.2</version>
<type>war</type>
</dependency>
This war file which is part of an ear is exploded in the target directly and I need to copy a file(version.properties) to the WEB-INF/classes folder of this exploded war directory (target/mywebapp-1.3.2.war/). How can I refer to this folder in the antrun plugin without any hardcoding? Thanks in advance.
I'm going to cheat a bit and ask that you declare the dependency like this, with references to properties:
<dependency>
<groupId>${war.groupId}</groupId>
<artifactId>${war.artifactId}</artifactId>
<version>${war.version}</version>
<type>war</type>
</dependency>
and the properties would look something like this in your pom.
<properties>
<war.groupId>com.abc.webapp</war.groupId>
<war.artifactId>mywebapp</war.artifactId>
<war.version>1.3.2</war.version>
</properties>
Now, you still need to change the war GAV if required, but you only need to do it once, and the <dependency> and copy will both refer to the same thing.
Then maybe you could also use the maven-resouces-plugin and its copy-resource goal.
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>2.5</version>
<executions>
<execution>
<id>copy-resources</id>
<!-- here the phase you need -->
<phase>validate</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${basedir}/${war.artifactId}-${war.version}.war/WEB-INF/classes</outputDirectory>
<resources>
<resource>
<directory>where_version.properties_is</directory>
<includes>
<include>version.properties</include>
</includes>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>

How to include automatically xmlbeans generated code into maven jar?

I have a project which uses Apache Xmlbeans for databinding. Currently it is very simple it only has some Schema-Files in src/main/xsd and xsdconfig in src/main/xsdconfig.
I want to include the generated Classes into the generated jar-File. It works if I specify the xmlbeans goal:
"mvn xmlbeans:xmlbeans package" --> Creates a Jar with the xmlbeans classes
But I want to do this within the normal build cycle: "mvn package" --> should create a jar with the xmlbeans classes, but won't.
The pom is the following:
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.test</groupId>
<artifactId>xmlbeans-maven-test</artifactId>
<version>0.0.1-SNAPSHOT</version>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>maven-xmlbeans-plugin</artifactId>
<version>2.3.3</version>
</plugin>
</plugins>
</pluginManagement>
</build>
<dependencies>
<dependency>
<groupId>org.apache.xmlbeans</groupId>
<artifactId>xmlbeans</artifactId>
<version>2.4.0</version>
<scope>compile</scope>
</dependency>
</dependencies>
</project>
I tried to bind it manually to the "generate-sources" (And to the "compile" phase, too) phase, but it does not work.
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>de.leradon</groupId>
<artifactId>xmlbeans-maven</artifactId>
<version>0.0.1-SNAPSHOT</version>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>maven-xmlbeans-plugin</artifactId>
<version>2.3.3</version>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>xmlbeans</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
</build>
<dependencies>
<dependency>
<groupId>org.apache.xmlbeans</groupId>
<artifactId>xmlbeans</artifactId>
<version>2.4.0</version>
<scope>compile</scope>
</dependency>
</dependencies>
</project>
How can I configure the plugin, so that when I run "mvn package" all the generated classes are packaged into the jar?
Greetings,
lerad
If you configure the plugin under pluginManagement, you still need to declare it under plugins. To simplify, I'm not using the pluginManagement in the pom.xml below:
<project>
...
<dependencies>
...
<dependency>
<groupId>org.apache.xmlbeans</groupId>
<artifactId>xmlbeans</artifactId>
<version>2.4.0</version>
<scope>compile</scope>
</dependency>
</dependencies>
<build>
<plugins>
...
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>xmlbeans-maven-plugin</artifactId>
<version>2.3.3</version>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>xmlbeans</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
With this POM (and some XSD in src/main/xsd which is the default location), running mvn clean package just works (i.e. sources are generated from the XSD, compiled and packaged as part of the build).
Try this.
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>xmlbeans-maven-plugin</artifactId>
<version>2.3.2</version>
<executions>
<execution>
<id />
<phase>generate-sources</phase>
<goals>
<goal>xmlbeans</goal>
</goals>
</execution>
</executions>
<configuration>
<schemaDirectory>src/main/xsd</schemaDirectory>
<staleFile>${project.build.directory}/generated-sources/xmlbeans/.staleFlag</staleFile>
<verbose>false</verbose>
<quiet>false</quiet>
<javaSource>1.6</javaSource>
</configuration>
</plugin>