viernes, 11 de enero de 2013

Maven Archetype from Existing Project

Hi there,

So this weeks I've been having to mess around with Maven, in particular with archetypes.
Being new at this particular aspect of the Maven world I started where almost anyone will the Maven documentation page.

Any way.......

Thing is, this helped me a lot to understand the structure of a Maven archetype project but it didn't get me to create an archetype in an easy way.
In the end I found this blog.

As it turns out, the easiest way to create a Maven archetype is using an existing maven project.
Which makes senses.
As with anything in life if you like to create a template for something it's easier to create that something an then extract the template.

So this is the case, and the way to achieve this is:

mvn archetype:create-from-project

This will create a maven archetype from a project and will leave this new archetype project in:

target/generated-sources/archetype/

Now that you have you're base archetype you can start to tune it, and when you're ready to go just do:

mvn install

This will install the archetype in your local m2 repo.

Finally for those of you who don't know how to use this archetype one it's in place, this is the way:

mvn archetype:generate -DarchetypeGroupId={group.id.defined.in.the.archetype} -DarchetypeArtifactId={artifact-id-defined-in-the-archetype}



And that's it, have fun


martes, 8 de enero de 2013

Out of Memory with Maven & MAVEN_OPTS

Have you ever got an error like this:


java.lang.OutOfMemoryError: Java heap space
at java.util.Arrays.copyOf(Arrays.java:2786)
at java.io.ByteArrayOutputStream.write(ByteArrayOutputStream.java:94)
at java.util.jar.JarVerifier.update(JarVerifier.java:194)
at java.util.jar.JarFile.initializeVerifier(JarFile.java:322)
at java.util.jar.JarFile.getInputStream(JarFile.java:388)
at sun.misc.URLClassPath$JarLoader$2.getInputStream(URLClassPath.java:69


Well this is the easy solution, increase the memory of the JVM.

BUT HOW IF I'M BUILDING WITH MAVEN???

God question, and the answer is:

export MAVEN_OPTS=-Xmx512m


Of course this will follow the same rules as for the vm arguments for the JVM, so please modify your memory limit accordingly.

Also this export command, for you Mac users, will only set the env var for the current terminal not for all the future ones.

Hope you find this useful I know I'll keep coming back to this post just to remember this.