Maven knowledge

From JazzTeamWiki
Jump to: navigation, search

Maven base info

Troubleshooting

In the case you have problems running your web application through maven command in eclipse (e.g. mvn jetty:run), and this problem is about com:sun:tools.jar - please specify in your eclipse in Installed JRE workspace settings Java SDK, but not JRE, as otherwise tools.jar is not found in JRE.

More details with screenshots could be found here http://hobione.wordpress.com/2009/03/11/missing-comsuntoolsjar142/

base goals

  • compile
  • test runs tests
  • eclipse:eclipse generates eclipse .classpath and .project files
  • eclipse:add-maven-repo adds maven repo to the workspace
  • jar:jar
  • install base goal, does all the work we need - compile, test, create jars and install at local repo
  • clean
  • package
  • site makes a site

additional goals

  • process-resources
  • validate
  • generate-sources
  • process-sources
  • generate-resources
  • process-resources
  • verify

base archetypes

  • simple project
mvn archetype:create \
  -DarchetypeGroupId=org.apache.maven.archetypes \
  -DgroupId=com.mycompany.app \
  -DartifactId=my-app
  • site
 
  mvn archetype:create \
  -DarchetypeGroupId=org.apache.maven.archetypes \
  -DarchetypeArtifactId=maven-archetype-site \
  -DgroupId=com.mycompany.app \
  -DartifactId=my-app-site
  • web application
mvn archetype:create \
    -DarchetypeGroupId=org.apache.maven.archetypes \
    -DarchetypeArtifactId=maven-archetype-webapp \
    -DgroupId=com.mycompany.app \
    -DartifactId=my-webapp

useful tips

say where eclipse workspace is
mvn eclipse:eclipse -Declipse.workspaсe=..
access java docs and sources
-DdownloadJavadocs=true -DdownloadSources=true
check mvn version 
mvn --version
official repo to check if dependencies are available 
http://repo1.maven.org/maven2/
skipping tests
-Dmaven.skip.tests=true
maven and JVM arguments
set MAVEN_OPTS=-Xmx512M -XX:MaxPermSize=128M
.m2\settings.xml
proxies
 
	<proxies>
		<proxy>
			<active>true</active>
			<protocol>http</protocol>
			<host>soltrend.astelit.ukr</host>
			<port>3128</port>
		</proxy>
	</proxies>
local pom file
repositories
	<repositories>
		<repository>
		    <id>codehaus-snapshots</id>
		    <name>Maven Codehaus snapshot repository</name>
		    <url>http://snapshots.repository.codehaus.org/</url>
		</repository>
	</repositories>
JPDA options to maven
export JPDA_OPTS="-Xdebug -Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=n"
export MAVEN_OPTS="-XX:MaxPermSize=192m -Xmx512M $JPDA_OPTS"


Maven eclipse plugin

update maven eclipse 
remove plugin .m2\repository\org\apache\maven\plugins\maven-eclipse-plugin\ and run mvn eclipse:eclipse, what will push maven to download a new version of maven eclipse plugin. Otherwise some functionality may not be supported if you have old version of plugin
why it could be used
  • to analyze dependencies in a graphical way
  • to run maven config files from eclipse
  • to simplify editing of pom file

useful links

Apache CXF project how-to, build environment is entirely based on maven

Book on maven for eclipse plugin