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>
Related
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
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>
...
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>
I'm using almost same POM for both my projects, they are on the same workspace but they are not related at all, they are related however because in both I use spring and jboss. Here is the pom :
<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.springinaction.hello</groupId>
<artifactId>spring-in-action</artifactId>
<packaging>jar</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>spring-in-action</name>
<url>http://maven.apache.org</url>
<properties>
<jboss.ome>C:\jboss-5.1.0.GA\server\default\deploy</jboss.ome>
<springversion>2.5.3</springversion>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring</artifactId>
<version>${springversion}</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.14</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.0</version>
<configuration>
<warName>spring-book</warName>
<outputDirectory>${jboss.ome}</outputDirectory>
</configuration>
</plugin>
</plugins>
</build>
</project>
What I want to achieve with this POM is that I want to name my war when built spring-book.war and copy it to Jboss location I specified. Now in my first project this works it does exactly what I requested but in other it does not. I changed springversion and jboss home properties variable but everything remains the same, what can I do ? The project builds and all, everything is working perfectly just I don't want to copy everytime in my jboss dir and previously remove the old war, it takes about 20sec on each source code change its a lot
Problem spotted at this line:
<packaging>jar</packaging>
You're not using the right packaging, it should be:
<packaging>war</packaging>
After this change the war plugin should get called and things should work like in the other project :)
You could leave the output directory at its default, and use a profile instead with the maven jboss plugin. It has a hard-deploy target which copies your artifact to the deploy directory. If it's in a profile, you can activate it when (and only when) you want.
Moreover, with the antrun plugin, you can also delete the old war file before copying over the new one (this is useful when the war filename includes the version, but in your case may not be needed).
<profiles>
<profile>
<id>deploy</id>
<build>
<plugins>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>remove-old-war</id>
<phase>prepare-package</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<tasks>
<delete>
<fileset dir="${jboss.ome}"
includes="*.war"/>
</delete>
</tasks>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jboss-maven-plugin</artifactId>
<executions>
<execution>
<id>redeploy-server</id>
<phase>pre-integration-test</phase>
<goals>
<goal>hard-deploy</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
You can then activate the profile with
mvn -Pdeploy install
I have a simple pom and added an ant-run to the compile but it only executes then when I do the following:
mvn install antrun:run
mvn install -- doesn't process the ant-run
mvn antrun:run -- doesn't process the ant-run
I thought that be linking the plugin to the lifecyce phase that the plugin would be executed when I try to achieve that phase. This is not what is happening.
Am I missing some nuance, do I need to have a profile which enables the plugin?
Thanks for the help (pom below)
<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.mycompany.app</groupId>
<artifactId>my-app</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>my-app</name>
<url>http://maven.apache.org</url>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.3</version>
<executions>
<execution>
<id>antecho</id>
<phase>compile</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<tasks>
<echo message="Hello,world"/>
</tasks>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
</build>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
You've specified the plugin below the <pluginManagement> section. This means that this configuration will be used if the plugin is also declared directly under build/plugins, for example in a child POM.
To make it work in this instance remove the <pluginManagement> tags so that <plugins> is directly below <build> like this:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
...
</plugin>
</plugins>
</build>
You need to add a phase.
e.g.:
<executions>
<execution>
<id>xml2fastinfoset</id>
<phase>generate-sources</phase>
<goals>
<goal>xml2fastinfoset</goal>
</goals>
</execution>
</executions>
You might find this maven antrun example helpful.