{"id":2263,"date":"2011-02-06T11:03:34","date_gmt":"2011-02-06T09:03:34","guid":{"rendered":"https:\/\/test.viaboxx.de\/2011\/02\/06\/simple-and-fast-prototyping-with-maven\/"},"modified":"2021-08-11T10:02:26","modified_gmt":"2021-08-11T10:02:26","slug":"simple-and-fast-prototyping-with-maven","status":"publish","type":"post","link":"https:\/\/www.viaboxx.de\/en\/blog\/simple-and-fast-prototyping-with-maven\/","title":{"rendered":"Simple and fast prototyping with Maven"},"content":{"rendered":"\n<p>Sometimes you are not working in the big enterprise project with thousand lines of code. You just want to play with a new library or a single aspect. Integrating this from the beginning in the main project can sometimes be a slow and complicated task.<\/p>\n\n\n\n<p>We have a special area called <em>Sandbox<\/em> for this small projects in our repository. After years of IDE usage, some people loose the speed in starting a small project from scratch. Too much tooling can be a problem, but the right tooling can be a great time saver.<br>Maven is most of the time a useful thing, if used in the right way. Don\u2019t reinvent the wheel and make it too complicated for others to understand your prototype.<\/p>\n\n\n\n<p>I played with the PDF library itext \u2013 great one. With just a few lines of code. I even needed to install this library on different computers and operating systems (font types, \u2026). A jar is the purest form for Java projects. But with external dependencies you are dealing with the classpath. To avoid this I packaged the dependencies into an Uber-Jar.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">[codesyntax lang=\"xml\"]\n&lt;pre>&amp;lt;project xmlns=\"http:\/\/maven.apache.org\/POM\/4.0.0\" xmlns:xsi=\"http:\/\/www.w3.org\/2001\/XMLSchema-instance\"\n         xsi:schemaLocation=\"http:\/\/maven.apache.org\/POM\/4.0.0 http:\/\/maven.apache.org\/maven-v4_0_0.xsd\"&amp;gt;\n    &amp;lt;modelVersion&amp;gt;4.0.0&amp;lt;\/modelVersion&amp;gt;\n \n    &amp;lt;groupId&amp;gt;de.viaboxx&amp;lt;\/groupId&amp;gt;\n    &amp;lt;artifactId&amp;gt;itext-pdf-writer&amp;lt;\/artifactId&amp;gt;\n    &amp;lt;version&amp;gt;1.0-SNAPSHOT&amp;lt;\/version&amp;gt;\n    &amp;lt;packaging&amp;gt;jar&amp;lt;\/packaging&amp;gt;\n \n    &amp;lt;dependencies&amp;gt;\n        &amp;lt;dependency&amp;gt;\n            &amp;lt;groupId&amp;gt;com.lowagie&amp;lt;\/groupId&amp;gt;\n            &amp;lt;artifactId&amp;gt;itext&amp;lt;\/artifactId&amp;gt;\n            &amp;lt;version&amp;gt;2.0.7&amp;lt;\/version&amp;gt;\n        &amp;lt;\/dependency&amp;gt;\n    &amp;lt;\/dependencies&amp;gt;\n \n    &amp;lt;build&amp;gt;\n        &amp;lt;plugins&amp;gt;\n            &amp;lt;plugin&amp;gt;\n                &amp;lt;groupId&amp;gt;org.apache.maven.plugins&amp;lt;\/groupId&amp;gt;\n                &amp;lt;artifactId&amp;gt;maven-jar-plugin&amp;lt;\/artifactId&amp;gt;\n                &amp;lt;configuration&amp;gt;\n                    &amp;lt;archive&amp;gt;\n                        &amp;lt;manifest&amp;gt;\n                            &amp;lt;mainClass&amp;gt;de.viaboxx.itext.Main&amp;lt;\/mainClass&amp;gt;\n                            &amp;lt;addClasspath&amp;gt;true&amp;lt;\/addClasspath&amp;gt;\n                        &amp;lt;\/manifest&amp;gt;\n                    &amp;lt;\/archive&amp;gt;\n                &amp;lt;\/configuration&amp;gt;\n            &amp;lt;\/plugin&amp;gt;\n            &amp;lt;plugin&amp;gt;\n                &amp;lt;artifactId&amp;gt;maven-assembly-plugin&amp;lt;\/artifactId&amp;gt;\n                &amp;lt;configuration&amp;gt;\n                    &amp;lt;descriptorRefs&amp;gt;\n                        &amp;lt;descriptorRef&amp;gt;jar-with-dependencies&amp;lt;\/descriptorRef&amp;gt;\n                    &amp;lt;\/descriptorRefs&amp;gt;\n                    &amp;lt;archive&amp;gt;\n                        &amp;lt;manifest&amp;gt;\n                            &amp;lt;mainClass&amp;gt;de.viaboxx.itext.Main&amp;lt;\/mainClass&amp;gt;\n                        &amp;lt;\/manifest&amp;gt;\n                    &amp;lt;\/archive&amp;gt;\n                &amp;lt;\/configuration&amp;gt;\n                &amp;lt;executions&amp;gt;\n                    &amp;lt;execution&amp;gt;\n                        &amp;lt;id&amp;gt;make-my-jar-with-dependencies&amp;lt;\/id&amp;gt;\n                        &amp;lt;phase&amp;gt;package&amp;lt;\/phase&amp;gt;\n                        &amp;lt;goals&amp;gt;\n                            &amp;lt;goal&amp;gt;single&amp;lt;\/goal&amp;gt;\n                        &amp;lt;\/goals&amp;gt;\n                    &amp;lt;\/execution&amp;gt;\n                &amp;lt;\/executions&amp;gt;\n            &amp;lt;\/plugin&amp;gt;\n        &amp;lt;\/plugins&amp;gt;\n    &amp;lt;\/build&amp;gt;\n&amp;lt;\/project&amp;gt;&lt;\/pre>\n[\/codesyntax]<\/pre>\n\n\n\n<p>The assembly plugin is just one of the possibilities. There are several Maven plugins to create Uber-Jars. But the assembly plugin worked great.<\/p>\n\n\n\n<p>My example main class is pretty simple. Just a few lines to demonstrate the use case.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">[codesyntax lang=\"java\"]\n&lt;pre>package de.viaboxx.itext;\n \nimport com.lowagie.text.Document;\nimport com.lowagie.text.Paragraph;\nimport com.lowagie.text.pdf.PdfWriter;\n \nimport java.io.FileOutputStream;\n \npublic class Main {\n    public static void main(String[] args) {\n        try {\n            Document document = new Document();\n            PdfWriter.getInstance(document, new FileOutputStream(\"hello.pdf\"));\n            document.open();\n            document.add(new Paragraph(\"Hello\"));\n            document.close();\n        } catch (Exception e) {\n            e.printStackTrace();\n        }\n    }\n}&lt;\/pre>\n[\/codesyntax]<\/pre>\n\n\n\n<p>To package it run:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">&lt;div>\n&lt;div id=\"highlighter_582527\" class=\"syntaxhighlighter  plain\">&lt;code class=\"plain plain\">mvn install&lt;\/code>&lt;\/div>\n&lt;\/div><\/pre>\n\n\n\n<p>You will find a file with the Name *-jar-with-dependencies.jar in the target folder.<br>To run it, call:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">java -jar NAME-jar-with-dependencies.jar<\/pre>\n\n\n\n<p>Maven is a little bit verbose in its, but you can copy and paste the functionality most of the time.<\/p>\n\n\n\n<p>Another useful command is the execution of the Main class directly from Maven (if you don\u2019t want to package it):<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">mvn compile\nmvn exec:java -Dexec.mainClass=\"de.viaboxx.itext.Main\"\n<\/pre>\n\n\n\n<p>Download the full project as <a href=\"\/wp-content\/uploads\/2014\/06\/itext-with-maven.zip\">ZIP<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Sometimes you are not working in the big enterprise project with thousand lines of code. You just want to play with a new library or a [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_uag_custom_page_level_css":"","site-sidebar-layout":"default","site-content-layout":"default","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"default","adv-header-id-meta":"","stick-header-meta":"default","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[76],"tags":[],"class_list":["post-2263","post","type-post","status-publish","format-standard","hentry","category-code"],"uagb_featured_image_src":{"full":false,"thumbnail":false,"medium":false,"medium_large":false,"large":false,"1536x1536":false,"2048x2048":false},"uagb_author_info":{"display_name":"Simon Tiffert","author_link":"https:\/\/www.viaboxx.de\/en\/blog\/author\/simon-tiffertviaboxx-de\/"},"uagb_comment_info":0,"uagb_excerpt":"Sometimes you are not working in the big enterprise project with thousand lines of code. You just want to play with a new library or a [&hellip;]","_links":{"self":[{"href":"https:\/\/www.viaboxx.de\/en\/wp-json\/wp\/v2\/posts\/2263"}],"collection":[{"href":"https:\/\/www.viaboxx.de\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.viaboxx.de\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.viaboxx.de\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.viaboxx.de\/en\/wp-json\/wp\/v2\/comments?post=2263"}],"version-history":[{"count":2,"href":"https:\/\/www.viaboxx.de\/en\/wp-json\/wp\/v2\/posts\/2263\/revisions"}],"predecessor-version":[{"id":7063,"href":"https:\/\/www.viaboxx.de\/en\/wp-json\/wp\/v2\/posts\/2263\/revisions\/7063"}],"wp:attachment":[{"href":"https:\/\/www.viaboxx.de\/en\/wp-json\/wp\/v2\/media?parent=2263"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.viaboxx.de\/en\/wp-json\/wp\/v2\/categories?post=2263"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.viaboxx.de\/en\/wp-json\/wp\/v2\/tags?post=2263"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}