Run Tomcat with Maven and Eclipse - Unknown lifecycle phase - eclipse

I am using Eclipse Helios,Tomcat Server 7. I have build my project using Maven. When I try to build my project, I get the below error in Eclipse.
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building encore Maven Webapp 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.095s
[INFO] Finished at: Tue Nov 06 18:17:55 IST 2012
[INFO] Final Memory: 2M/36M
[INFO] ------------------------------------------------------------------------
[ERROR] Unknown lifecycle phase "build". You must specify a valid lifecycle phase or a goal in the format <plugin-prefix>:<goal> or <plugin-group-id>:<plugin-artifact-id>[:<plugin-version>]:<goal>. Available lifecycle phases are: validate, initialize, generate-sources, process-sources, generate-resources, process-resources, compile, process-classes, generate-test-sources, process-test-sources, generate-test-resources, process-test-resources, test-compile, process-test-classes, test, prepare-package, package, pre-integration-test, integration-test, post-integration-test, verify, install, deploy, pre-clean, clean, post-clean, pre-site, site, post-site, site-deploy. -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/LifecyclePhaseNotFoundException
Please let me know what is wrong in my code and kindly point to right directions. I need to figure it out ASAP.
<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.encore</groupId>
<artifactId>encore</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>encore Maven Webapp</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.codehaus.mojo</groupId>
<artifactId>tomcat-maven-plugin</artifactId>
<version>1.1</version>
</dependency>
<dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-eclipse-plugin</artifactId>
<version>2.9</version>
</dependency>
</dependencies>
<build>
<finalName>encore</finalName>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>tomcat-maven-plugin</artifactId>
<version>2.9</version>
<configuration>
<server>mytomcatserver</server>
<path>/encore</path>
<url>http://localhost:8080</url>
<username>admin</username>
<password>admin</password>
</configuration>
</plugin>
</plugins>
</build>
</project>
This is my pom.xml. I am trying to Run my application as Run as-> mvn build from eclipse.

It sounds like you've accidentally set the wrong goal when trying to build from Eclipse. Edit your Maven "Run as.." settings like so:
Note the clean install which will run the Maven commands to clean your build and do a full build and install into the local repository.

Try mvn install instead of mvn build. build is not a valid option for Maven. You can find a list of valid options in the error message above.
If you just want to compile the sources, try mvn compile but that will usually produce an incorrect result when you have more than one pom.xml file in your project.

You should build : install , not build : mvn install ,not start with mvn ...

All ides ( Eclipse, Intellij etc.) have some problems with maven build, instead of using bundled maven component, use command-line maven.
In command line ( windows or linux console does not matter.) mvn clean, then mvn install will fix your problem. Command line usage can be change your view point of maven.

It is most probable you set incorrect goals in the configuration when you ran "run as" "Maven build" and now can't change it.
Right click on the project -> run as -> Run configurations.
A picture to illustrate: https://i.stack.imgur.com/Ry65K.png
This will bring back up the window you first had on your first build and you can then follow the instructions of the more experienced contributors above.
Hope this helps.

Error: org.apache.maven.lifecycle.LifecyclePhaseNotFoundException
For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/LifecyclePhaseNotFoundException
Solution : Unknown lifecycle phase or wrong goal example:First I am using "clean package tea-container-test:tomcat-test -P "XXX" -e" as goalĀ , then I changed a goal as "test -P XXX" , then It works perfectly,so Please check , your goal is right or wrong.
"Creates a new exception to indicate that the specified lifecycle phase is not defined by any known lifecycle".

I also had the same problem, uninstall the GIT bash and install again. This will resolve EnvVar issue is any.
If still not solved, please check with your commands. Copy and paste your commands from notepad and this should work

Related

How to fix Missing requirement for javax.imageio while building Eclipse-CDT using Maven?

I downloaded the eclipse cdt source package org.eclipse.cdt-CDT_9_8_1.tar.xz from https://git.eclipse.org/c/cdt/org.eclipse.cdt.git and using maven 3.6.1 i tried to build it with command mvn clean install. Some packages were downloaded from repos and at the end it exited with the below error message
I need to build cdt from source as i want some changes in CDT source code. I am not an expert in Maven, not sure what's going wrong. Please help to resolve the issue
[INFO] Resolving dependencies of MavenProject: org.eclipse.cdt:org.eclipse.cdt.build.gcc.core:1.0.1-SNAPSHOT # D:\Eclipse\Sources\CDT9.8.1_GIT\cdt-releng\org.eclipse.cdt\build\org.eclipse.cdt.build.gcc.core.polyglot.build.properties
[ERROR] Cannot resolve target definition:
[ERROR] Software being installed: com.sun.xml.bind 2.2.0.v201505121915
[ERROR] Missing requirement: com.sun.xml.bind 2.2.0.v201505121915 requires 'java.package; javax.imageio 0.0.0' but it could not be found
[ERROR] Failed to resolve target definition D:\Eclipse\Sources\CDT9.8.1_GIT\cdt-releng\org.eclipse.cdt\releng\org.eclipse.cdt.target\cdt.target: See log for details -> [Help 1]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MavenExecutionException
The issue here is, that some plugins do not define a RequiredExecutionEnvironment. If such a plugin depends on a JRE package the build fails with the given error.
In Tycho it is possible to define such an environment:
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>target-platform-configuration</artifactId>
<version>${tycho.version}</version>
<configuration>
<!-- needed as some plugins do not set a execution environment they would fail to get jre packages (eg. javax.imageio) -->
<executionEnvironment>JavaSE-1.8</executionEnvironment>
</configuration>
</plugin>

Issues with Maven project for Hibernate tutorial

I am following the Hibernate documentation and trying to create a Maven project in my eclipse. I have created a new maven project by selecting default options shown in eclipse except for groupId, artifactId and version details which I have selected (org.hibernate.tutorials, hibernate-tutorial, 1.0.0-SNAPSHOT respectively) based on the information present in pom.xml shown in Hibernate documentation. After that I have replaced the pom.xml file in my project with the one shown in documentation. Then I have added version details for each of the dependencies which are missing in the documentation. Here is my final pom.xml file:
<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>org.hibernate.tutorials</groupId>
<artifactId>hibernate-tutorial</artifactId>
<version>1.0.0-SNAPSHOT</version>
<name>First Hibernate Tutorial</name>
<build>
<!-- we dont want the version to be part of the generated war file name -->
<finalName>${artifactId}</finalName>
</build>
<dependencies>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>4.3.6.Final</version>
</dependency>
<!-- Because this is a web app, we also have a dependency on the servlet api. -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
</dependency>
<!-- Hibernate uses slf4j for logging, for our purposes here use the simple backend -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.5.6</version>
</dependency>
<dependency>
<groupId>javassist</groupId>
<artifactId>javassist</artifactId>
<version>3.12.1.GA</version>
</dependency>
</dependencies>
Now in eclipse I see below errors:
1) Maven Configuration Problem:
Failure to transfer
org.apache.maven.plugins:maven-resources-plugin:pom:2.5 from
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. Original error:
Could not transfer artifact
org.apache.maven.plugins:maven-resources-plugin:pom:2.5 from/to
central (http://repo.maven.apache.org/maven2): The operation was
cancelled.
2) Maven Problems:
CoreException: Could not get the value for parameter compilerId for plugin execution default-compile: PluginResolutionException: Plugin org.apache.maven.plugins:maven-compiler-plugin:2.3.2 or one of its dependencies could not be resolved: Failed to collect dependencies for org.apache.maven.plugins:maven-compiler-plugin:jar:2.3.2 (): ArtifactDescriptorException: Failed to read artifact descriptor for org.codehaus.plexus:plexus-container-default:jar:1.0-alpha-9-stable-1: UnresolvableModelException: Failure to transfer org.codehaus.plexus:plexus-containers:pom:1.0.3 from 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. Original error: Could not transfer artifact org.codehaus.plexus:plexus-containers:pom:1.0.3 from/to central (http://repo.maven.apache.org/maven2): The operation was cancelled.
3) Maven Problem:
CoreException: Could not get the value for parameter compilerId for plugin execution default-testCompile: PluginResolutionException: Plugin org.apache.maven.plugins:maven-compiler-plugin:2.3.2 or one of its dependencies could not be resolved: Failure to transfer org.codehaus.plexus:plexus-utils:jar:1.4.1 from 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. Original error: Could not transfer artifact org.codehaus.plexus:plexus-utils:jar:1.4.1 from/to central (http://repo.maven.apache.org/maven2): The operation was cancelled.
4) Maven Problem:
Plugin execution not covered by lifecycle configuration: org.apache.maven.plugins:maven-compiler-plugin:2.3.2:compile (execution: default-compile, phase: compile)
5) Maven Problem:
Plugin execution not covered by lifecycle configuration: org.apache.maven.plugins:maven-compiler-plugin:2.3.2:testCompile (execution: default-testCompile, phase: test-compile)
6) Maven Problem:
Project configuration is not up-to-date with pom.xml. Run Maven->Update Project or use Quick Fix.
Update: When I build the project in eclipse I am getting below error:
Errors occurred during the build.
Errors running builder 'Maven Project Builder' on project 'hibernate-tutorial'.
Could not calculate build plan: Plugin org.apache.maven.plugins:maven-resources-plugin:2.5 or one of its dependencies could not be resolved: Failed to read artifact descriptor for org.apache.maven.plugins:maven-resources-plugin:jar:2.5
Plugin org.apache.maven.plugins:maven-resources-plugin:2.5 or one of its dependencies could not be resolved: Failed to read artifact descriptor for org.apache.maven.plugins:maven-resources-plugin:jar:2.5
Could not calculate build plan: Plugin org.apache.maven.plugins:maven-resources-plugin:2.5 or one of its dependencies could not be resolved: Failed to read artifact descriptor for org.apache.maven.plugins:maven-resources-plugin:jar:2.5
Plugin org.apache.maven.plugins:maven-resources-plugin:2.5 or one of its dependencies could not be resolved: Failed to read artifact descriptor for org.apache.maven.plugins:maven-resources-plugin:jar:2.5
Please help me how can I fix these issues. I am blocked at first step of learning Hibernate.
Thanks in advance.
Exit eclipse
Remove (or rename to be safe) your .m2/repository directory, it will be located in your home directory on your machine.
Start eclipse, right click your project, select Update Maven Project, check Force Update of Snapshots/Releases, press OK
It did not allow me to rename .m2 dir. Below are the detailed steps which resolved my error:
* I removed project from Eclipse
* Exited Eclipse
* Deleted (not shift deleted) .m2 folder from C/Users/Kshitija/ location
* Opened Eclipse, created maven project again
* Right clicked on the project -> Maven -> update project -> selected an option of "check Force Update of Snapshots/Releases", press OK
as soon as project is built, the error disappeared

Trouble with the sonar-packaging-maven-plugin after refactoring

I have some trouble developing a plugin for my company, later called as "myPlugin".
Background:
I was reading the book "SonarQube in Action" by the Manning company.
There was a little guide for developing a own plugin (they used the redmine plugin as example for developing). It told me to use the sonar-plugin-archetype to create the basic framework.
Situation before refactoring:
I wrote the plugin and it works fine. I encountered the problem when I've done some refactoring. Before the refactoring every package in the src folder in my tree (using ecplise) was called "main.java.org.sonar.plugins.myplugin" but the package decleration within each class was "org.sonar.plugins.myplugin". This were default settings created by using the sonar-plugin-archetype.
The settings within the pom.xml of the sonar-packaging-maven-plugin were the following once.
Pom-snippet before any changes were done:
<plugin>
<groupId>org.codehaus.sonar</groupId>
<artifactId>sonar-packaging-maven-plugin</artifactId>
<version>1.9</version>
<extensions>true</extensions>
<configuration>
<pluginClass>org.sonar.plugins.myplugin.myPlugin</pluginClass>
</configuration>
</plugin>
So far everything worked fine. Now we come to my problem.
Situation after refactoring:
As my company has some naming conevtions for classes and packages i changed the package names in the tree to "com.mycompany.sonar.plugins.myplugin" and the package decleration within each class also to "com.mycompany.sonar.plugins.myplugin". Then i changed the classPath option for the sonar-packaging-maven-plugin to "com.mycompany.sonar.plugins.myplugin.myPlugin". All I've done so to say was changing "org." into "com.mycompany.".
Pom-snippet after changes were done:
<plugin>
<groupId>org.codehaus.sonar</groupId>
<artifactId>sonar-packaging-maven-plugin</artifactId>
<version>1.9</version>
<extensions>true</extensions>
<configuration>
<pluginClass>com.mycompany.sonar.plugins.myplugin.myPlugin</pluginClass>
</configuration>
</plugin>
When i was running the "compile" command everything worked. Using "package" does not work, because the sonar-packaging-maven-plugin was not able to find the given class (see console output below). When i'm refoactoring everything again back to the beginning it works again.
[...]
[INFO] --- sonar-packaging-maven-plugin:1.9:sonar-plugin (default-sonar-plugin) # sonar-projectkeychecker-plugin ---
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 19.649 s
[INFO] Finished at: 2014-04-02T11:42:01+01:00
[INFO] Final Memory: 13M/67M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.codehaus.sonar:sonar-packaging-maven-plugin:1.9:sonar-plugin (default-sonar-plugin) on project sonar-myplugin-plugin: Plugin class not found: 'com.mycompany.sonar.plugins.myplugin.myPlugin-> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
My Question: Why are my new names not working? Are there any inner convetions for the sonar-packaging-maven-plugin (like the packaging name has to beginn with "org.sonar" ot something like this)?
Thank you for reading this long text and your try to help me :)
pluginClass is the entry point of the plugin. Value must be an existing class. In your example I suppose that there's a typo, it should be com.mycompany.sonar.plugins.myplugin.MyPlugin (upper-case M).
Under <plugin> I was missing the <extensions>true</extensions> tag

What type of new project for the Hibernate tutorial?

I am trying to follow this Hibernate tutorial:
http://docs.jboss.org/hibernate/orm/3.3/reference/en/html/tutorial.html
which seems pretty easy & straightforward, but I got stuck on the very 1st decision point: When selecting File > New Project to use the tutorial's suggested pom.xml, which of the many type of projects should I select?
Intuitively, I thought of creating a new Maven project:
Maven > Maven Project [Next]
[v] Create a simple project (skip archtype selection) [Next]
But at step #3 it prompts me for the very same information provided by the tutorial's pom.xml. So I am thinking the tutorial was aiming at creating a "blank project" and then manually adding the suggested pom.xml to it?
But what type of "blank project" would that be?
Java?
Java EE?
EJB?
JAXB?
JPA?
Maven?
Does it matter?
(sorry, don't have much experience (yet) with this new jargon, will get there eventually)
UPDATE 1: Actually, the proposed method of selecting a Maven project (regardless whether starting with bogus or correct info) doesn't work:
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[ERROR] FATAL ERROR
[INFO] ------------------------------------------------------------------------
[INFO] Error building POM (may not be this project's POM).
Project ID: org.hibernate.tutorials:hibernate-tutorial
POM Location: C:\Users\Daniel\Workspace\First Hibernate Tutorial\pom.xml
Validation Messages:
[0] 'dependencies.dependency.version' is missing for org.hibernate:hibernate-core:jar
[1] 'dependencies.dependency.version' is missing for javax.servlet:servlet-api:jar
[2] 'dependencies.dependency.version' is missing for org.slf4j:slf4j-simple:jar
[3] 'dependencies.dependency.version' is missing for javassist:javassist:jar
Reason: Failed to validate POM for project org.hibernate.tutorials:hibernate-tutorial at C:\Users\Daniel\Workspace\First Hibernate Tutorial\pom.xml
I am going to check now whether creating a plain Java project, then converting it to a Maven (after copying that tutorial's pom.xml) will do the trick.
UPDATE 2: Creating a plain Java project, then converting it to a Maven (after copying that tutorial's pom.xml) produces the same errors.
What am I missing?
UPDATE 3: Thanks to #cowls tip below I found that "I" was missing were the version numbers for the Maven dependencies. "I" because it's the tutorial that was missing them (what kind of a tutorial is this?)
Once I used some known version numbers, e.g.:
<dependencies>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>3.5.6-Final</version>
</dependency>
<!-- Because this is a web app, we also have a dependency on the servlet api. -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>1.2_02</version>
</dependency>
<!-- Hibernate uses slf4j for logging, for our purposes here use the simple backend -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.5.10</version>
</dependency>
<!-- Hibernate gives you a choice of bytecode providers between cglib and javassist -->
<dependency>
<groupId>javassist</groupId>
<artifactId>javassist</artifactId>
<version>3.8.0.GA</version>
</dependency>
</dependencies>
I have been able to get rid of that scary FATAL ERROR message. That error message's "tip" BTW was counter-productive as it was pointing to the wrong direction:
[INFO] Error building POM (may not be this project's POM).
Now... I am still getting a build error, albeit much less scary:
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Building First Hibernate Tutorial
[INFO] task-segment: [install]
[INFO] ------------------------------------------------------------------------
[INFO] [resources:resources {execution: default-resources}]
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory C:\Users\dben\ws-study\First Hibernate Tutorial\src\main\resources
Downloading: http://repo1.maven.org/maven2/javax/servlet/servlet-api/1.2_02/servlet-api-1.2_02.pom
[INFO] Unable to find resource 'javax.servlet:servlet-api:pom:1.2_02' in repository central (http://repo1.maven.org/maven2)
Downloading: http://repo1.maven.org/maven2/javax/servlet/servlet-api/1.2_02/servlet-api-1.2_02.jar
[INFO] Unable to find resource 'javax.servlet:servlet-api:jar:1.2_02' in repository central (http://repo1.maven.org/maven2)
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] Failed to resolve artifact.
Missing:
----------
1) javax.servlet:servlet-api:jar:1.2_02
Try downloading the file manually from the project website.
Then, install it using the command:
mvn install:install-file -DgroupId=javax.servlet -DartifactId=servlet-api -Dversion=1.2_02 -Dpackaging=jar -Dfile=/path/to/file
Alternatively, if you host your own repository you can deploy the file there:
mvn deploy:deploy-file -DgroupId=javax.servlet -DartifactId=servlet-api -Dversion=1.2_02 -Dpackaging=jar -Dfile=/path/to/file -Durl=[url] -DrepositoryId=[id]
Path to dependency:
1) org.hibernate.tutorials:hibernate-tutorial:jar:1.0.0-SNAPSHOT
2) javax.servlet:servlet-api:jar:1.2_02
----------
1 required artifact is missing.
for artifact:
org.hibernate.tutorials:hibernate-tutorial:jar:1.0.0-SNAPSHOT
from the specified remote repositories:
central (http://repo1.maven.org/maven2)
Interesting tutorial: I was expecting to learn some Hibernate but instead I am finding myself learning Maven. :)
UPDATE 4: I corrected the javax.servlet version to 2.4 and all is well now.
LESSONS LEARNED:
Maven's pom.xml requires a <version> for each & every dependency.
That <version>'s value must be valid.
Creating a new Maven project, then replacing its pom.xml entirely would work, but it still creates it with the incorrect subdirectory under Workspace because there is no way to define the <name> in the wizard-based creation process.
Creating a plain Java Project, then adding the pom.xml to its directory, then refreshing the Package Explorer view is the recommended way to go (no subdirectory renaming necessary).
That tutorial recommends Maven's "standard layout" but then breaks it by using the declared package "org.hibernate.tutorial.domain" which does not match the expected package "main.java.org.hibernate.tutorial.domain"... Do take Eclipse's fix suggestion to rename the package to "main.java.org.hibernate.tutorial.domain". (and move Event.java to the newly renamed package!)
The Hibernate configuration command (mvn exec:java -Dexec.mainClass="org.hsqldb.Server" etc.) must be run from the directory where pom.xml resides.
Easiest is to create a new maven project and use the maven-archetype-quickstart archetype.
This will create a basic maven project and you should be able to go from there.
Note that a maven project is just a Java project that uses Maven to build it, hence you will see a pom.xml file in your project.
Using this pom file you can build the project, include external dependencies and much more. I would suggest using the m2e plugin if you are developing with eclipse to help you manage the maven projects better: http://eclipse.org/m2e/
Each dependency you specify should have a version number associated with it.
e.g.
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>3.5.6-Final</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
</dependency>
To get the correct version number, just google artifactid maven dependency. E.g. hibernate-core maven dependency.
Look for the link for the maven central repository - i.e. http://mvnrepository.com. If you cant find it on Google you can search directly on the site, however I find its search feature quite poor.
Put your Java code in src/main/java and your resources in src/main/resources (e.g. xml files etc).
You can then build the project using mvn clean install

Why does the maven eclipse plugin break the maven jetty plugin?

I would like to have the maven eclipse plugin regenerate my .classpath whenever a build is run, and I did so by using the following configuration:
<!--
Generate a new .classpath each time the build is run, but don't try
to download sources or javadocs
-->
<profile>
<id>elipse-update</id>
<activation>
<file>
<exists>.classpath</exists>
</file>
</activation>
<build>
<plugins>
<plugin>
<artifactId>maven-eclipse-plugin</artifactId>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>eclipse</goal>
</goals>
<configuration>
<downloadSources>false</downloadSources>
<downloadJavadocs>false</downloadJavadocs>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
For some reason, this causes the maven jetty plugin to fail with ClassNotFoundException errors (it complains about all sorts of Spring classes not being there). Of course, it worked without a hit when I didn't have the maven eclipse plugin installed. Here's an example of what I'm talking about:
$ mvn jetty:run
[INFO] Scanning for projects...
...
[INFO] Starting jetty 6.1.22 ...
2010-02-11 20:53:08.984:INFO::jetty-6.1.22
2010-02-11 20:53:09.109:WARN::Could not instantiate listener org.springframework.web.context.ContextLoaderListener
java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at org.codehaus.classworlds.RealmClassLoader.loadClassDirect(RealmClassLoader.java:195)
at org.codehaus.classworlds.DefaultClassRealm.loadClass(DefaultClassRealm.java:255)
at org.codehaus.classworlds.DefaultClassRealm.loadClass(DefaultClassRealm.java:274)
at org.codehaus.classworlds.RealmClassLoader.loadClass(RealmClassLoader.java:214)
at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
Of course, if I delete that eclipse plugin section, I can run jetty as expected:
$ mvn jetty:run
[INFO] Scanning for projects...
...
Feb 11, 2010 8:55:28 PM org.springframework.web.context.ContextLoader initWebApplicationContext
INFO: Root WebApplicationContext: initialization completed in 1672 ms
2010-02-11 20:55:28.687:INFO::Started SelectChannelConnector#0.0.0.0:8080
[INFO] Started Jetty Server
[INFO] Starting scanner at interval of 5 seconds.
Some things I know:
Yes, I only activate this profile if the .classpath is present. This seems counter-intuitive, but I have a reason: I have another profile that activates when the .classpath is absent which runs the eclipse plugin with the options for downloading source code and javadocs set to true. I don't want this to happen each build, so I created a separate plugin config for when the classpath is already there.
Yes, I could simply create properties that held the values of the options I wish to change instead of specifying the entire plugin config again. In that case, I would just set a eclipse.downloadSources property to true or false depending on the presence of the classpath and have a single plugin definition in the regular build section.
Any advice? This is a strange problem.
Thanks,
LES
I suspect the Maven Eclipse Plugin to mess do some classpath woodo that affects the jetty plugin later.
But to be honest, this is not a very common way to use the Eclipse plugin, at least not to my knowledge. Most people don't include it in their build, they just run it when the POM has changed and this generally doesn't happen every build. Moreover, touching the .classpath confuses Eclipse if I remember well and forces a clean rebuild of the project which is pretty annoying.
So at the end, and I'm sorry for that, this seems to introduce more annoyances than benefits. You can try to open a Jira issue though.
You really don't want to run the maven-eclipse-plugin on every build when there's a .classpath present. I can't tell you exactly what it does to the classpaths, but this is not how it's intended to be used. The assumption is that when you run it you only run eclipse:eclipse (or some other goal).
Why do you want to keep re-running it?