How to set eclipse project specific validation preferences with m2e - eclipse

When invoking importing maven projects into eclipse from git using "Import Maven Projects" the m2e plugins to seems to generate a new .project and .classpath and some other files even though those files are checked in.
To get around this problem I would like to not check in any eclipse specific files, but there are customizations made to each project file such as custom save actions, or changes to the validation to ignore specific things, or changes to the javascript configuration for a dynamic web project that need to be preserved, so either those files need to checked or those settings need to be generated by m2e.
Any way to use m2e to configure the eclipse project validators?

We had a similar problem in the past. We solved it by
don't checkin eclipse specific files (svn ignore, git ignore, ...)
Use Workspace Mechanic plugin to keep eclipse settings the same accross development machines / developers.

The other answer has suggested the solution with eclipse. But if you are flexible with using a different IDE, I suggest using Netbeans with git. I tested both IDEs and finally found out I could save time in different cases using Netbeans! No such problems as mentioned above.

I made m2e-codestyle-maven-plugin for another purpose but it should serve what you need as well (in my case I wanted to set the default settings to have all validations turned on from my coding-standards project.
The key thing you have to do is fork a copy of my coding-standards project and add/change the appropriate setting in org.eclipse.wst.validation.prefs namely
vals/org.eclipse.wst.xml.core.xml/global=FF03
To disable the validations for XML for example. You can have it activated only on m2e by using profiles as shown here
https://github.com/trajano/jee/blob/master/jee-domain-api/pom.xml#L24
<profile>
<id>m2e</id>
<activation>
<property>
<name>m2e.version</name>
</property>
</activation>
<build>
<plugins>
<plugin>
<groupId>net.trajano.mojo</groupId>
<artifactId>m2e-codestyle-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>configure</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>net.trajano</groupId>
<artifactId>coding-standards</artifactId>
<version>${coding-standards.version}</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
</profile>

Related

Maven Incremental Compilation under Eclipse

I've recently converted a big (and ugly) legacy project to Maven. It is a really really huge project (~2.7M lines of code, and a nice mix of java, jsp, js, and even VBS scripts) and is not well structured. Everything is located under a single Maven artifact (and thus a single Eclipse project).
Even with that bad structure, it used to be less or more manageable from Eclipse (even if a bit slow), but now, since it is Mavenized, every single change made to source code triggers an almost full rebuild of the code base (and 2.7M LoC take something like 10 minutes to finish), which is really unusable on a daily basis.
I've found the following bug report related to maven-compiler-plugin, unable to have an incremental compilation: https://issues.apache.org/jira/browse/MCOMPILER-205, and I'm quite confident that this is the root of our performance issues.
Have you any workaround? Do you know of a maven-compiler-plugin version not impacted with that issue? Or a setting in Eclipse which could help? Any other idea?
Thanks
The incremental compiler in Eclipse (ecj, used by the JDT) totally overrides the compiler used by command line Maven builds. Any maven-compiler-plugin or javac issue should be discarded as irrelevant. I would expect m2e/Maven to have no significant impact on a single project workspace, as big as it is. Obviously since you're seeing the opposite behavior, something is apparently slowing down the Maven builder.
Since you use jsp and js files, my guess this is a war project. If you're using the Eclipse Java EE distribution, one thing you can try is to disable the m2e-wtp integration, see if it makes any difference. Go to Preferences > Maven > Java EE Integration and uncheck Enable Java EE Configuration.
If that doesn't help (or doesn't apply to your set up), another thing you could try would be to disable Maven resource processing during incremental builds. In your pom.xml, try adding:
<profiles>
<profile>
<id>m2e</id>
<!-- This profile is only activated when building in Eclipse with m2e -->
<activation>
<property>
<name>m2e.version</name>
</property>
</activation>
<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.apache.maven.plugins
</groupId>
<artifactId>
maven-resources-plugin
</artifactId>
<versionRange>
[1.0,)
</versionRange>
<goals>
<goal>resources</goal>
<goal>testResources</goal>
</goals>
</pluginExecutionFilter>
<action>
<ignore></ignore>
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</profile>
</profiles>
There's a chance it might break something else, but at least that should help determine whether resource processing is the culprit here.
Anything else will require a deeper analysis, I suggest you open a ticket to https://bugs.eclipse.org/bugs/enter_bug.cgi?product=M2E
Disable automatic build is the only option you have. Just build when you are interested in the artifacts.
You did not say what goals you are calling maven with. Maybe it would already be enough if you do not run all tests using -DskipTests (or even not compile them by using -Dmaven.test.skip=true), or if not willing to skip those introduce profiles to run just the necessary tests.
Since you are telling it's a legacy project I suspect that changing the project structure into a multi-module maven project is out of scope. You can then try if you can speed up using parallel builds (using -T 4 (4 threads) or -T 2C (2 threads per core).

How to automatically generate lexer+parser with ANTLR4 and Maven?

I'am new to ANTLR4, and it seems that there is no Eclipse-Plug-In for v4. So it would nice to build automatically the Java sources from the .g4 grammars. I have a simple, empty Maven-project with src/main/java, src/test/java. Where to place the .g4 files? How can I automatically build the grammars with Maven?
My own POM-test failed:
<repository>
<id>mvn-public</id>
<name>MVNRepository</name>
<url>http://mvnrepository.com</url>
</repository>
...
<build>
<plugins>
<plugin>
<groupId>org.antlr</groupId>
<artifactId>antlr4-maven-plugin</artifactId>
<version>4.0.0</version>
<executions>
<execution>
<goals>
<goal>antlr</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
Eclipse says:
Failure to find org.antlr:antlr4-maven-plugin:pom:4.0.0 in http://repo.maven.apache.org/maven2 was cached in the local repository, resolution will not be reattempted until the update interval of
central has elapsed or updates are forced
I created the following Gist with a pom.xml designed solely for supporting automatic code generation from ANTLR 4 grammars during an Eclipse build. It includes the necessary lifecycle information for m2e to know that the code generation is necessary, and explicitly adds the code generation folder using the build-helper-maven-plugin since Eclipse seemed to have some trouble locating it otherwise.
In this configuration, grammar files (*.g4) are placed alongside the other Java source files. The Maven plugin will automatically add the proper package ... statement to the generated files, so you shouldn't include a #header{package ...} line in the grammar itself.
https://gist.github.com/sharwell/4979017
Check out this Antlr4 plugin for Eclipse
https://github.com/jknack/antlr4ide

Eclipse javadoc: The type package-info is already defined

OS: Windows 7 x64
Eclipse Platform: 3.7.2.M20120208
m2e: 1.0.200.20111228-1245
Have similar problem as in this bug.
There is a bunch of package-info.java files in /src and /test folders, so they have same package. Eclipse show error:
"The type **package-info** is already defined"
I can delete package-info.java files either in /test or /src to avoid problem indication. But this workaround is not very comfort since I am using SCM and need to delete this files all time after update.
Same for Eclipse Platform 4.2.0.I20120608-1400
You can do this -->
Go to Build path -> configure build path -->
in Source tab -->
select the package (in which you have these problematic package-info.java file)
for eg. project-name/src/test/java
click on exclude -> and in exclusion pattern add "**/package-info.java"
this should solve the problem, as plainly you are asking eclipse to exclude these files, and thus you wouldn't have to delete those files and solving your SCM related issues
There are a few options to solve this:
Move away from package-info.java files, and replace them with package.html files.
Only have package-info.java files in the src/ tree, as the same-named packages in the test/ tree will "overlap" the src/ tree.
Generate javadoc separately for the src/ and test/ trees, as they are probably for different audiences.
If you use maven and m2e for interaction between eclipse and maven. There is a quite clean solution: add a profile to pom.xml that is activated only by m2e and prevents compilation of package-info.java in the test-compile phase. Here a sample :
<profile>
<id>m2e</id><!--This profile is activated when eclipse interacts with maven (using m2e).-->
<activation>
<property>
<name>m2e.version</name>
</property>
</activation>
<build>
<plugins>
<plugin>
<!--eclipse do not support duplicated package-info.java, in both src and test.-->
<artifactId>maven-compiler-plugin</artifactId>
<executions>
<execution>
<id>default-testCompile</id>
<phase>test-compile</phase>
<configuration>
<testExcludes>
<exclude>**/package-info.java</exclude>
</testExcludes>
</configuration>
<goals>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>

Question Regarding External Jars and MAVEN

I have two GWT projects Project A and Project B.The dependencies of these projects are taken care by MAVEN.Project B depends on Project A ,and this part is already taken care of.
Now i need to add an external Jar into Project A.I do not want to use Maven for this .I just want to add the external jar file into Project A and update my ProjectA.gwt.xml to inherit the jar.
So i included the jar file in Project A.But Project B was not recognizing the classes in the jar.So i went ahead and followed the following steps
1) Right Clicked on Project A and selected Build Path
2) Click on Configure Build Path
3) Order and Export the jar file
Then after doing so ,my Project B could compile the classes used from the JAR file.But at Runtime its crashing.Its not able to recognize the classes from the JAR file.
Can anyone provide me what to do on this?
Please provide me solution with/without using MAVEN.I would prefer without using MAVEN.
Thanks
I think you should keep all the dependency management in Maven.
The Eclipse Maven plugin manage the Build Path Configuration of your Eclipse project, it should be not modified manually.
You could use this configuration to add external librairies to the repository :
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<version>2.3</version>
<executions>
<execution>
<id>deploy-on-local-repo1</id>
<phase>generate-sources</phase>
<goals>
<goal>install-file</goal>
</goals>
<inherited>false</inherited>
<configuration>
<file>src/your-librairie.jar</file>
<groupId>com.yourlibrairiegroupID</groupId>
<artifactId>librairie-name</artifactId>
<version>1.0</version>
<packaging>jar</packaging>
<generatePom>true</generatePom>
</configuration>
</execution>
</executions>
</plugin>
Hope it will fix your problem.

GWT/Eclipse/Jetty issue: Jasper can't resolve tag libraries

I'm trying to get GWT Hosted mode working in Eclipse, à la this HOWTO. Servlets work fine, as does my GWT code, but all my JSPs fail because with errors such as the following:
[WARN] /view/lniExecutiveSummary.htm
org.apache.jasper.JasperException: /WEB-INF/jsp/lni/lniExecutiveSummary.jsp(1,1) The absolute uri: http://java.sun.com/jsp/jstl/fmt cannot be resolved in either web.xml or the jar files deployed with this application
at org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:39)
at org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:409)
[ trimmed ]
This webapp works fine when deployed under Tomcat 5x; I just can't seem to get it to resolve the taglibs when running in Eclipse.
I'm new to Eclipse, and getting it working with all the moving parts required for GWT+Maven has me pulling my hair out.
Update: I'm no longer using Eclipse; I've switched (back!) to Intellij IDEA. So I can't honestly evaluate the answers you kind folks have posted. Once some voting action happens, or someone else reports success with one of these methods, I'll accept the appropriate answer. Thanks.
I feel your pain. I've gone thru the same pain trying to get gwt, maven, and eclipse to work together.
I've been able to get it working with maven using the following pom.xml. This way you can use mvn gwt:run to run in hosted mode, but unfortunately, I could never get the mvn goal mvn gwt:eclipse for generating an eclipse launch run time config to work.
Here's the relevant snippets from my pom.xml. Note that I've found it easier to install gwt in separate location and point maven to use that instead of having mvn download gwt from repo. The "system" level scope in the mvn dependencies are what make this happen.
<properties>
<!-- convenience to define GWT version in one place -->
<gwt.version>1.7.1</gwt.version>
<google.webtoolkit.home>${env.GWT_HOME}</google.webtoolkit.home>
<!-- tell the compiler we can use 1.5 -->
<maven.compiler.source>1.6</maven.compiler.source>
<maven.compiler.target>1.6</maven.compiler.target>
</properties>
<dependencies>
<!-- GWT dependencies (from central repo) -->
<dependency>
<groupId>com.google.gwt</groupId>
<artifactId>gwt-servlet</artifactId>
<version>${gwt.version}</version>
<scope>system</scope>
<systemPath>${env.GWT_HOME}/gwt-servlet.jar</systemPath>
</dependency>
<dependency>
<groupId>com.google.gwt</groupId>
<artifactId>gwt-user</artifactId>
<version>${gwt.version}</version>
<scope>system</scope>
<systemPath>${env.GWT_HOME}/gwt-user.jar</systemPath>
</dependency>
... other dependencies...
</dependencies>
<build>
<outputDirectory>war/WEB-INF/classes</outputDirectory>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>gwt-maven-plugin</artifactId>
<version>1.1</version>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>generateAsync</goal>
<goal>test</goal>
</goals>
</execution>
</executions>
<configuration>
<runTarget>com.gwt.example/Application.html</runTarget>
<extraJvmArgs>-Xmx512m</extraJvmArgs>
</configuration>
</plugin>
<!--
If you want to use the target/web.xml file mergewebxml produces,
tell the war plugin to use it.
Also, exclude what you want from the final artifact here.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<webXml>target/web.xml</webXml>
<warSourceExcludes>.gwt-tmp/**</warSourceExcludes>
</configuration>
</plugin>
-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.0.2</version>
<configuration>
<source>${maven.compiler.source}</source>
<target>${maven.compiler.target}</target>
<module>com.gwt.example</module>
</configuration>
</plugin>
</plugins>
...rest of pom.xml...
Another technique I've had success with is to use the eclipse google gwt plugin. Just use the wizard to create a new gwt project, make sure that you can run it from eclipse, then modify with your own code.
This webapp works fine when deployed under Tomcat 5x; I just can't seem to get it to resolve the taglibs when running in Eclipse. I'm new to Eclipse, and getting it working with all the moving parts required for GWT+Maven has me pulling my hair out.
You apparently have the JSTL JAR file(s) in Tomcat/lib instead of WEB-INF/lib. You can fix this in at least three ways:
Move/copy the JSTL JAR file(s) into WEB-INF/lib.
Move/copy the JSTL JAR file(s) into Tomcat/lib of your development machine.
Associate the right Tomcat server containing the JSTL JAR file(s) with web project in Eclipse. If not done yet, add the Tomcat server in Servers view. Then in project properties go to Java Build Path > Libraries > Add Library > Server Runtime > select the server in question.
Add the Jar files in eclipse project classpath. if you already had this file tomcat lib. This option will works for you. Second option is add jar in Web-Inf lib folder if you have eclipse web project.
Did you try to mark the "jsf-api.jar" as "exported" in your Java project ?
(as mentioned in this thread)
1.) Go into the java-project properties and mark the "jsf-api.jar" as exported.
(project>properties>java build path>order and exports)
2.) Go into the advanced global tomcat preferences and add your project to
the tomcat classpath (windows>preferences>tomcat>advanced>add projects to
tomcat classpath)
Then, try again to run your webapp under eclipse.
Here is an article describing the same procedure/setup, not for JSF but Hudson (same problem though)
You can clearly see the two steps I mentioned above:
(source: hudson-ci.org)
(source: hudson-ci.org)