search

Home  >  Q&A  >  body text

intellij-idea - 使用IDEA 打包 java程序,包括图片、配置文件等

我用IDEA写了个java小程序,想打包成可执行的jar文件,发到别的电脑使用。
但是打包老是出问题,不是运行不了就是运行了之后,没有图标和我另外加入的图片。
还有个问题就是我给程序增加了配置文件,但是打包的时候被打包到jar里面去了,导致我无法修改配置文件。
麻烦大家有遇到这方面问题或者有经验的帮忙解答一下。

伊谢尔伦伊谢尔伦2820 days ago1030

reply all(2)I'll reply

  • 天蓬老师

    天蓬老师2017-04-17 17:20:07

    maven project:
    Use the maven-assembly-plugin plug-in
    For usage, please refer to http://www.infoq.com/cn/news/2011/06/xxb-maven-9-package
    For example,
    assembly.xml needs to be The configuration file is packaged in a separate folder and can be configured as follows
    <assembly>

    <id>assembly</id>
    <formats>
        <format>tar.gz</format>
    </formats>
    <includeBaseDirectory>true</includeBaseDirectory>
    <fileSets>
        <fileSet>
            <directory>src/main/assembly/bin</directory>
            <outputDirectory>bin</outputDirectory>
            <fileMode>0755</fileMode>
        </fileSet>
        <fileSet>
            <directory>src/main/resources/${package.environment}</directory>
            <outputDirectory>conf</outputDirectory>
            <fileMode>0644</fileMode>
        </fileSet>
        <fileSet>
            <directory>lib/</directory>
            <outputDirectory>lib</outputDirectory>
        </fileSet>
    </fileSets>
    <dependencySets>
        <dependencySet>
            <outputDirectory>lib</outputDirectory>
        </dependencySet>
    </dependencySets>

    </assembly>
    When writing the bin startup script, you need to include the conf directory in the classpath

    reply
    0
  • 阿神

    阿神2017-04-17 17:20:07

    It would be more troublesome to package the resources yourself. For various configurations, you can try spring-boot

    reply
    0
  • Cancelreply