<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-7076829014222870999</id><updated>2011-08-24T10:24:34.101+01:00</updated><category term='maven'/><title type='text'>Sam's notes</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://sea36.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7076829014222870999/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://sea36.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>samadams</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>4</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-7076829014222870999.post-4588654266189988253</id><published>2010-05-29T08:24:00.011+01:00</published><updated>2010-05-29T19:03:12.008+01:00</updated><title type='text'>Type-safe arbitary properties in Java</title><content type='html'>&lt;div class="moz-text-html" lang="x-unicode"&gt;Yesterday a colleague approached me regarding the best method for associating arbitrary properties with an object in Java. The object currently has a &lt;span style="font-family:courier new;"&gt;Map&amp;lt;String,String&gt;&lt;/span&gt; for which it exposes public &lt;span style="font-family:courier new;"&gt;setProperty&lt;/span&gt; and &lt;span style="font-family:courier new;"&gt;getProperty&lt;/span&gt; methods, but he wanted to be able to associate properties other than Strings, without having to serialize them.&lt;br /&gt;&lt;br /&gt;I have seen Objects using a &lt;span style="font-family:courier new;"&gt;Map&amp;lt;String,Object&gt;&lt;/span&gt; to store properties, but this leads to code becoming littered with casts, with the associated risks of &lt;span style="font-family:courier new;"&gt;ClassCastExceptions&lt;/span&gt; appearing at runtime.&lt;br /&gt;&lt;br /&gt;My suggested solution was to use generics to hide the property map behind a type-safe facade.&lt;br /&gt;&lt;br /&gt;First we define a generically typed Key:&lt;br /&gt;&lt;pre&gt;public class Key&amp;lt;T&gt; {&lt;br /&gt;&lt;br /&gt;  private final String name;&lt;br /&gt;&lt;br /&gt;  public Key(String name) {&lt;br /&gt;    this.name = name;&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt;  @Override&lt;br /&gt;  public int hashCode() {&lt;br /&gt;    return 37 * (name != null ? name.hashCode() : 0);&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt;  @Override&lt;br /&gt;  public boolean equals(Object obj) {&lt;br /&gt;    return this == obj;&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt;  @Override&lt;br /&gt;  public String toString() {&lt;br /&gt;    return "Key{" + name + "}";&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt;}&lt;/pre&gt;&lt;br /&gt;When we use this as the key for our property map, the Java compiler can infer the Object type from the key, preventing us from associating a mistyped Object with a key, and correctly casting the Object back when we get it:&lt;br /&gt;&lt;pre&gt;public class MyObject {&lt;br /&gt;&lt;br /&gt;  private Map&amp;lt;Key,Object&gt; properties = new HashMap&amp;lt;Key, Object&gt;();&lt;br /&gt;&lt;br /&gt;  public &amp;lt;T&gt; void setProperty(Key key, T value) {&lt;br /&gt;    properties.put(key, value);&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt;  public &amp;lt;T&gt; T getProperty(Key&amp;lt;T&gt; key) {&lt;br /&gt;    return (T) properties.get(key);&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt;}&lt;/pre&gt;&lt;br /&gt;The types can be determined at compile time, so there is no need for casts:&lt;br /&gt;&lt;pre&gt;  MyObject obj = new MyObject();&lt;br /&gt;        &lt;br /&gt;  Key&lt;String&gt; kstr = new Key&lt;String&gt;("foo");&lt;br /&gt;  Key&lt;Integer&gt; kint = new Key&lt;Integer&gt;("bar");&lt;br /&gt;&lt;br /&gt;  obj.setProperty(kstr, "string");&lt;br /&gt;  obj.setProperty(kint, 123);&lt;br /&gt;  String s = obj.getProperty(kstr);&lt;br /&gt;  Integer i = obj.getProperty(kint);&lt;/pre&gt;&lt;br /&gt;Errors will also be detected by the compiler:&lt;br /&gt;&lt;pre&gt;  // Try to set a String value to an Integer-typed property&lt;br /&gt;  obj.setProperty(kint, "xyz");&lt;br /&gt;&lt;br /&gt;  // Try to cast the value of an Integer-typed property to a String&lt;br /&gt;  String x = (String) obj.getProperty(kint);&lt;/pre&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7076829014222870999-4588654266189988253?l=sea36.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sea36.blogspot.com/feeds/4588654266189988253/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sea36.blogspot.com/2010/05/type-safe-arbitary-properties.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7076829014222870999/posts/default/4588654266189988253'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7076829014222870999/posts/default/4588654266189988253'/><link rel='alternate' type='text/html' href='http://sea36.blogspot.com/2010/05/type-safe-arbitary-properties.html' title='Type-safe arbitary properties in Java'/><author><name>samadams</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7076829014222870999.post-867845992551734017</id><published>2010-04-27T10:23:00.005+01:00</published><updated>2010-04-27T10:59:51.190+01:00</updated><title type='text'>Creating PNGs from Jmol</title><content type='html'>&lt;div style="text-align: center;"&gt;&lt;span class="Apple-style-span"  style="color:#0000EE;"&gt;&lt;u&gt;&lt;br /&gt;&lt;/u&gt;&lt;/span&gt;&lt;/div&gt;&lt;a href="http://jmol.sourceforge.net/"&gt;Jmol&lt;/a&gt; is a fantastic open source 3D viewer for chemical structures.  I've exported images from the application many times, both as PNGs and for rendering with POV-Ray, but after a bit of digging and trial &amp;amp; error I've figured out how to automate the process...&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;// Create the objects&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;java.awt.Canvas display = new Canvas();&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;org.jmol.adapter.smarter.SmarterJmolAdapter adapter = new &lt;/span&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;SmarterJmolAdapter();&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;org.jmol.viewer.Viewer viewer = (Viewer)&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;Viewer.allocateViewer(display, adapter, null, null, null, &lt;/span&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;null, null);&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;try {&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;viewer.setScreenDimension(new Dimension(1, 1));&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;viewer.scriptWait("load 'crystal.cif' {1 1 1};");&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;// can do more scripting here...&lt;/span&gt;&lt;/div&gt;&lt;div&gt;    &lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;viewer.setScreenDimension(new Dimension(400, 400));&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;// anti-aliasing enabled&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;viewer.getGraphics3D().setWindowParameters(400, 400, true);&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;// Create image&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;viewer.getImageAs("PNG", 1, 400, 400, "image.png", null);&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;} finally {&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;// Ensure threads are stopped&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;viewer.setModeMouse(JmolConstants.MOUSE_NONE);&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;}&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style=" ;font-family:Georgia, serif;"&gt;Using &lt;a href="http://www.imb-jena.de/cgi-bin/3d_mapping.pl?CODE=1deh"&gt;Jena3D&lt;/a&gt;'s script for automatic orientation of structures, recently &lt;/span&gt;&lt;span class="Apple-style-span"  style="font-family:Georgia, serif;"&gt;&lt;a href="http://sourceforge.net/mailarchive/message.php?msg_name=4B768753.8010901@fli-leibniz.de"&gt;mentioned by Rolf Huehne on the Jmol-users mailing list&lt;/a&gt;&lt;/span&gt;&lt;span class="Apple-style-span"  style=" ;font-family:Georgia, serif;"&gt; I've been able to create some great pictures of crystal structures:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style=" ;font-family:Georgia, serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style=" ;font-family:Georgia, serif;"&gt;&lt;a href="http://3.bp.blogspot.com/_fze7t1NnmvU/S9ax46fXbcI/AAAAAAAAAAM/qbEhDhIzbAM/s1600/xray%252fjr9906%252fimage.png"&gt;&lt;img src="http://3.bp.blogspot.com/_fze7t1NnmvU/S9ax46fXbcI/AAAAAAAAAAM/qbEhDhIzbAM/s320/xray%252fjr9906%252fimage.png" border="0" alt="" id="BLOGGER_PHOTO_ID_5464750789192281538" style="display: block; margin-top: 0px; margin-right: auto; margin-bottom: 10px; margin-left: auto; text-align: center; cursor: pointer; width: 320px; height: 320px; " /&gt;&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;If only there was a really easy way for these to be used as place-holders for a &lt;a href="http://www.appelsiini.net/projects/lazyload"&gt;lazy-loading&lt;/a&gt; Jmol applets, making websites embedding Jmol really fast... any volunteers?!&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7076829014222870999-867845992551734017?l=sea36.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sea36.blogspot.com/feeds/867845992551734017/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sea36.blogspot.com/2010/04/creating-pngs-from-jmol.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7076829014222870999/posts/default/867845992551734017'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7076829014222870999/posts/default/867845992551734017'/><link rel='alternate' type='text/html' href='http://sea36.blogspot.com/2010/04/creating-pngs-from-jmol.html' title='Creating PNGs from Jmol'/><author><name>samadams</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://3.bp.blogspot.com/_fze7t1NnmvU/S9ax46fXbcI/AAAAAAAAAAM/qbEhDhIzbAM/s72-c/xray%252fjr9906%252fimage.png' height='72' width='72'/><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7076829014222870999.post-6296970653112288811</id><published>2009-02-10T02:39:00.002Z</published><updated>2009-02-10T23:54:32.209Z</updated><category scheme='http://www.blogger.com/atom/ns#' term='maven'/><title type='text'>Running and distributing Maven projects</title><content type='html'>Maven makes building java projects very easy, dealing with dependencies and transitive dependencies (dependencies of dependencies, dependencies of dependencies of dependencies etc...), but what happens if you want to run a program? Or to create a distribution for people who don't use Maven?&lt;br /&gt;&lt;br /&gt;Well, it turns out that there are several easy things we can do...&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="font-weight: bold;"&gt;1) Run a class' main method:&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;The first thing we can do is run the main method of a class inside a Maven built project, having Maven take care of all the dependencies, using the &lt;a href="http://mojo.codehaus.org/exec-maven-plugin/"&gt;exec&lt;/a&gt; &lt;span class="blsp-spelling-error" id="SPELLING_ERROR_0"&gt;plugin&lt;/span&gt;:&lt;br /&gt;&lt;pre style="font-weight: bold;"&gt;&lt;span class="blsp-spelling-error" id="SPELLING_ERROR_1"&gt;mvn&lt;/span&gt; exec:java -Dexec.mainClass=(package.className) [ -&lt;span class="blsp-spelling-error" id="SPELLING_ERROR_2"&gt;Dexec&lt;/span&gt;.&lt;span class="blsp-spelling-error" id="SPELLING_ERROR_3"&gt;args&lt;/span&gt;=(&lt;span class="blsp-spelling-error" id="SPELLING_ERROR_4"&gt;commandLineArgs&lt;/span&gt;) ]&lt;/pre&gt;We can specify which class to run, and pass arguments to its main method. To pass more than one argument the arguments need enclosing in double quotes, and separating by spaces. Spaces that are part of arguments are escaped with a slash, as are slashes...&lt;br /&gt;&lt;br /&gt;&lt;table border="1" cellspacing="0"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;th&gt;Command&lt;/th&gt;&lt;th&gt;&lt;span class="blsp-spelling-error" id="SPELLING_ERROR_5"&gt;args&lt;/span&gt; passed to main method&lt;/th&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;-&lt;span class="blsp-spelling-error" id="SPELLING_ERROR_6"&gt;Dexec&lt;/span&gt;.&lt;span class="blsp-spelling-error" id="SPELLING_ERROR_7"&gt;args&lt;/span&gt;=foo&lt;/td&gt;&lt;td&gt;One argument: '&lt;i&gt;foo&lt;/i&gt;'&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;-&lt;span class="blsp-spelling-error" id="SPELLING_ERROR_8"&gt;Dexec&lt;/span&gt;.&lt;span class="blsp-spelling-error" id="SPELLING_ERROR_9"&gt;args&lt;/span&gt;="foo"&lt;/td&gt;&lt;td&gt;One argument: '&lt;i&gt;foo&lt;/i&gt;'&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;-&lt;span class="blsp-spelling-error" id="SPELLING_ERROR_10"&gt;Dexec&lt;/span&gt;.&lt;span class="blsp-spelling-error" id="SPELLING_ERROR_11"&gt;args&lt;/span&gt;="foo bar"&lt;/td&gt;&lt;td&gt;Two arguments: '&lt;i&gt;foo&lt;/i&gt;' and '&lt;i&gt;bar&lt;/i&gt;'&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;-&lt;span class="blsp-spelling-error" id="SPELLING_ERROR_12"&gt;Dexec&lt;/span&gt;.&lt;span class="blsp-spelling-error" id="SPELLING_ERROR_13"&gt;args&lt;/span&gt;="foo\ bar"&lt;/td&gt;&lt;td&gt;One argument: '&lt;i&gt;foo bar&lt;/i&gt;'&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;-&lt;span class="blsp-spelling-error" id="SPELLING_ERROR_14"&gt;Dexec&lt;/span&gt;.&lt;span class="blsp-spelling-error" id="SPELLING_ERROR_15"&gt;args&lt;/span&gt;="foo\\ bar"&lt;/td&gt;&lt;td&gt;Two arguments: '&lt;i&gt;foo\&lt;/i&gt;' and '&lt;i&gt;bar&lt;/i&gt;'&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;2) Build a &lt;span class="blsp-spelling-error" id="SPELLING_ERROR_16"&gt;classpath&lt;/span&gt;:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;What if we want to use our code without Maven? If we're going to be working on the machine we've been building our project on, we can get Maven to tell us how to set our &lt;span class="blsp-spelling-error" id="SPELLING_ERROR_17"&gt;classpath&lt;/span&gt; to point at all the dependency JAR files in our local repository:&lt;br /&gt;&lt;pre&gt;&lt;span style="font-weight: bold;"&gt;&lt;span class="blsp-spelling-error" id="SPELLING_ERROR_18"&gt;mvn&lt;/span&gt; dependency:build-&lt;span class="blsp-spelling-error" id="SPELLING_ERROR_19"&gt;classpath&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;[INFO] Scanning for projects...&lt;br /&gt;[INFO] Searching repository for &lt;span class="blsp-spelling-error" id="SPELLING_ERROR_20"&gt;plugin&lt;/span&gt; with prefix: 'dependency'.&lt;br /&gt;[INFO] ------------------------------------------------------------------------&lt;br /&gt;[INFO] Building &lt;span class="blsp-spelling-error" id="SPELLING_ERROR_21"&gt;CMLXOM&lt;/span&gt;&lt;br /&gt;[INFO]    task-segment: [dependency:build-&lt;span class="blsp-spelling-error" id="SPELLING_ERROR_22"&gt;classpath&lt;/span&gt;]&lt;br /&gt;[INFO] ------------------------------------------------------------------------&lt;br /&gt;[INFO] [dependency:build-&lt;span class="blsp-spelling-error" id="SPELLING_ERROR_23"&gt;classpath&lt;/span&gt;]&lt;br /&gt;[INFO] Dependencies &lt;span class="blsp-spelling-error" id="SPELLING_ERROR_24"&gt;classpath&lt;/span&gt;:&lt;br /&gt;/home/sam/.m2/repository/dom4j/dom4j/1.6.1/dom4j-1.6.1.jar:/home/sam/.m2/reposi&lt;br /&gt;tory/jaxen/jaxen/1.1-beta-8/jaxen-1.1-beta-8.jar:/home/sam/.m2/repository/jdom/&lt;br /&gt;jdom/1.0/jdom-1.0.jar:/home/sam/.m2/repository/junit/junit/4.0/junit-4.0.jar:/h&lt;br /&gt;ome/sam/.m2/repository/log4j/log4j/1.2.13/log4j-1.2.13.jar:/home/sea36/.m2/repo&lt;br /&gt;sitory/xalan/xalan/2.7.0/xalan-2.7.0.jar:/home/sam/.m2/repository/xerces/xerces&lt;br /&gt;Impl/2.8.0/xercesImpl-2.8.0.jar:/home/sam/.m2/repository/xerces/xmlParserAPIs/2&lt;br /&gt;.6.2/xmlParserAPIs-2.6.2.jar:/home/sam/.m2/repository/xml-apis/xml-apis/1.3.03/&lt;br /&gt;xml-apis-1.3.03.jar:/home/sam/.m2/repository/xom/xom/1.1/xom-1.1.jar&lt;br /&gt;[INFO] ------------------------------------------------------------------------&lt;br /&gt;[INFO] BUILD SUCCESSFUL&lt;br /&gt;[INFO] ------------------------------------------------------------------------&lt;/pre&gt;&lt;span style="font-weight: bold;"&gt;3)  Export a project's dependencies out of the local repository:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Alternatively, we can export all the &lt;span class="blsp-spelling-error" id="SPELLING_ERROR_25"&gt;depencency&lt;/span&gt; JAR files for the project, collating them in the &lt;span style="font-style: italic;"&gt;target/dependency&lt;/span&gt; directory:&lt;br /&gt;&lt;pre&gt;&lt;span style="font-weight: bold;"&gt;&lt;span class="blsp-spelling-error" id="SPELLING_ERROR_26"&gt;mvn&lt;/span&gt; dependency:copy-dependencies&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;[INFO] Scanning for projects...&lt;br /&gt;[INFO] Searching repository for &lt;span class="blsp-spelling-error" id="SPELLING_ERROR_27"&gt;plugin&lt;/span&gt; with prefix: 'dependency'.&lt;br /&gt;[INFO] ------------------------------------------------------------------------&lt;br /&gt;[INFO] Building &lt;span class="blsp-spelling-error" id="SPELLING_ERROR_28"&gt;CMLXOM&lt;/span&gt;&lt;br /&gt;[INFO]    task-segment: [dependency:copy-dependencies]&lt;br /&gt;[INFO] ------------------------------------------------------------------------&lt;br /&gt;[INFO] [dependency:copy-dependencies]&lt;br /&gt;[INFO] Copying dom4j-1.6.1.jar to .\target\dependency\dom4j-1.6.1.jar&lt;br /&gt;[INFO] Copying jaxen-1.1-beta-8.jar to .\target\dependency\jaxen-1.1-beta-8.jar&lt;br /&gt;[INFO] Copying jdom-1.0.jar to .\target\dependency\jdom-1.0.jar&lt;br /&gt;[INFO] Copying junit-4.0.jar to .\dependency\junit-4.0.jar&lt;br /&gt;[INFO] Copying log4j-1.2.13.jar to .\target\dependency\log4j-1.2.13.jar&lt;br /&gt;[INFO] Copying xalan-2.7.0.jar to .\target\dependency\xalan-2.7.0.jar&lt;br /&gt;[INFO] Copying xercesImpl-2.8.0.jar to .\target\dependency\xercesImpl-2.8.0.jar&lt;br /&gt;[INFO] Copying xmlParserAPIs-2.6.2.jar to .\target\dependency\xmlParserAPIs-2.6.2.jar&lt;br /&gt;[INFO] Copying xml-apis-1.3.03.jar to .\target\dependency\xml-apis-1.3.03.jar&lt;br /&gt;[INFO] Copying xom-1.1.jar to .\target\dependency\xom-1.1.jar&lt;br /&gt;[INFO] ------------------------------------------------------------------------&lt;br /&gt;[INFO] BUILD SUCCESSFUL&lt;br /&gt;[INFO] ------------------------------------------------------------------------&lt;/pre&gt;&lt;span style="font-weight: bold;"&gt;4) Build a single jar containing project and all dependencies:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;And finally, we can get Maven to build us a single JAR file containing both our project, and all its dependencies:&lt;br /&gt;&lt;pre style="font-weight: bold;"&gt;&lt;span class="blsp-spelling-error" id="SPELLING_ERROR_29"&gt;mvn&lt;/span&gt; assembly:assembly -&lt;span class="blsp-spelling-error" id="SPELLING_ERROR_30"&gt;DdescriptorId&lt;/span&gt;=jar-with-dependencies&lt;/pre&gt;&lt;span style="font-weight: bold;"&gt;Beware with this approach:&lt;/span&gt;&lt;br /&gt;If there are multiple dependencies containing files with the same name and path, only one version will be included in this JAR file.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7076829014222870999-6296970653112288811?l=sea36.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sea36.blogspot.com/feeds/6296970653112288811/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sea36.blogspot.com/2009/02/running-programs-with-maven.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7076829014222870999/posts/default/6296970653112288811'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7076829014222870999/posts/default/6296970653112288811'/><link rel='alternate' type='text/html' href='http://sea36.blogspot.com/2009/02/running-programs-with-maven.html' title='Running and distributing Maven projects'/><author><name>samadams</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7076829014222870999.post-4072055240513407654</id><published>2009-02-09T22:56:00.001Z</published><updated>2009-02-10T23:46:25.875Z</updated><category scheme='http://www.blogger.com/atom/ns#' term='maven'/><title type='text'>Attaching javadocs and sources to Maven install/deploy</title><content type='html'>&lt;div xmlns="http://www.w3.org/1999/xhtml"&gt;When installing &lt;a href="http://maven.apache.org/"&gt;maven&lt;/a&gt; artifacts to your local repository, or deploying them to a remote repository, it is really helpful to attach a copy of the source code and the javadoc.&lt;br /&gt;&lt;br /&gt;If you code Java in &lt;a href="http://www.eclipse.org/"&gt;eclipse&lt;/a&gt;, you can use the &lt;a href="http://m2eclipse.codehaus.org/"&gt;m2eclipse plugin&lt;/a&gt; to automatically download the source and javadoc files for dependencies, and then display the associated javadoc by hovering over a method or when using dot-complete, and inspect the source code by pressing F3.&lt;br /&gt;&lt;br /&gt;So, how do you attach the source and javadoc to an installation or deployment?&lt;br /&gt;&lt;pre style="font-weight: bold;" class="code"&gt;mvn clean javadoc:jar source:jar install&lt;/pre&gt;This will install three jar files to your local repository:&lt;br /&gt;&lt;ul&gt;&lt;li&gt;(artifactId)-(version).jar - containing the compiled artifact&lt;/li&gt;&lt;li&gt;(artifactId)-(version)-javadoc.jar - containing the artifact's javadoc&lt;/li&gt;&lt;li&gt;(artifactId)-(version)-sources.jar - containing the artifact's source files&lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7076829014222870999-4072055240513407654?l=sea36.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sea36.blogspot.com/feeds/4072055240513407654/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sea36.blogspot.com/2009/02/attaching-javadocs-and-sources-to-maven.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7076829014222870999/posts/default/4072055240513407654'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7076829014222870999/posts/default/4072055240513407654'/><link rel='alternate' type='text/html' href='http://sea36.blogspot.com/2009/02/attaching-javadocs-and-sources-to-maven.html' title='Attaching javadocs and sources to Maven install/deploy'/><author><name>samadams</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry></feed>
