> I will go through this and give it a try. If the simplest example will
> work, then I want to exclude things like the docs/ directory and other
> artifacts from the jar that is produced.
>
> The book example might work, but most likely not. The <manifest> section
> was left completely out. It was probably not tried first before going to
> press.
Whoops. I misremembered - this chapter didn't feature the manifest piece,
it has you run it by specifying the main class. However, I just tried the
example (I skipped all the unit test pieces) as printed in the dead-tree
version of their book which I have here. I found a couple of problems that
I'll make sure are reported to the Sonatype guys:
- Main.java ought to have "int zipcode = 60202;" and "zipcode =
Integer.parseInt(args[0])", and the member variable/ctor argument should
be ints as well
- YahooRetriever.retrieve() should throw Exception
- the project POM is missing the Java 1.5 compiler configuration:
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.5</source>
<target>1.5</target>
</configuration>
</plugin>
</plugins>
</build>
As I said, I skipped all the test stuff, but did verify that simply adding
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
will cause mvn assembly:assembly to build the JAR with dependencies.
We can bind this automatically to the project lifecycle by adding
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>assembly</goal>
</goals>
</execution>
</executions>
so we'll also get our jar-with-dependencies during the package phase.
Lastly to customize the manifest you want to add
<archive>
<manifest>
<mainClass>org.sonatype.mavenbook.weather.Main</mainClass>
</manifest>
</archive>
within the <configuration> element.
Final POM snipper for the assembly plugin:
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>assembly</goal>
</goals>
</execution>
</executions>
<configuration>
<archive>
<manifest>
<mainClass>org.sonatype.mavenbook.weather.Main</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
The only tricky bit here was knowing how to add <archive> there.
Originally I attempted to configure the maven-jar-plugin, but the assembly
plugin doesn't use the jar plugin - it goes to the Maven Archiver
directly, which has manifest support built into it (the jar plugin also
uses this). When you look at the jar plugin's documentation at
http://maven.apache.org/plugins/maven-jar-plugin/, it links to the
Archiver site for docs on what can go into the <archive> element that you
use to configure the JAR plugin. The assembly plugin takes the same
argument - which you can see documented at
http://maven.apache.org/plugins/maven-assembly-plugin/assembly-mojo.html -
so you can pass the same configuration.
I give you the documentation pointers not to assert that it's the best way
to present this information - there is clearly a knowledge chicken-and-egg
problem where you have to know something's there before you know to look
there for it - but to illustrate my thought process when I look for things
like this.
Hope this helps -
- John
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]