Eclipse Juno and install Maven surefire plugin - eclipse

I'm learning Maven, and I have a sample project with a simple pom.
I want too add the surefire plugin so I may run junit tests.
I'm assuming that I can somehow add the plugin using Eclipse, or do I need to use the command line?

It seems the answer provided by #Ajay George is best, but if you're missing the pretty JUnit GUI with the red and green bars, refer to this comment by #thSoft:
You can view Surefire's test reports in Eclipse's JUnit view if you
open the XML files in target/surefire-reports.

Install m2eclipse which contains the surefire plugin.
The screenshot give below contains the "Run As" -> "Maven Test" option which will invoke the surefire plugin.

Related

Where maven is installed (eclipse plugin)

I have M2Eclipse plugin installed on my eclipse, and now I am reading a book that says to use the mvn command, I think that I could use eclipse IDE to follow the book, but I want to know a little more about maven. Of course, the command "mvn" is not recognized, I need to edit my PATH variable.
I googled where is maven installed, and the answer is that it is an apache tool and the path is where you want to unzip the package.
BUT, what if I donĀ“t want to install the apache project?? Is there any other option, because how I say at the beginning, I have M2Eclipse plugin installed, so I image that the executable file must to be in some folder into the plugin eclipse path... or does it use only java jar libraries without a binary??
Thank you very much.
M2E is a plugin in Eclipse and not Maven. You are using an embedded Maven version which is part of Ecilpse. You should always install Maven to be useable via command line cause there are difference between M2E/Eclipse and command line.
You can run any mvn goal by clicking on a maven project, than right click and select Run As -> Maven Build... and type any goal you want.

How to combine mvn clean and mvn install into a single task?

I'm following the Scala, Eclipse and Maven Integration tutorial.
It is really useful.
But there is one thing that seems annoying to me:
I always need to run two commands from the Eclipse Run as menu:
Maven clean
Maven install
Is there any way to configure Scala and Maven plugins for Eclipse, to make it possible to run both tasks as a single command from the Eclipse menu?
For example:
Maven clean install
like in the following Eclipse non-Scala configuration.
Choose the option Maven build..., and type clean install in the Goals text box.

Indigo Maven Project Builder

In Eclipse it is possible to configure builders for a project. I am using m2e and Eclipse indigo for a dynamic web project. I am trying to figure out exactly what happens when I invoke Build for the project from eclipse and so be able to understand the difference between this and a just doing a maven build from the command line. I go to project / builders and see there are five builders: JavaScript Validator, Java Builder, Faceted Project Validation Builder, Maven Prokect Builer and Validation. It would be interesting to see what goals the Maven Project Builder will do but I can't see this from this screen. Edit is disabled. I try Project Properties / Maven and there is nothing to do with Goals there. Even though this http://maven.40175.n5.nabble.com/Preventing-Maven-project-builder-from-being-run-td137622.html suggests there should be.
I am wondering is there any way to see and configure what goals Eclipse will call?
Many thanks.
Strange as it sounds, m2e does not really invoke Maven to do the build.
Its job is to parse POM file and delegate the job of doing everything that it finds there to Eclipse.
It does so by mapping maven plugins to special m2e Eclipse plugins.
Sometimes, when no mapping exists you get a warning and you have a choice of either disabling this part of your build or running the maven plugin in I guess default wrapper provided by m2e. In either case the result is not as good as when a maven-to-eclipse plugin mapping exists

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.

maven adds dependency but eclipse does not see it

I've created a new project in maven like this:
mvn archetype:generate -DgroupId=com.mycompany.app -DartifactId=my-app -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false
After that I use: mvn eclipse:eclipse
The problem is that when I add the project to my IDE, eclipse indicates errors. When I run it I get classNotFound for JUnit. In project properties I see that junit is added to build path
In project properties I see: M2_REPO/junit/junit/3.8.1/junit-3.8.1.jar
But I cant use for example: import junit.framework.Test;
Why is that? To be honest, I have some major problems with dependency in maven and eclipse. Maven adds them correctly but eclipse doesn't see it correctly. It's not only the junit. What should I check/set?
Should I install some plugin to eclipse for maven support ?
EDIT
I thought again about everything. Of course the problem was small. M2_REPO was not recognize by Eclipse. I've added this variable and set it in od maven directory. It worked like a charm.
You can use the m2eclipse plugin for eclipse
http://m2eclipse.sonatype.org/installing-m2eclipse.html
I don't know if having the plugin would solve your problem, I used to do the command line before I started using m2elcipse, I never had the issue that you described
what version of eclipse are you using?