{"id":1993,"date":"2017-03-24T11:56:17","date_gmt":"2017-03-24T06:26:17","guid":{"rendered":"https:\/\/www.wikitechy.com\/technology\/?p=1993"},"modified":"2017-03-28T16:40:47","modified_gmt":"2017-03-28T11:10:47","slug":"create-executable-jar-dependencies-using-maven","status":"publish","type":"post","link":"https:\/\/www.wikitechy.com\/technology\/create-executable-jar-dependencies-using-maven\/","title":{"rendered":"JAVA &#8211; How to create an executable JAR with dependencies using Maven"},"content":{"rendered":"<h4 id=\"maven\"><span style=\"color: #800000;\"><b>Maven<\/b><\/span><\/h4>\n<ul>\n<li>Mavenis a powerful project management tool that is based on POM (project object model). It is used for projects build, dependency and documentation.<\/li>\n<li>It simplifies the build process like ANT. But it is too much advanced than ANT.<\/li>\n<li>Current version of Maven is 3.<\/li>\n<\/ul>\n<h4 id=\"a-jar-java-archive\"><span style=\"color: #ff6600;\"><b>A JAR (Java <\/b><b>ARchive<\/b><b>)<\/b><\/span><\/h4>\n<ul>\n<li>JAR is a package file format typically used to aggregate many Java class files and associated metadata and resources (text, images, etc.) into one file for distribution.<\/li>\n<\/ul>\n<h4 id=\"to-create-a-jar-file-with-maven\"><span style=\"color: #000000;\"><b>TO CREATE A JAR FILE WITH MAVEN<\/b><\/span><\/h4>\n<p><span style=\"color: #000000;\"><u><b>Create a simple Java project<\/b><\/u><\/span><\/p>\n<ul>\n<li>Create a Java project from the Maven quick start template.<\/li>\n<\/ul>\n[pastacode lang=\u201djavascript\u201d manual=\u201d%24%20mvn%20archetype%3Agenerate%20-DgroupId%3Dcom.wikitechy.core.utils%20-DartifactId%3DdateUtils%0A%20-DarchetypeArtifactId%3Dmaven-archetype-quickstart%20-DinteractiveMode%3Dfalse%0A\u201d message=\u201djavascript code\u201d highlight=\u201d\u201d provider=\u201dmanual\u201d\/]\n[ad type=\u201dbanner\u201d]\n<ul>\n<li>The following files and folder structure will be created.<\/li>\n<\/ul>\n[pastacode lang=\u201dcss\u201d manual=\u201d.%0A%7C____dateUtils%0A%7C%20%7C____pom.xml%0A%7C%20%7C____src%0A%7C%20%7C%20%7C____main%0A%7C%20%7C%20%7C%20%7C____java%0A%7C%20%7C%20%7C%20%7C%20%7C____com%0A%7C%20%7C%20%7C%20%7C%20%7C%20%7C____wikitechy%0A%7C%20%7C%20%7C%20%7C%20%7C%20%7C%20%7C____core%0A%7C%20%7C%20%7C%20%7C%20%7C%20%7C%20%7C%20%7C____utils%0A%7C%20%7C%20%7C%20%7C%20%7C%20%7C%20%7C%20%7C%20%7C____App.java%0A%7C%20%7C%20%7C____test%0A%7C%20%7C%20%7C%20%7C____java%0A%7C%20%7C%20%7C%20%7C%20%7C____com%0A%7C%20%7C%20%7C%20%7C%20%7C%20%7C____wikitechy%0A%7C%20%7C%20%7C%20%7C%20%7C%20%7C%20%7C____core%0A%7C%20%7C%20%7C%20%7C%20%7C%20%7C%20%7C%20%7C____utils%0A%7C%20%7C%20%7C%20%7C%20%7C%20%7C%20%7C%20%7C%20%7C____AppTest.java%0A\u201d message=\u201dcss code\u201d highlight=\u201d\u201d provider=\u201dmanual\u201d\/]\n<p>Above folder structure is not enough, <b>create a log4j.properties file <\/b>and put it in <b>src<\/b><b>\/main\/resources\/log4j.properties<\/b>, just create the resources folder manually.<\/p>\n<h4 id=\"log4j-properties\"><span style=\"color: #000000;\"><b>log4j.properties<\/b><\/span><\/h4>\n[pastacode lang=\u201djava\u201d manual=\u201d%23%20Root%20logger%20option%0Alog4j.rootLogger%3DDEBUG%2C%20stdout%0A%0A%23%20Direct%20log%20messages%20to%20stdout%0Alog4j.appender.stdout%3Dorg.apache.log4j.ConsoleAppender%0Alog4j.appender.stdout.layout%3Dorg.apache.log4j.PatternLayout%0Alog4j.appender.stdout.layout.ConversionPattern%3D%25d%7BABSOLUTE%7D%20%255p%20%25c%7B1%7D%3A%25L%20-%20%25m%25n%0A\u201d message=\u201djava code\u201d highlight=\u201d\u201d provider=\u201dmanual\u201d\/]\n<h4 id=\"make-it-support-eclipse\"><span style=\"color: #000000;\"><b>Make it support Eclipse.<\/b><\/span><\/h4>\n[pastacode lang=\u201djava\u201d manual=\u201d%24%20mvn%20eclipse%3Aeclipse%0A\u201d message=\u201djava code\u201d highlight=\u201d\u201d provider=\u201dmanual\u201d\/]\n[ad type=\u201dbanner\u201d]\n<h4 id=\"update-pom-xml\"><span style=\"color: #000000;\"><b>Update Pom.xml<\/b><\/span><\/h4>\n<p>Update pom.xml to declare both <b>log4j<\/b> and the <b>jodatime<\/b><b> dependencies<\/b>, for output to a jar format, make sure the packaging is set to \u201cjar\u201d.<\/p>\n<h4 id=\"pom-xml\"><span style=\"color: #0000ff;\"><b>pom.xml<\/b><\/span><\/h4>\n[pastacode lang=\u201dmarkup\u201d manual=\u201d%3Cproject%20xmlns%3D%22http%3A%2F%2Fmaven.apache.org%2FPOM%2F4.0.0%22%0A%09xmlns%3Axsi%3D%22http%3A%2F%2Fwww.w3.org%2F2001%2FXMLSchema-instance%22%0A%09xsi%3AschemaLocation%3D%22http%3A%2F%2Fmaven.apache.org%2FPOM%2F4.0.0%0A%09http%3A%2F%2Fmaven.apache.org%2Fmaven-v4_0_0.xsd%22%3E%0A%09%3CmodelVersion%3E4.0.0%3C%2FmodelVersion%3E%0A%09%3CgroupId%3Ecom.wikitechy.core.utils%3C%2FgroupId%3E%0A%09%3CartifactId%3EdateUtils%3C%2FartifactId%3E%0A%3C!\u2013%20Output%20to%20jar%20format%20\u2013%3E%0A%09%3Cpackaging%3Ejar%3C%2Fpackaging%3E%0A%0A%09%3Cversion%3E1.0-SNAPSHOT%3C%2Fversion%3E%0A%09%3Cname%3EdateUtils%3C%2Fname%3E%0A%09%3Curl%3Ehttp%3A%2F%2Fmaven.apache.org%3C%2Furl%3E%0A%3Cproperties%3E%0A%09%09%3Cjdk.version%3E1.7%3C%2Fjdk.version%3E%0A%09%09%3Cjodatime.version%3E2.5%3C%2Fjodatime.version%3E%0A%09%09%3Cjunit.version%3E4.11%3C%2Fjunit.version%3E%0A%09%09%3Clog4j.version%3E1.2.17%3C%2Flog4j.version%3E%0A%09%3C%2Fproperties%3E%0A%0A%09%3Cdependencies%3E%0A%09%09%3Cdependency%3E%0A%09%09%09%3CgroupId%3Ejunit%3C%2FgroupId%3E%0A%09%09%09%3CartifactId%3Ejunit%3C%2FartifactId%3E%0A%09%09%09%3Cversion%3E%24%7Bjunit.version%7D%3C%2Fversion%3E%0A%09%09%09%3Cscope%3Etest%3C%2Fscope%3E%0A%09%09%3C%2Fdependency%3E%0A%09%09%3Cdependency%3E%0A%09%09%09%3CgroupId%3Ejoda-time%3C%2FgroupId%3E%0A%09%09%09%3CartifactId%3Ejoda-time%3C%2FartifactId%3E%0A%09%09%09%3Cversion%3E%24%7Bjodatime.version%7D%3C%2Fversion%3E%0A%09%09%3C%2Fdependency%3E%0A%3Cdependency%3E%0A%09%09%09%3CgroupId%3Elog4j%3C%2FgroupId%3E%0A%09%09%09%3CartifactId%3Elog4j%3C%2FartifactId%3E%0A%09%09%09%3Cversion%3E%24%7Blog4j.version%7D%3C%2Fversion%3E%0A%09%09%3C%2Fdependency%3E%0A%09%3C%2Fdependencies%3E%0A%0A%09%3Cbuild%3E%0A%09%09%3CfinalName%3Edateutils%3C%2FfinalName%3E%0A%09%09%3Cplugins%3E%0A%0A%09%09%09%3C!\u2013%20download%20source%20code%20in%20Eclipse%2C%20best%20practice%20\u2013%3E%0A%09%09%09%3Cplugin%3E%0A%09%09%09%09%3CgroupId%3Eorg.apache.maven.plugins%3C%2FgroupId%3E%0A%09%09%09%09%3CartifactId%3Emaven-eclipse-plugin%3C%2FartifactId%3E%0A%09%09%09%09%3Cversion%3E2.9%3C%2Fversion%3E%0A%09%09%09%09%3Cconfiguration%3E%0A%09%09%09%09%09%3CdownloadSources%3Etrue%3C%2FdownloadSources%3E%0A%09%09%09%09%09%3CdownloadJavadocs%3Efalse%3C%2FdownloadJavadocs%3E%0A%09%09%09%09%3C%2Fconfiguration%3E%0A%09%09%09%3C%2Fplugin%3E%0A%3C!\u2013%20Set%20a%20JDK%20compiler%20level%20\u2013%3E%0A%09%09%09%3Cplugin%3E%0A%09%09%09%09%3CgroupId%3Eorg.apache.maven.plugins%3C%2FgroupId%3E%0A%09%09%09%09%3CartifactId%3Emaven-compiler-plugin%3C%2FartifactId%3E%0A%09%09%09%09%3Cversion%3E2.3.2%3C%2Fversion%3E%0A%09%09%09%09%3Cconfiguration%3E%0A%09%09%09%09%09%3Csource%3E%24%7Bjdk.version%7D%3C%2Fsource%3E%0A%09%09%09%09%09%3Ctarget%3E%24%7Bjdk.version%7D%3C%2Ftarget%3E%0A%09%09%09%09%3C%2Fconfiguration%3E%0A%09%09%09%3C%2Fplugin%3E%0A%0A%09%09%09%3C!\u2013%20Make%20this%20jar%20executable%20\u2013%3E%0A%09%09%09%3Cplugin%3E%0A%09%09%09%09%3CgroupId%3Eorg.apache.maven.plugins%3C%2FgroupId%3E%0A%09%09%09%09%3CartifactId%3Emaven-jar-plugin%3C%2FartifactId%3E%0A%09%09%09%09%3Cconfiguration%3E%0A%3C!\u2013%20DO%20NOT%20include%20log4j.properties%20file%20in%20our%20Jar%20\u2013%3E%0A%09%09%09%09%20%20%3Cexcludes%3E%0A%09%09%09%09%09%3Cexclude%3E**%2Flog4j.properties%3C%2Fexclude%3E%0A%09%09%09%09%20%20%3C%2Fexcludes%3E%0A%09%09%09%09%20%20%3Carchive%3E%0A%09%09%09%09%09%3Cmanifest%3E%0A%3C!\u2013%20Jar%20file%20entry%20point%20\u2013%3E%0A%09%09%09%09%09%09%3CmainClass%3Ecom.wikitechy.core.utils.App%3C%2FmainClass%3E%0A%09%09%09%09%09%3C%2Fmanifest%3E%0A%09%09%09%09%20%20%3C%2Farchive%3E%0A%09%09%09%09%3C%2Fconfiguration%3E%0A%09%09%09%3C%2Fplugin%3E%0A%0A%09%09%3C%2Fplugins%3E%0A%09%3C%2Fbuild%3E%0A%0A%3C%2Fproject%3E%0A\u201d message=\u201dhtml code\u201d highlight=\u201d\u201d provider=\u201dmanual\u201d\/]\n<h4 id=\"update-app-java\"><span style=\"color: #000000;\"><b>Update App.java<\/b><\/span><\/h4>\n<h4 id=\"app-java\"><span style=\"color: #000000;\"><b>App.java<\/b><\/span><\/h4>\n[pastacode lang=\u201djava\u201d manual=\u201dpackage%20com.wikitechy.core.utils%3B%0A%0Aimport%20org.apache.log4j.Logger%3B%0Aimport%20org.joda.time.LocalDate%3B%0A%0Apublic%20class%20App%20%0A%7B%0A%0A%09private%20static%20final%20Logger%20logger%20%3D%20Logger.getLogger(App.class)%3B%0A%0A%09public%20static%20void%20main(String%5B%5D%20args)%0A%20%7B%0A%09%09System.out.println(getLocalCurrentDate())%3B%0A%7D%0Aprivate%20static%20String%20getLocalCurrentDate()%20%7B%0A%0A%09%09if%20(logger.isDebugEnabled())%20%7B%0A%09%09%09logger.debug(%22getLocalCurrentDate()%20is%20executed!%22)%3B%0A%09%09%7D%0A%0A%09%09LocalDate%20date%20%3D%20new%20LocalDate()%3B%0A%09%09return%20date.toString()%3B%0A%0A%09%7D%0A%0A%7D%0A\u201d message=\u201djava code\u201d highlight=\u201d\u201d provider=\u201dmanual\u201d\/]\n<ul>\n<li>Thus this project has two dependencies : <b>log4j <\/b>and <b>jodatime<\/b>.<\/li>\n<\/ul>\n<h4 id=\"working-with-dependencies\"><span style=\"color: #000000;\"><b>Working with Dependencies<\/b><\/span><\/h4>\n<h4 id=\"how-to-add-dependencies-in-a-jar\"><span style=\"color: #000000;\"><b>How to add dependencies in a jar<\/b><\/span><\/h4>\n<ul>\n<li>we can put both log4j.jar and jodatime.jar inside the final.jar, but our classes are unable to call other classes which is inside the unpack log4j.jar, Java jar is designed like this, unless we can create a special class loader like one-jar plugin.<\/li>\n<li>Alternatively, use maven-assembly-plugin to extract all dependency jars into raw classes, and group it together.<\/li>\n<li>Try one-jar plugin, it will create a fat-jar, which includes the entire project\u2019s dependencies into a single jar file.<b><br \/>\n<\/b><\/li>\n<\/ul>\n<h4 id=\"solution\"><span style=\"color: #000000;\"><b>Solution<\/b><\/span><\/h4>\n<ul>\n<li>Copy the entire project\u2019s dependencies to a pre-defined folder, and define the dependency class path in the jar\u2019s manifest file.<\/li>\n<li>The updated and final pom.xml, to use maven-dependency-plugin to copy all dependencies to target\/dependency-jars\/ folder, and use maven-jar-plugin to add the dependency class path.<\/li>\n<\/ul>\n<h4 id=\"pom-xml-2\"><span style=\"color: #000000;\"><b>pom.xml<\/b><\/span><\/h4>\n[pastacode lang=\u201dmarkup\u201d manual=\u201d%3Cproject%20xmlns%3D%22http%3A%2F%2Fmaven.apache.org%2FPOM%2F4.0.0%22%0A%09xmlns%3Axsi%3D%22http%3A%2F%2Fwww.w3.org%2F2001%2FXMLSchema-instance%22%0A%09xsi%3AschemaLocation%3D%22http%3A%2F%2Fmaven.apache.org%2FPOM%2F4.0.0%0A%09http%3A%2F%2Fmaven.apache.org%2Fmaven-v4_0_0.xsd%22%3E%0A%09%3CmodelVersion%3E4.0.0%3C%2FmodelVersion%3E%0A%09%3CgroupId%3Ecom.wikitechy.core.utils%3C%2FgroupId%3E%0A%09%3CartifactId%3EdateUtils%3C%2FartifactId%3E%0A%09%3Cpackaging%3Ejar%3C%2Fpackaging%3E%0A%09%3Cversion%3E1.0-SNAPSHOT%3C%2Fversion%3E%0A%09%3Cname%3EdateUtils%3C%2Fname%3E%0A%09%3Curl%3Ehttp%3A%2F%2Fmaven.apache.org%3C%2Furl%3E%0A%3Cproperties%3E%0A%09%09%3Cjdk.version%3E1.7%3C%2Fjdk.version%3E%0A%09%09%3Cjodatime.version%3E2.5%3C%2Fjodatime.version%3E%0A%09%09%3Cjunit.version%3E4.11%3C%2Fjunit.version%3E%0A%09%09%3Clog4j.version%3E1.2.17%3C%2Flog4j.version%3E%0A%09%09%3C%2Fproperties%3E%0A%3Cdependencies%3E%0A%09%09%3Cdependency%3E%0A%09%09%09%3CgroupId%3Ejunit%3C%2FgroupId%3E%0A%09%09%09%3CartifactId%3Ejunit%3C%2FartifactId%3E%0A%09%09%09%3Cversion%3E%24%7Bjunit.version%7D%3C%2Fversion%3E%0A%09%09%09%3Cscope%3Etest%3C%2Fscope%3E%0A%09%09%3C%2Fdependency%3E%0A%09%09%3Cdependency%3E%0A%09%09%09%3CgroupId%3Ejoda-time%3C%2FgroupId%3E%0A%09%09%09%3CartifactId%3Ejoda-time%3C%2FartifactId%3E%0A%09%09%09%3Cversion%3E%24%7Bjodatime.version%7D%3C%2Fversion%3E%0A%09%09%3C%2Fdependency%3E%0A%3Cdependency%3E%0A%09%09%09%3CgroupId%3Elog4j%3C%2FgroupId%3E%0A%09%09%09%3CartifactId%3Elog4j%3C%2FartifactId%3E%0A%09%09%09%3Cversion%3E%24%7Blog4j.version%7D%3C%2Fversion%3E%0A%09%09%3C%2Fdependency%3E%0A%09%3C%2Fdependencies%3E%0A%0A%09%3Cbuild%3E%0A%09%09%3CfinalName%3Edateutils%3C%2FfinalName%3E%0A%09%09%3Cplugins%3E%0A%0A%09%09%09%3C!\u2013%20download%20source%20code%20in%20Eclipse%2C%20best%20practice%20\u2013%3E%0A%09%09%09%3Cplugin%3E%0A%09%09%09%09%3CgroupId%3Eorg.apache.maven.plugins%3C%2FgroupId%3E%0A%09%09%09%09%3CartifactId%3Emaven-eclipse-plugin%3C%2FartifactId%3E%0A%09%09%09%09%3Cversion%3E2.9%3C%2Fversion%3E%0A%09%09%09%09%3Cconfiguration%3E%0A%09%09%09%09%09%3CdownloadSources%3Etrue%3C%2FdownloadSources%3E%0A%09%09%09%09%09%3CdownloadJavadocs%3Efalse%3C%2FdownloadJavadocs%3E%0A%09%09%09%09%3C%2Fconfiguration%3E%0A%09%09%09%3C%2Fplugin%3E%0A%3Cdependency%3E%0A%09%09%09%3CgroupId%3Elog4j%3C%2FgroupId%3E%0A%09%09%09%3CartifactId%3Elog4j%3C%2FartifactId%3E%0A%09%09%09%3Cversion%3E%24%7Blog4j.version%7D%3C%2Fversion%3E%0A%09%09%3C%2Fdependency%3E%0A%09%3C%2Fdependencies%3E%0A%0A%09%3Cbuild%3E%0A%09%09%3CfinalName%3Edateutils%3C%2FfinalName%3E%0A%09%09%3Cplugins%3E%0A%0A%09%09%09%3C!\u2013%20download%20source%20code%20in%20Eclipse%2C%20best%20practice%20\u2013%3E%0A%09%09%09%3Cplugin%3E%0A%09%09%09%09%3CgroupId%3Eorg.apache.maven.plugins%3C%2FgroupId%3E%0A%09%09%09%09%3CartifactId%3Emaven-eclipse-plugin%3C%2FartifactId%3E%0A%09%09%09%09%3Cversion%3E2.9%3C%2Fversion%3E%0A%09%09%09%09%3Cconfiguration%3E%0A%09%09%09%09%09%3CdownloadSources%3Etrue%3C%2FdownloadSources%3E%0A%09%09%09%09%09%3CdownloadJavadocs%3Efalse%3C%2FdownloadJavadocs%3E%0A%09%09%09%09%3C%2Fconfiguration%3E%0A%09%09%09%3C%2Fplugin%3E%0A%3C!\u2013%20Set%20a%20compiler%20level%20\u2013%3E%0A%09%09%09%3Cplugin%3E%0A%09%09%09%09%3CgroupId%3Eorg.apache.maven.plugins%3C%2FgroupId%3E%0A%09%09%09%09%3CartifactId%3Emaven-compiler-plugin%3C%2FartifactId%3E%0A%09%09%09%09%3Cversion%3E2.3.2%3C%2Fversion%3E%0A%09%09%09%09%3Cconfiguration%3E%0A%09%09%09%09%09%3Csource%3E%24%7Bjdk.version%7D%3C%2Fsource%3E%0A%09%09%09%09%09%3Ctarget%3E%24%7Bjdk.version%7D%3C%2Ftarget%3E%0A%09%09%09%09%3C%2Fconfiguration%3E%0A%09%09%09%3C%2Fplugin%3E%0A%3C!\u2013%20Make%20this%20jar%20executable%20\u2013%3E%0A%09%09%09%3Cplugin%3E%0A%09%09%09%09%3CgroupId%3Eorg.apache.maven.plugins%3C%2FgroupId%3E%0A%09%09%09%09%3CartifactId%3Emaven-jar-plugin%3C%2FartifactId%3E%0A%09%09%09%09%3Cconfiguration%3E%0A%09%09%09%09%20%20%3Cexcludes%3E%0A%09%09%09%09%09%3Cexclude%3E**%2Flog4j.properties%3C%2Fexclude%3E%0A%09%09%09%09%20%20%3C%2Fexcludes%3E%0A%3Carchive%3E%0A%3Cmanifest%3E%0A%3CaddClasspath%3Etrue%3C%2FaddClasspath%3E%0A%3CmainClass%3Ecom.wikitechy.core.utils.App%3C%2FmainClass%3E%0A%3CclasspathPrefix%3Edependency-jars%2F%3C%2FclasspathPrefix%3E%0A%3C%2Fmanifest%3E%0A%3C%2Farchive%3E%0A%3C%2Fconfiguration%3E%0A%3C%2Fplugin%3E%0A%0A%3C!\u2013%20Copy%20project%20dependency%20\u2013%3E%0A%09%09%09%3Cplugin%3E%0A%09%09%09%09%3CgroupId%3Eorg.apache.maven.plugins%3C%2FgroupId%3E%0A%09%09%09%09%3CartifactId%3Emaven-dependency-plugin%3C%2FartifactId%3E%0A%09%09%09%09%3Cversion%3E2.5.1%3C%2Fversion%3E%0A%09%09%09%09%3Cexecutions%3E%0A%09%09%09%09%20%3Cexecution%3E%0A%3Cid%3Ecopy-dependencies%3C%2Fid%3E%0A%09%09%09%09%09%3Cphase%3Epackage%3C%2Fphase%3E%0A%09%09%09%09%09%3Cgoals%3E%0A%09%09%09%09%09%09%3Cgoal%3Ecopy-dependencies%3C%2Fgoal%3E%0A%09%09%09%09%09%3C%2Fgoals%3E%0A%09%09%09%09%09%3Cconfiguration%3E%0A%20%3C!\u2013%20exclude%20junit%2C%20we%20need%20runtime%20dependency%20only%20\u2013%3E%0A%09%09%09%3CincludeScope%3Eruntime%3C%2FincludeScope%3E%0A%09%09%09%3CoutputDirectory%3E%24%7Bproject.build.directory%7D%2Fdependency-jars%2F%3C%2FoutputDirectory%3E%0A%09%09%09%09%09%3C%2Fconfiguration%3E%0A%09%09%09%09%20%20%3C%2Fexecution%3E%0A%09%09%09%09%3C%2Fexecutions%3E%0A%09%09%09%3C%2Fplugin%3E%0A%0A%09%09%3C%2Fplugins%3E%0A%09%3C%2Fbuild%3E%0A%0A%3C%2Fproject%3E%0A\u201d message=\u201dhtml code\u201d highlight=\u201d\u201d provider=\u201dmanual\u201d\/]\n[ad type=\u201dbanner\u201d]\n<h4 id=\"final-jar-file\"><span style=\"color: #000000;\"><b>final Jar file<\/b><\/span><\/h4>\n<h4 id=\"package\"><span style=\"color: #000000;\"><b>Package<\/b><\/span><\/h4>\n[pastacode lang=\u201djavascript\u201d manual=\u201d%24%20mvn%20package%0A\u201d message=\u201djavascript code\u201d highlight=\u201d\u201d provider=\u201dmanual\u201d\/]\n<ul>\n<li>Review the folder structure in the target folder<\/li>\n<\/ul>\n<p><img fetchpriority=\"high\" decoding=\"async\" class=\"wp-image-2000 size-full aligncenter\" src=\"https:\/\/www.wikitechy.com\/technology\/wp-content\/uploads\/2017\/03\/Pictureo.png\" alt=\"\" width=\"749\" height=\"304\" \/><\/p>\n<p>A dateutils.jar is created, and the entire project runtime dependencies (excluded junit) are copied to target\/dependency-jars\/ folder.<\/p>\n<h4 id=\"list-out-the-dateutils-jar-content\"><span style=\"color: #000000;\"><b>List out the dateutils.jar content :<\/b><\/span><\/h4>\n[pastacode lang=\u201djavascript\u201d manual=\u201d%24%20jar%20tf%20target%2Fdateutils.jar%0AMETA-INF%2F%0AMETA-INF%2FMANIFEST.MF%0Acom%2F%0Acom%2Fwikitechy%2F%0Acom%2Fwikitechy%2Fcore%2F%0Acom%2Fwikitechy%2Fcore%2Futils%2F%0Acom%2Fwikitechy%2Fcore%2Futils%2FApp.class%0AMETA-INF%2Fmaven%2F%0AMETA-INF%2Fmaven%2Fcom.wikitechy.core.utils%2F%0AMETA-INF%2Fmaven%2Fcom.wikitechy.core.utils%2FdateUtils%2F%0AMETA-INF%2Fmaven%2Fcom.wikitechy.core.utils%2FdateUtils%2Fpom.xml%0AMETA-INF%2Fmaven%2Fcom.wikitechy.core.utils%2FdateUtils%2Fpom.properties%0A%0A\u201d message=\u201djavascript code\u201d highlight=\u201d\u201d provider=\u201dmanual\u201d\/]\n<p><b>Extracts and review the content of MANIFEST.MF, the dependencies are added in the Class-Path.<\/b><\/p>\n[pastacode lang=\u201djavascript\u201d manual=\u201dMETA_INF%2FMANIFEST.MF%0AManifest-Version%3A%201.0%0ABuilt-By%3A%20wikitechy%0ABuild-Jdk%3A%201.7.0_05%0AClass-Path%3A%20dependency-jars%2Fjoda-time-2.5.jar%20dependency-jars%2Flog4j-1.2.17.jar%0ACreated-By%3A%20Apache%20Maven%203.1.1%0AMain-Class%3A%20com.wikitechy.core.utils.App%0AArchiver-Version%3A%20Plexus%20Archiver%0A\u201d message=\u201djavascript code\u201d highlight=\u201d\u201d provider=\u201dmanual\u201d\/]\n[ad type=\u201dbanner\u201d]\n<h4 id=\"run-it\"><span style=\"color: #000000;\"><b>Run it<\/b><\/span><\/h4>\n[pastacode lang=\u201djavascript\u201d manual=\u201d%24%20java%20-jar%20target%2Fdateutils.jar%0A%0Alog4j%3AWARN%20No%20appenders%20could%20be%20found%20for%20logger%20(com.wikitechy.core.utils.App).%0Alog4j%3AWARN%20Please%20initialize%20the%20log4j%20system%20properly.%0Alog4j%3AWARN%20See%20http%3A%2F%2Flogging.apache.org%2Flog4j%2F1.2%2Ffaq.html%23noconfig%20for%20more%20info.%0A2014-10-19%0A\u201d message=\u201djavascript code\u201d highlight=\u201d\u201d provider=\u201dmanual\u201d\/]\n<h4 id=\"where-is-log4j-properties\"><span style=\"color: #000000;\"><b>Where is log4j.properties?<\/b><\/span><\/h4>\n<p>To exclude the log4j.properties in the jar file, to avoid issues like multiple log4j.properties files in classpath.<\/p>\n<p>We can still pass in the log4j properties via the log4j.configuration system property like this :<\/p>\n[pastacode lang=\u201djavascript\u201d manual=\u201d%24%20java%20-jar%20-Dlog4j.configuration%3Dfile%3A%2Ffull_path%2Flog4j.properties%20target%2Fdateutils.jar%0A%0A17%3A09%3A15%2C385%20DEBUG%20App%3A18%20-%20getLocalCurrentDate()%20is%20executed!%0A\u201d message=\u201djavascript code\u201d highlight=\u201d\u201d provider=\u201dmanual\u201d\/]\n","protected":false},"excerpt":{"rendered":"<p>Maven Mavenis a powerful project management tool that is based on POM (project object model). It is used for projects build, dependency and documentation. It simplifies the build process like ANT. But it is too much advanced than ANT. Current version of Maven is 3. A JAR (Java ARchive) JAR is a package file format [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[26,24,275],"tags":[4251,4246,4253,4254,4249,4248,4242,4238,4240,4241,4244,4243,4239,4252,4245,4250,4247,2177],"class_list":["post-1993","post","type-post","status-publish","format-standard","hentry","category-css","category-html","category-javascript","tag-building-a-runnable-jar-with-maven-2","tag-can-i-add-jars-to-maven-2-build-classpath-without-installing-them","tag-how-can-i-create-an-executable-jar-without-dependencies-using-maven","tag-how-can-i-create-an-executable-jar-without-including-3pp-dependencies-using-maven","tag-including-dependencies-in-a-jar-with-maven","tag-java-how-do-i-build-standalone-distributions-of-maven-based-projects","tag-maven-assembly-plugin-include-dependency-jars","tag-maven-build-jar-with-dependencies-command-line","tag-maven-create-executable-jar-with-external-dependencies","tag-maven-jar-with-dependencies-example","tag-maven-maven-assembly-plugin","tag-maven-shade-plugin-executable-jar-with-dependencies","tag-maven-jar-plugin-include-dependencies","tag-maven-add-a-dependency-to-a-jar-by-relative-path","tag-onejar-maven-plugin","tag-problem-building-executable-jar-with-maven","tag-why-does-maven-have-such-a-bad-rep","tag-why-is-it-faster-to-process-a-sorted-array-than-an-unsorted-array"],"_links":{"self":[{"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/posts\/1993","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/comments?post=1993"}],"version-history":[{"count":0,"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/posts\/1993\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/media?parent=1993"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/categories?post=1993"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/tags?post=1993"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}