How do I make the Eclipse Checkstyle plugin and the Maven Checkstyle plugin use the same rules? - eclipse

I'd like the Checkstyle rules in Eclipse match the rules when my Maven build runs on Jenkins.
How do I go about that?
Thanks.
[edit]
So I exported the checkstyle settings in eclipse to a new XML file in the project folder and pointed the maven checkstyle plugin at that with
<plugin>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>2.6</version>
<configuration>
<configLocation>checkstyle.xml</configLocation>
</configuration>
</plugin>

You will have to export your eclipse checkstyle settings into a file and configure your Jenkin (/Hudson) checkstyle plugin to use the same configuration file.

I did it as followed: I have a separate maven build project that contains checkstyle/pmd and others stuff (rule sets) on the classpath.
Add this project as dependency in the checkstyle/pmd plugin configuration in your pom, and it will work in maven and in jenkins/hudson if you simple call the maven checkstyle/pmd goal.
Works like a charm.

Related

How to display checkstyle violations generated through maven build in eclipse IDE

I want the check style violations generated through maven build in Eclipse IDE (using external maven) like how your java file get published with checkstyle violations when you do "check code with checkstyle".
I can run my files explicitly with eclipse checkstyle plugins but my project requirement is to run with maven build.
Is there a way to achieve this? I couldn't find any links regarding this issue.
Personally, I do that through Sonar, which is running checkstyle. I installed Sonar locally and added the following profile to my maven project (you could also add it to your personal ~ /.m2/settings.xml):
<profile>
<id>sonar</id>
<activation>
<activeByDefault>false</activeByDefault>
</activation>
<properties>
<sonar.jdbc.url>jdbc:postgresql://localhost:5432/sonar</sonar.jdbc.url>
<sonar.jdbc.driver>org.postgresql.Driver</sonar.jdbc.driver>
<sonar.jdbc.username>sonar</sonar.jdbc.username>
<sonar.jdbc.password>sonar</sonar.jdbc.password>
<sonar.host.url>http://localhost:7080/sonar</sonar.host.url>
</properties>
</profile>
Now, you can run Sonar on your project with:
mvn sonar:sonar -Psonar
In Eclipse, you need to install the Sonar plugin. It allows you to either run a local analysis directly in Eclipse or retrieve the outcome of a remote one. In both cases, violations and problems are added to the Eclipse warnings/message dialog so that you can follow up easily.

Error when importing Maven-GWT project ("No marketplace entries found to handle gwt-maven-plugin")

I'm using Eclipse Indigo on Win XP, Maven 3.0.3 and GWT 2.4. I created a Maven-GWT project using the Mavne gwt archetype. Then I opened Eclipse, went to File -> Import, selected Existing Maven Projects, chose the pom for my GWT-Maven project, and then got this dialog:
The errors are
No marketplace entries found to handle gwt-maven-plugin:2.4.0:generateAsync in Eclipse. Please see Help for more information.
No marketplace entries found to handle gwt-maven-plugin:2.4.0:i18n in Eclipse. Please see Help for more information.
No marketplace entries found to handle maven-war-plugin:2.1.1:exploded in Eclipse. Please see Help for more information.
Anyone know how to resolve these errors? It is wreaking havoc when I actually import my project and try and work with it. - Dave
Make sure you are not using the embedded Maven of Eclipse.
Go to Window->Preference ->Maven -> Installation->choose your own maven installation folder there.
EDIT
If your company pays for IDE, you should ask for IntelliJ the IDE for Java, which I would say is better than Eclipse in many ways, not saying Eclipse is not good, that's just a good alternative. And you won't have this issue to start with
If your pom is not specific as to the version of the maven-resources-plugin, that version will come from the superpom. By default, m2e uses an embedded copy of Maven 3.0.x. If the superpom there points to 2.4.3 and your 'outside-of-Eclipse' version asks for something else, then the Maven inside of Eclipse will go looking for 2.4.3 and fail due to the 'offline'.
Fix by configuring m2e to use the Maven installation you are using outside, or turning off 'offline' for one build.
If you want to use maven from your local installation instead of the embedded version that comes with m2e, You have to do this
Windows ==> Preferences ==> Maven ==> Installations ==> Click Add (select your local maven installation directory)
Installation Directory is not where local repository. It is where maven is installed.
After changing try right click on project then,
Maven ----> Update Project
See How to solve "Plugin execution not covered by lifecycle configuration" for Spring Data Maven Builds
You can basically just copy the snippet from http://code.google.com/p/google-web-toolkit/wiki/WorkingWithMaven#POM_changes_needed_for_Eclipse_Indigo and adapt to your plugins and goals.
I am using a different approach with maven, gwt and eclipse.
I am using the maven eclipse plugin to generate a .classpath and .project file and import the project manually into eclipse (not as a maven project).
My configuration for the maven eclipse plugin looks like this:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-eclipse-plugin</artifactId>
<version>2.8</version>
<configuration>
<downloadSources>true</downloadSources>
<downloadJavadocs>false</downloadJavadocs>
<buildOutputDirectory>${project.build.directory}/${project.build.finalName}/WEB-INF/classes</buildOutputDirectory>
<projectnatures>
<projectnature>org.eclipse.jdt.core.javanature</projectnature>
<projectnature>com.google.gdt.eclipse.core.webAppNature</projectnature>
<nature>com.google.gwt.eclipse.core.gwtNature</nature>
</projectnatures>
<buildcommands>
<buildcommand>org.eclipse.jdt.core.javabuilder</buildcommand>
<buildcommand>com.google.gdt.eclipse.core.webAppProjectValidator</buildcommand>
<buildcommand>com.google.appengine.eclipse.core.projectValidator</buildcommand>
<buildcommand>com.google.gwt.eclipse.core.gwtProjectValidator</buildcommand>
</buildcommands>
<classpathContainers>
<classpathContainer>org.eclipse.jdt.launching.JRE_CONTAINER</classpathContainer>
<classpathContainer>com.google.gwt.eclipse.core.GWT_CONTAINER</classpathContainer>
</classpathContainers>
<excludes>
<exclude>com.google.gwt:gwt-servlet</exclude>
<exclude>com.google.gwt:gwt-user</exclude>
<exclude>com.google.gwt:gwt-dev</exclude>
<exclude>javax.validation:validation-api</exclude>
</excludes>
<linkedResources>
<linkedResource>
<name>war</name>
<type>2</type>
<location>${basedir}/target/${project.artifactId}-${project.version}</location>
</linkedResource>
</linkedResources>
</configuration>
</plugin>
Hope that helps
This helped me:
Delete the project from eclipse (but don't delete from disk)
Close eclipse
In your user folder there is .m folder.
Delete repository folder underneath it (.m/repository).
Open eclipse Import project as existing maven project (from disk).

Eclipse:Run on server option not visible for maven project

I'm running through the jboss as7 getting started guide here http://hudson.jboss.org/jenkins/job/JBoss-AS7-Docs/lastSuccessfulBuild/artifact/guides/developer-getting-started-guide/target/docbook/publish/en-US/html/helloworld.html . The tutorial has us setting up an example helloworld quickstart maven project.
I'm able to deploy this project from the command line successfully
mvn package jboss-as:deploy
but when I attempt to deploy the helloworld example from Eclipse - the 'run on server' option is missing from the run menu. I have Eclipse 3.7 and maven wtp installed.
Not sure how to fix, any advice appreciated.
The run on server related options only appears if your project has the Dynamic Web Moudle project facets.
You can try to configure it using the Project Facets options in your project properties
To help any other developer with this problem.
I was dealing with this issue recently. Maven projects are structured differently than Dynamic Web Projects. So when you manually add the Dynamic Web Module using Project Facets, eclipse may not register it properly as a Maven project.
To solve this, you have to install the m2e plugin and M2E Eclipse WTP plugin (this tells Eclipse how to run your maven projects).
Go to Help -> Eclipse Marketplace to search for the plugins.
After installing, you will need to restart Eclipse then you will be able to use "run on server" for your Maven projects.
Note: You may need to remove/delete the previous project then import/create it again after the restart.
You have to add maven eclipse pluginin your pom.xml file..
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-eclipse-plugin</artifactId>
<version>2.9</version>
</plugin>
According to Red Hat's site, The M2E Eclipse WTP plugin (m2eclipse-wtp) has been deprecated in favor of the newer m2e-wtp plugin. If you don't want to go through the marketplace, the URL for the new plugin is http://download.eclipse.org/technology/m2e/releases.
After copying the project and refreshing it, closing and reopening it, removing and re-adding it (right-click on server) and updating Maven... the option reappeared.
I think it occurs when you up the version of the Java compiler in your .pom file, when you up the compiler in project properties or it has to do with using the newer Jersey (2) version or when you both include local libraries and maven dependencies, it may also be a consequence of a combination of these. It's pretty unclear.
Note though, that you can still add/remove projects by right-clicking on the server in the servers tab.

How to build an Eclipse plugin with maven?

How do you build an Eclipse plugin with Maven? What dependencies or plugins do I need? I am looking to develop for Eclipse 3.7.
You can use Maven 3.3 (at least) and Maven Tycho 0.24.0. Add this to your project's .mvn/extensions.xml:
<extensions>
<extension>
<groupId>org.eclipse.tycho.extras</groupId>
<artifactId>tycho-pomless</artifactId>
<version>0.26.0</version>
</extension>
</extensions>
Then you must define your pom.xml according to the structure of your project.
I recommend this article: Eclipse Tycho for building Eclipse Plug-ins, OSGi bundles and RCP applications - Tutorial
You can follow the example on this page to have a general idea of using maven plugin Tycho.

Generate Web Application Project for Eclipse using Maven.

I'm new to this approach. I've used Maven, Tomcat and Eclipse for my web application. But I'm trying the approach where you create a Maven project using an archetype plugin.
My goal is to create a Web Application Project for Eclipse using Maven that can then be imported into Eclipse. I'm pretty sure there is a super-easy way to do this and I want to know what it is.
I'm using Tomcat 6, Eclipse Helios and Maven 2.
I was referring to this 3-part post:
http://united-coders.com/phillip-steffensen/maven-2-part-1-setting-up-a-simple-apache-maven-2-project
But when I imported the project into Eclipse, I couldn't see the Run As > Run on server option.
What is the best way to go about this? Any links to resources that'd help me understand the approach would be great!
My goal is to create a Web Application Project for eclipse using maven that can then be imported into Eclipse. I'm pretty sure there is a super-easy way to do this and I want to know what it is.
Use the maven archetype plugin to generate your project. Here is how to tell it to use the maven-archetype-webapp when invoking it from the command line:
mvn archetype:generate -DarchetypeArtifactId=maven-archetype-webapp
But when I imported the project into eclipse, I couldn't see the Run As > Run on server option.
It actually all depends on what you use for Eclipse/Maven integration. There are basically two options (and they both provide WTP integration):
the maven-eclipse-plugin which is a Maven plugin that can generate Eclipse files (.project and .classpath and so on) allowing to import the project as Existing projects into Workspace.
the m2eclipse plugin which is an Eclipse Plugin providing Maven integration inside Eclipse and allowing to import a Maven project as Existing Maven projects.
The maven-eclipse-plugin approach
If you use the maven-eclipse-plugin, you have to configure it for WTP support and here is a typical configuration:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-eclipse-plugin</artifactId>
<version>2.8</version>
<configuration>
<projectNameTemplate>[artifactId]-[version]</projectNameTemplate>
<wtpmanifest>true</wtpmanifest>
<wtpapplicationxml>true</wtpapplicationxml>
<wtpversion>2.0</wtpversion>
<manifest>${basedir}/src/main/resources/META-INF/MANIFEST.MF</manifest>
</configuration>
</plugin>
With this configuration, running mvn eclipse:eclipse on your maven project will generate the WTP files so that the project can be recognized as a Dynamic project (i.e. runnable on a Server). Then import it via Import... > Existing projects into Workspace.
The m2eclipse approach
If you use the m2eclipse plugin (and that would be my recommendation), make sure to install the Maven Integration for WTP from the extras. From the install instructions:
Installing m2eclipse Extras
To install optional m2eclipse
components, you will need to use the
m2eclipse Extras update site. This
update site contains the following
m2eclipse components:
Maven SCM Integration
Maven SCM handler for Team/CVS
Maven SCM handler for Subclipse
Maven issue tracking configurator for Mylyn 3.x
Maven Integration for WTP
M2Eclipse Extensions Development Support
m2eclipse Extras Update Site: http://m2eclipse.sonatype.org/sites/m2e-extras
And then just import your project via Import... > Existing Maven projects and if it's a webapp, it should get recognized as a Dynamic project.
Indigo: m2eclipse approach for Indigo is different. See Maven/Tomcat Projects In Eclipse Indigo/3.7
Important: Note that both approaches are exclusive, use one or the other. But in both cases, there is no need to add a facet manually if you use them correctly.
Download and install the eclipse maven plugin from here. Create your project using the new project wizard in eclipse. Select Maven project and create the project using the archetype you discussed. Set appropriate source folders and add libraries used as part of project properties. This should set you up for your project.
Very simple,
you only have to create a new Maven project with packaging type ‘war’ and directories creation done automatically