{"id":475,"date":"2013-02-08T05:51:24","date_gmt":"2013-02-08T08:51:24","guid":{"rendered":"https:\/\/www.semeru.com.br\/blog\/?p=475"},"modified":"2022-12-20T21:21:31","modified_gmt":"2022-12-21T00:21:31","slug":"gerando-um-jar-com-as-dependencias-em-um-projeto-maven","status":"publish","type":"post","link":"https:\/\/www.semeru.com.br\/blog\/gerando-um-jar-com-as-dependencias-em-um-projeto-maven\/","title":{"rendered":"Gerando um .jar com as depend\u00eancias em um projeto Maven"},"content":{"rendered":"<p>Uma das coisas mais incovenientes para iniciantes em Maven \u00e9 ao gerar um .jar da aplica\u00e7\u00e3o as depend\u00eancias n\u00e3o serem inclu\u00eddas no .jar final ou o .jar n\u00e3o inicializar a execu\u00e7\u00e3o. Entretanto algumas configura\u00e7\u00f5es bem simples podem resolver esse problema e incluir as depend\u00eancias corretamente. Aproveitamos o projeto do <a href=\"https:\/\/www.semeru.com.br\/blog\/?p=439\">post anterior<\/a> e adicionamos o trecho que c\u00f3digo abaixo.<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\n&lt;!-- CONFIGURA\u00c7\u00d5ES DE BUILD RESPONS\u00c1VEIS POR INCLUIR AS DEPEND\u00caNCIAS NO .JAR FINAL --&gt;\n\n&lt;build&gt;\n    &lt;plugins&gt;\n       &lt;!-- DEFINE O PLUGIN MAVEN RESPONS\u00c1VEL POR COMPILAR O PROJETO SUA VERS\u00c3O E O JDK UTILIZADO  --&gt;\n       &lt;plugin&gt;\n            &lt;groupid&gt;org.apache.maven.plugins&lt;\/groupid&gt;\n            &lt;artifactid&gt;maven-compiler-plugin&lt;\/artifactid&gt;\n            &lt;version&gt;2.3.2&lt;\/version&gt;\n            &lt;configuration&gt;\n                &lt;source&gt;1.6\n                &lt;target&gt;1.6&lt;\/target&gt;\n            &lt;\/configuration&gt;\n        &lt;\/plugin&gt;  \n\n        &lt;!-- DEFINE AS CONFIGURA\u00c7\u00d5ES DO MAVEN ASSEMBLER  --&gt;\n        &lt;plugin&gt;\n            &lt;artifactid&gt;maven-assembly-plugin&lt;\/artifactid&gt;\n            &lt;configuration&gt;\n                &lt;archive&gt;\n\n                   &lt;!-- DEFINE QUAL \u00c9 A CLASSE MAIN DA APLICA\u00c7\u00c3O  --&gt;\n                    &lt;manifest&gt;\n                        &lt;addclasspath&gt;true&lt;\/addclasspath&gt;\n                        &lt;mainclass&gt;br.com.semeru.datesynchronizer.RecoveryDateWitchURL&lt;\/mainclass&gt;\n                    &lt;\/manifest&gt;\n                &lt;\/archive&gt;\n\n                &lt;!-- ADICIONO AO NOME DO JAR FINAL UM COMPLEMENTO DIZENDO\n                     QUE ELE CONT\u00c9M AS DEPEND\u00caNCIAS  --&gt;\n\n                &lt;descriptorrefs&gt;\n                    &lt;descriptorref&gt;jar-with-dependencies&lt;\/descriptorref&gt;\n                &lt;\/descriptorrefs&gt;\n            &lt;\/configuration&gt;\n            &lt;executions&gt;\n                &lt;execution&gt;\n\n                    &lt;!-- DETERMINO QUE O JAR GERADO INCLUIR\u00c1 AS DEPEND\u00caNCIAS E ELAS \n                    SER\u00c3O EMPACOTADAS JUNTO COM O PROJETO EM UM \u00daNICO JAR  --&gt;\n\n                    &lt;id&gt;make-my-jar-with-dependencies&lt;\/id&gt;\n                    &lt;phase&gt;package&lt;\/phase&gt;\n                    &lt;goals&gt;\n                        &lt;goal&gt;single&lt;\/goal&gt;\n                    &lt;\/goals&gt;\n                &lt;\/execution&gt;\n            &lt;\/executions&gt;\n        &lt;\/plugin&gt;\n    &lt;\/plugins&gt;\n&lt;\/build&gt;\n<\/pre>\n<p>Ap\u00f3s executarmos a build veremos algo similar a imagem abaixo, s\u00e3o criados dois .jars um com e outro sem as depend\u00eancias. Esse jar pode ser startado por duplo clique, pelo DOS ou pelo Shell do GNU\/Linux.<\/p>\n<p><a href=\"https:\/\/www.semeru.com.br\/blog\/gerando-um-jar-com-as-dependencias-em-um-projeto-maven\/mavenwithdependencies\/\" rel=\"attachment wp-att-476\"><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter size-full wp-image-476\" src=\"https:\/\/www.semeru.com.br\/blog\/wp-content\/uploads\/2013\/01\/MavenWithDependencies.png\" alt=\"MavenWithDependencies\" width=\"756\" height=\"209\" srcset=\"https:\/\/www.semeru.com.br\/blog\/wp-content\/uploads\/2013\/01\/MavenWithDependencies.png 945w, https:\/\/www.semeru.com.br\/blog\/wp-content\/uploads\/2013\/01\/MavenWithDependencies-300x82.png 300w\" sizes=\"(max-width: 756px) 100vw, 756px\" \/><\/a><\/p>\n<p>Al\u00e9m disso se abrirmos o jar com uma ferramenta como o winrar veremos que al\u00e9m das classes no nosso projeto, assinalados em vermelho, temos tamb\u00e9m outros diret\u00f3rios, assinalados em azul, contendo as depend\u00eancias e as classes compiladas das mesmas como podemos observar nos pontos indicados pelas setas.<\/p>\n<p><a href=\"https:\/\/www.semeru.com.br\/blog\/gerando-um-jar-com-as-dependencias-em-um-projeto-maven\/mavenwithdependencies2\/\" rel=\"attachment wp-att-477\"><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter size-full wp-image-477\" src=\"https:\/\/www.semeru.com.br\/blog\/wp-content\/uploads\/2013\/01\/MavenWithDependencies2.png\" alt=\"MavenWithDependencies2\" width=\"667\" height=\"540\" srcset=\"https:\/\/www.semeru.com.br\/blog\/wp-content\/uploads\/2013\/01\/MavenWithDependencies2.png 833w, https:\/\/www.semeru.com.br\/blog\/wp-content\/uploads\/2013\/01\/MavenWithDependencies2-300x242.png 300w\" sizes=\"(max-width: 667px) 100vw, 667px\" \/><\/a><\/p>\n<p>Se voc\u00ea tem alguma d\u00favida relacionada ao conte\u00fado desse post sinta-se a vontade de comentar, criticar e\/ou contribuir com o seu coment\u00e1rio. Al\u00e9m disso voc\u00ea pode acessar todo o c\u00f3digo fonte desse projeto atrav\u00e9s do <a href=\"https:\/\/github.com\/leandrocgsi\/DateSynchronizer\">GitHub<\/a>.<\/p>\n<h2>Treinamentos relacionados com este post<\/h2>\n<p><a href=\"https:\/\/pub.erudio.com.br\/kr\/blog_rest_spring_java\" target=\"_blank\" rel=\"noopener\"><\/p>\n<p><img decoding=\"async\" style=\"max-width: 100%;\" title=\"REST API's RESTFul do 0 \u00e0  AWS com Spring Boot 3, Java e Docker\" src=\"https:\/\/raw.githubusercontent.com\/leandrocgsi\/blog-images\/main\/07-rest-spring-java.png\"><br \/>\n<\/a><\/p>\n<p><a href=\"https:\/\/pub.erudio.com.br\/kr\/blog_microservices_java\" target=\"_blank\" rel=\"noopener\"><br \/>\n        <img decoding=\"async\" style=\"max-width: 100%;\" title=\"Microservices do 0 com Spring Cloud, Spring Boot e Docker\" src=\"https:\/\/raw.githubusercontent.com\/leandrocgsi\/blog-images\/main\/14-microservices-java.png\"><br \/>\n<\/a><\/p>\n<p><a href=\"https:\/\/pub.erudio.com.br\/kr\/blog_rest_spring_kotlin\" target=\"_blank\" rel=\"noopener\"><br \/>\n        <img decoding=\"async\" style=\"max-width: 100%;\" title=\"REST API's RESTFul do 0 \u00e0 AWS com Spring Boot 3, Kotlin e Docker\" src=\"https:\/\/raw.githubusercontent.com\/leandrocgsi\/blog-images\/main\/18-rest-spring-kotlin.png\"><br \/>\n<\/a><\/p>\n<p><a href=\"https:\/\/pub.erudio.com.br\/kr\/blog_ms_kotlin\" target=\"_blank\" rel=\"noopener\"><br \/>\n        <img decoding=\"async\" style=\"max-width: 100%;\" title=\"Microsservi\u00e7os do 0 com Spring Cloud, Kotlin e Docker\" src=\"https:\/\/raw.githubusercontent.com\/leandrocgsi\/blog-images\/main\/22-ms-kotlin.png\"><br \/>\n<\/a><\/p>\n<p><a href=\"https:\/\/pub.erudio.com.br\/kr\/blog_docker\" target=\"_blank\" rel=\"noopener\"><br \/>\n        <img decoding=\"async\" style=\"max-width: 100%;\" title=\"Docker do 0 \u00e0 Maestria: Cont\u00eaineres Desmistificados mais 3 B\u00d4NUS\" src=\"https:\/\/raw.githubusercontent.com\/leandrocgsi\/blog-images\/main\/09-docker.png\"><br \/>\n<\/a><\/p>\n<p><a href=\"https:\/\/pub.erudio.com.br\/kr\/blog_docker_para_aws\" target=\"_blank\" rel=\"noopener\"><br \/>\n        <img decoding=\"async\" style=\"max-width: 100%;\" title=\"Docker para Amazon AWS Implante Apps Java e .NET com Travis CI\" src=\"https:\/\/raw.githubusercontent.com\/leandrocgsi\/blog-images\/main\/10-docker-to-aws.png\"><br \/>\n<\/a><\/p>\n<p><a href=\"https:\/\/pub.erudio.com.br\/kr\/blog_kotlin\" target=\"_blank\" rel=\"noopener\"><br \/>\n        <img decoding=\"async\" style=\"max-width: 100%;\" title=\"Kotlin para DEVs Java: Aprenda a Linguagem Padr\u00e3o do Android\" src=\"https:\/\/raw.githubusercontent.com\/leandrocgsi\/blog-images\/main\/20-kotlin.png\"><br \/>\n<\/a><\/p>\n<div align=\"right\"><div class=\"sharexyWidgetNoindexUniqueClassName\"><div id=\"shr_48112038\"><\/div><\/div><\/div>","protected":false},"excerpt":{"rendered":"<p>Uma das coisas mais incovenientes para iniciantes em Maven \u00e9 ao gerar um .jar da aplica\u00e7\u00e3o as depend\u00eancias n\u00e3o serem inclu\u00eddas no .jar final ou o .jar n\u00e3o inicializar a execu\u00e7\u00e3o. Entretanto algumas configura\u00e7\u00f5es bem simples podem resolver esse problema e incluir as depend\u00eancias corretamente. Aproveitamos o projeto do post anterior e adicionamos o trecho [&#8230;]<\/p>\n<div align=\"right\">\n<div class=\"sharexyWidgetNoindexUniqueClassName\">\n<div id=\"shr_48112038\"><\/div>\n<\/div>\n<\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[86,93],"tags":[176,183],"_links":{"self":[{"href":"https:\/\/www.semeru.com.br\/blog\/wp-json\/wp\/v2\/posts\/475"}],"collection":[{"href":"https:\/\/www.semeru.com.br\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.semeru.com.br\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.semeru.com.br\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.semeru.com.br\/blog\/wp-json\/wp\/v2\/comments?post=475"}],"version-history":[{"count":19,"href":"https:\/\/www.semeru.com.br\/blog\/wp-json\/wp\/v2\/posts\/475\/revisions"}],"predecessor-version":[{"id":1433,"href":"https:\/\/www.semeru.com.br\/blog\/wp-json\/wp\/v2\/posts\/475\/revisions\/1433"}],"wp:attachment":[{"href":"https:\/\/www.semeru.com.br\/blog\/wp-json\/wp\/v2\/media?parent=475"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.semeru.com.br\/blog\/wp-json\/wp\/v2\/categories?post=475"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.semeru.com.br\/blog\/wp-json\/wp\/v2\/tags?post=475"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}