Create a single executable JAR from a Spring Based Java Application

前端 未结 4 1339
攒了一身酷
攒了一身酷 2020-12-30 10:22

I have a spring based application that does a component/package scan looking for packages within a certain namespace. The application runs perfectly in Eclipse and I\'d like

相关标签:
4条回答
  • 2020-12-30 10:54

    use Maven Shade Plugin for create uberjar. This could help you too.

    0 讨论(0)
  • 2020-12-30 10:55

    You can use your option 1 Maven Compile to a single jar with additional goal parameters.

    mvn clean package spring-boot:repackage
    

    It will create the standalone jar file with Spring autoload functionality.

    0 讨论(0)
  • 2020-12-30 11:00

    I just had the very same problem than you today, with doing exactly the same steps :)

    So thanks for your message, it makes me save some time and besides, i just want to quickly answer to your "Why it worked is still a mystery." sentence :

    "This is because I have several Spring Jar in my dependencies. Some of the spring jars contain meta info files with the same name. To avoid that some meta files are overridden you have to merge it"

    So this is why you need to add those two transformers to the maven snippet given into the Maven Shade Plugin documentation :

    <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer"
      <resource>META-INF/spring.handlers</resource>
    </transformer>
    <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer"
      <resource>META-INF/spring.schemas</resource>
    </transformer
    

    source : http://robert-reiz.com/2011/11/14/832/

    Hope it helps for understanding ;)

    0 讨论(0)
  • 2020-12-30 11:06

    try this one in eclipse: in the menu choose File -> Export -> Runnable JAR file

    in the specification window:(after filling other blanks properly) Library handling : Select the second one

    and Finish

    now try the following command in cmd or terminal: java -jar [your project's name]

    Hope it helps

    0 讨论(0)
提交回复
热议问题