Maven
From Null-pointer
Contents |
Command line params
Work offline
-o
[root@localhost ~]# mvn -o clean install
skip tests
-DskipTests
[root@localhost ~]# mvn install -DskipTests
dependency tree
[root@localhost ~]# mvn dependency:tree
Dependency scope
Maven provides four dependency scopes [2]:
- compile: A compile-scope dependency is available in all phases. This is the default value.
- provided: A provided dependency is used to compile the application, but will not be deployed. You would use this scope when you expect the JDK or application server to provide the JAR. The servlet APIs are a good example.
- runtime: Runtime-scope dependencies are not needed for compilation, only for execution, such as JDBC (Java Database Connectivity) drivers.
- test: Test-scope dependencies are needed only to compile and run tests (JUnit, for example).
Executable jar
<build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-assembly-plugin</artifactId> <version>2.2-beta-5</version> <configuration> <descriptorRefs> <descriptorRef>jar-with-dependencies</descriptorRef> </descriptorRefs> <archive> <manifest> <mainClass>package.to.MainClass</mainClass> </manifest> </archive> </configuration> <executions> <execution> <!-- this is used for inheritance merges --> <id>make-assembly</id> <!-- append to the packaging phase. --> <phase>package</phase> <goals> <!-- goals == mojos --> <goal>single</goal> </goals> </execution> </executions> </plugin> </plugins> </build>
Generating DDL Scripts from JPA Annotations
pom.xml
- <build>
- <plugins>
- <plugin>
- <groupId>org.codehaus.mojo</groupId>
- <artifactId>hibernate3-maven-plugin</artifactId>
- <version>2.2</version>
- <executions>
- <execution>
- <phase>process-classes</phase>
- <goals>
- <goal>hbm2ddl</goal>
- </goals>
- </execution>
- </executions>
- <configuration>
- <components>
- <component>
- <name>hbm2ddl</name>
- <implementation>jpaconfiguration</implementation>
- </component>
- </components>
- <componentProperties>
- <persistenceunit>arbiter</persistenceunit>
- <outputfilename>schema.ddl</outputfilename>
- <drop>false</drop>
- <create>true</create>
- <export>false</export>
- <format>true</format>
- </componentProperties>
- </configuration>
- </plugin>
- </plugins>
- </build>
persistence.xml
- in
src/main/resources/META-INF
<persistence xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd" version="2.0"> <persistence-unit name="arbiter"> <jta-data-source>java:/DefaultDS</jta-data-source> <properties> <property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5InnoDBDialect"/> </properties> </persistence-unit> </persistence>
command
[root@localhost ~]# mvn hibernate3:hbm2ddl
sources
- http://users.mafr.de/~matthias/articles/generating-ddl-scripts.html
- http://unmaintainable.wordpress.com/2008/04/12/hibernate3-schema-creation/
Overlays
you need the type of war and scope of runtime
<dependency> <groupId>bbc.iplayer.jet</groupId> <artifactId>jet-common-dynamic-logging</artifactId> <version>10.16.1</version> <type>war</type> <scope>runtime</scope> </dependency>
exclusions
<build> <finalName>ace</finalName> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-war-plugin</artifactId> <configuration> <overlays> <overlay> <groupId>bbc.iplayer.jet</groupId> <artifactId>jet-common-dynamic-logging</artifactId> <excludes> <exclude>WEB-INF/web.xml</exclude> <exclude>WEB-INF/lib/**</exclude> </excludes> </overlay> </overlays> </configuration> </plugin> </plugins> </build>
maven lifecycle
Java 1.6
N.B. not that the source tag is not closed. This is just a hack to get it to display on this wiki.
<build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>2.0.2</version> <configuration> <source>1.6</source <target>1.6</target> <optimize>true</optimize> </configuration> </plugin> </plugins> </build>
jetty
<build> <finalName>myWar</finalName> <plugins> <plugin> <groupId>org.mortbay.jetty</groupId> <artifactId>maven-jetty-plugin</artifactId> <version>6.1.23</version> <configuration> <contextPath>/</contextPath> <scanIntervalSeconds>2</scanIntervalSeconds> <connectors> <connector implementation="org.mortbay.jetty.nio.SelectChannelConnector"> <port>8085</port> <maxIdleTime>60000</maxIdleTime> </connector> </connectors> </configuration> </plugin> </plugins> </build>
[root@localhost ~]# mvn jetty:run
debug
[root@localhost ~]# export MAVEN_OPTS='-Xmx1024m -Xms512m -XX:MaxPermSize=256m -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5005' [3]

