Eclipse automatically run maven goals - eclipse

In my Eclipse/Maven project, how can I call the buildHelper goals add-test-source, add-test-resource and add-resource?
This is my approach:
pom.xml:
<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>build-helper-maven-plugin</artifactId>
<versionRange>[1.0.0,)</versionRange>
<goals>
<goal>add-test-source</goal>
<goal>add-test-resource</goal>
<goal>add-resource</goal>
</goals>
</pluginExecutionFilter>
<pluginExecutionFilter>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compile-plugin</artifactId>
<versionRange>[1.0.0,)</versionRange>
<goals>
<goal>compile</goal>
<goal>test-compile</goal>
</goals>
</pluginExecutionFilter>
<action>
<execute>
<runOnIncremental>true</runOnIncremental>
</execute>
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
</plugins>
</pluginManagement>
lifecycle-mapping-metadata.xml (from Eclipse config):
<?xml version="1.0" encoding="UTF-8"?>
<lifecycleMappingMetadata>
<pluginExecutions>
</pluginExecutions>
</lifecycleMappingMetadata>
To test, I put an empty file into a test resources directory, change a source file, save and check if the empty file is in the corresponding target/ directory afterwards. It isn't.
When I manually run compile test-compile, the test file is getting copied.

Related

How do you generate resources for inclusion in src/main/resources without that triggering a subsequent build in eclipse

I'm trying to achieve the following in Eclipse:
When a source file changes, run an custom class that's included as part of the project dependencies, this class generates a file which needs to be placed into src/main/resources (such that it will get checked into source control by any developer working on the project). I'd even settle for /generated rather than src/main/resources.
I have the following, which seems to do the right thing, however even though the generated file is being placed into /generated, it triggers a further eclipse build, so essentially a circular loop of builds.
The following triggers m2e into action:
<pluginManagement>
<plugins>
<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>exec-maven-plugin</artifactId>
<versionRange>[1,)</versionRange>
<goals>
<goal>java</goal>
</goals>
</pluginExecutionFilter>
<action>
<execute>
<runOnConfiguration>false</runOnConfiguration>
<runOnIncremental>true</runOnIncremental>
</execute>
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
</plugins>
</pluginManagement>
The following triggers the custom class:
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.6.0</version>
<executions>
<execution>
<id>SchemaGenerator</id>
<phase>generate-sources</phase>
<goals>
<goal>java</goal>
</goals>
<configuration>
<mainClass>jit.SchemaGenerator</mainClass>
<arguments>
<argument>${project.basedir}/generated</argument>
<argument>schema.xml</argument>
</arguments>
</configuration>
</execution>
</executions>
</plugin>
</plugins>

No marketplace entries found to handle yeoman-maven-plugin

I have recently installed and created an application with JHipster. When i run the app in terminal with "mvn spring-boot:run", the app runs without problem.
But when i import the project (as a maven project) into Eclipse, i have this error in my pom:
No marketplace entries found to handle yeoman-maven-plugin:0.4:build
in Eclipse. Please see Help for more information.
Here is a screenshot of the error.
This is how this plugin is defined in the generated pom.xml by default:
<build>
<plugins>
<plugin>
<groupId>com.github.trecloux</groupId>
<artifactId>yeoman-maven-plugin</artifactId>
<version>0.4</version>
<executions>
<execution>
<id>run-grunt</id>
<phase>generate-resources</phase>
<goals>
<goal>build</goal>
</goals>
<configuration>
<skipTests>true</skipTests>
<buildTool>grunt</buildTool>
<buildArgs>compass:server --force</buildArgs>
</configuration>
</execution>
</executions>
<configuration>
<yeomanProjectDirectory>${project.basedir}</yeomanProjectDirectory>
</configuration>
</plugin>
</plugins>
</build>
How can i continue to manipulate, edit the generated project files in my Eclipse?
Eclipse lifecycle-mapping issue is described here:
http://www.eclipse.org/m2e/documentation/m2e-execution-not-covered.html
There is not m2e connector for yeoman-maven-plugin
Recommended way to deal with this issue it to ignore executing this plugin by m2e:
<build>
<plugins>
<pluginManagement>
<plugin>
<groupId>org.eclipse.m2e</groupId>
<artifactId>lifecycle-mapping</artifactId>
<version>1.0.0</version>
<configuration>
<lifecycleMappingMetadata>
<pluginExecutions>
<pluginExecution>
<pluginExecutionFilter>
<groupId>
com.github.trecloux
</groupId>
<artifactId>
yeoman-maven-plugin
</artifactId>
<versionRange>
[0.4,)
</versionRange>
<goals>
<goal>build</goal>
</goals>
</pluginExecutionFilter>
<action>
<ignore></ignore>
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
Note that executing maven from Eclipse is not affected.
As Mateusz Balbus said you have to modify the pom.xml, but with a small difference as we can find here :
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.eclipse.m2e</groupId>
<artifactId>lifecycle-mapping</artifactId>
<version>1.0.0</version>
<configuration>
<lifecycleMappingMetadata>
<pluginExecutions>
<pluginExecution>
<pluginExecutionFilter>
<groupId>
com.github.trecloux
</groupId>
<artifactId>
yeoman-maven-plugin
</artifactId>
<versionRange>
[0.4,)
</versionRange>
<goals>
<goal>build</goal>
</goals>
</pluginExecutionFilter>
<action>
<ignore></ignore>
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>

Run maven gwt application in hosted mode

I have created gwt maven project and I want run it so from command line I am providing:
mvn compile gwt:run -DrunTarget=com.engile.Engile/Engile.html
But In logs it shows:
ava.lang.IncompatibleClassChangeError: Implementing class
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(ClassLoader.java:631)
at java.lang.ClassLoader.defineClass(ClassLoader.java:615)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
at org.apache.catalina.loader.WebappClassLoader.findClassInternal(WebappClassLoader.java:1847)
at org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.java:890)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1354)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1233)
at com.appops.server.data.hibernate.SessionProvider.createSessionFactory(SessionProvider.java:46)
at com.appops.server.data.hibernate.HibernateDataSourceConnector.init(HibernateDataSourceConnector.java:39)
at com.engile.server.services.ConfigurationServlet.init(ConfigurationServlet.java:45)
at com.google.inject.servlet.ServletDefinition.init(ServletDefinition.java:117)
at com.google.inject.servlet.ManagedServletPipeline.init(ManagedServletPipeline.java:82)
at com.google.inject.servlet.ManagedFilterPipeline.initPipeline(ManagedFilterPipeline.java:102)
at com.google.inject.servlet.GuiceFilter.init(GuiceFilter.java:172)
at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:275)
at org.apache.catalina.core.ApplicationFilterConfig.setFilterDef(ApplicationFilterConfig.java:397)
at org.apache.catalina.core.ApplicationFilterConfig.<init>(ApplicationFilterConfig.java:108)
at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:3709)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4363)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:791)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:771)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:525)
and pom.xml includes:
<properties>
<!-- Convenience property to set the GWT version -->
<gwtVersion>2.4.0</gwtVersion>
<!-- GWT needs at least java 1.5 -->
<webappDirectory>${project.build.directory}/${project.build.finalName}</webappDirectory>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<plugins>
<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>gwt-maven-plugin</artifactId>
<!-- <versionRange>[2.5.0,)</versionRange> -->
<version>${gwtVersion}</version>
<goals>
<goal>resources</goal>
<goal>compile</goal>
<goal>i18n</goal>
<goal>generateAsync</goal>
</goals>
<configuration>
<runTarget>Engile.html</runTarget>
<hostedWebapp>${project.build.directory}/${project.build.finalName} </hostedWebapp>
<modules>
<module>com.engile.Engile</module>
</modules>
<!-- <runTarget>com.engile.Engile/Engile.html</runTarget> -->
</configuration>
</pluginExecutionFilter>
<action>
<execute />
</action>
</pluginExecution>
<pluginExecution>
<pluginExecutionFilter>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<versionRange>[2.1.1,)</versionRange>
<goals>
<goal>exploded</goal>
</goals>
</pluginExecutionFilter>
<action>
<execute />
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.5.1</version>
<configuration>
<webappDirectory>${webappDirectory}</webappDirectory>
</configuration>
</plugin>
</plugins>
</build>
In build path in source section I am providing outputfolder of src/main/java is target/classes and default output folder is:
engilev2_with_mavenold/src/main/webapp/WEB-INF/classes
is anything is wrong, I don't understand the webapp/classes folder and target/classes folder where java classes are compiled to ?
You have not configured gwt-maven-plugin in your build tag. You are only configuring maven-compiler-plugin and lifecycle-mapping plugin. The gwt-maven-plugin under lifecycle-plugin is only to inform eclipse to avoid invoking gwt compilation in refresh cycles,
You have the same issue in the other stackoverflow question too -
The parameters 'runTarget' for goal org.codehaus.mojo:gwt-maven-plugin:2.5.0:run are missing or invalid
Add another plugin tag in your pom.xml under buil tag after maven-compiler-plugin
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>gwt-maven-plugin</artifactId>
<!-- <versionRange>[2.5.0,)</versionRange> -->
<version>${gwtVersion}</version>
<goals>
<goal>resources</goal>
<goal>compile</goal>
<goal>i18n</goal>
<goal>generateAsync</goal>
</goals>
<configuration>
<runTarget>Engile.html</runTarget>
<hostedWebapp>${project.build.directory}/${project.build.finalName} </hostedWebapp>
<modules>
<module>com.engile.Engile</module>
</modules>
<!-- <runTarget>com.engile.Engile/Engile.html</runTarget> -->
</configuration>
</plugin>

The output directory for the project should be set to /gwtproject/src/main/webapp/WEB-INF/classes

I have created a GWT Maven project in Eclipse using New->Project->Maven project->GWT Eclipse plugin. It was created, but it gives some errors like
The output directory for the project should be set to /gwtproject/src/main/webapp/WEB-INF/classes
Is anything missing while configuring my project?
My pom.xml includes:
<build>
<!-- Generate compiled stuff in the folder used for developing mode -->
<outputDirectory>${webappDirectory}/WEB-INF/classes</outputDirectory>
<plugins>
<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>gwt-maven-plugin</artifactId>
<versionRange>[2.4.0,)</versionRange>
<goals>
<goal>resources</goal>
<goal>compile</goal>
<goal>i18n</goal>
<goal>generateAsync</goal>
</goals>
</pluginExecutionFilter>
<action>
<execute />
</action>
</pluginExecution>
<pluginExecution>
<pluginExecutionFilter>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<versionRange>[2.1.1,)</versionRange>
<goals>
<goal>exploded</goal>
</goals>
</pluginExecutionFilter>
<action>
<execute />
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.5</source>
<target>1.5</target>
</configuration>
</plugin>
</plugins>
</build>
An eclipsy solution to this problem is:
Select the project in the Package Explorer.
Open the properties of the project.
Select Java Build Path
Change the default output folder
Question the life decisions you made that landed you in Eclipse.
You should do a pre-check with GWT Article WorkingWithMaven - http://code.google.com/p/google-web-toolkit/wiki/WorkingWithMaven
Also refer GWT Sample project Validation, DynaTableRf and MobileWebApp.
You need to configure the missing part in <webappDirectory> tag in the pom. I think this should solve your problem: Click Here

adding src/main/aspect as a source folder to an eclipse maven project

I would like to be able to configure the pom.xml so that when I import it into eclipse it specifies src/main/aspect as an eclipse source folder.
At the moment, importing creates the default source folders but that is all.
What should be done?
Thanks
edit 1
I have configured the aspectj plugin thus:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<version>1.4</version>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>test-compile</goal>
</goals>
<configuration>
<source>${project.build.source}</source>
<target>${project.build.target}</target>
<aspectDirectory>src/main/aspect</aspectDirectory>
<testAspectDirectory>src/test/aspect</testAspectDirectory>
</configuration>
</execution>
</executions>
</plugin>
edit 2
I have configured the m2e plugin thus:
<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>
aspectj-maven-plugin
</artifactId>
<versionRange>
[1.4,)
</versionRange>
<goals>
<goal>test-compile</goal>
<goal>compile</goal>
</goals>
</pluginExecutionFilter>
<action>
<ignore></ignore>
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
You shouldn't configure the defaults of the plugin, cause it defines already the src/test/aspect and src/main/aspect and it shouldn't be necessary to configuration something supplemental to compile etc.
Furthermore the problem with eclipse could be based on a missing mapping for your m2e plugin this means to add the following to your build:
<pluginManagement>
<plugins>
<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>aspectj-maven-plugin</artifactId>
<versionRange>[1.4,)</versionRange>
<goals>
<goal>compile</goal>
<goal>test-compile</goal>
</goals>
</pluginExecutionFilter>
<action>
<execute />
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
</plugins>
</pluginManagement>
This might cause you problem in Eclipse not to see the source folder correctly imported.
I believe source is supposed to be a java version, not a directory. Same for target. sources allows you to specify the source directories, and the docs say that if not specified, the java sources of the current project will be used - just one for your project as configured currently.
I would try listing the directories in the sources parameter, and if that didn't work, I'd remove sources and try build-helper:add-source. I'm not sure there's an m2e connector for build-helper-maven-plugin yet so you might have to add a similar mapping to the one khmarbaise mentioned.
I think it would not be added as source folder by Eclipse. you could add it on your own in Java Build Path > Source.
This is not necessary: Then you need to have AJDT plugin installed in and convert the project to AspectJ Project, otherwise the .ajfiles will be full of errors complained by Eclipse. The errors does not affect maven compiling.
In my experience, recognized or not as source would not affect maven compiling the .aj files under src/main/aspect
Both aspectDirectory and aspectTestDirectory have default values as you given. they are not needed if the same as default.
Here below is my pom configuration (didn't try test-compile) and it works:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<version>1.4</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
<!--<Xlint>ignore</Xlint>--><!--bypass xlint warnings -->
</configuration>
<dependencies>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjtools</artifactId>
<version>1.7.2</version>
</dependency>
</dependencies>
<executions>
<execution>
<goals>
<goal>compile</goal>
</goals>
</execution>
</executions>
</plugin>