weixin_43205269
weixin_43205269
采纳率66.7%
2019-01-29 14:46

java项目打包。问题不难,只是我急要。

80

项目用的maven,本地jar,以及资源文件。用的eclipse打jar包,但是要求资源文件必须导出的jar包同级。否则图片等资源文件加载不出来。

    要求提供合适的方法将资源本件整合到jar包里面,没必要把资源文件漏在外面。还保留Runable jar的风格,把所有import JAR放在JAR外面独立的一个文件夹。
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

2条回答

  • qq_21741673 洗洗脚泡泡澡 2年前

    pom.xml 打包用assembly插件

    <build>
            <finalName>${artifactId}</finalName>
            <plugins>
                <!-- jar打包相关插件 -->
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-jar-plugin</artifactId>
                    <version>2.4</version>
                    <configuration>
                        <archive>
                            <manifestEntries>
                                <Class-Path>conf/</Class-Path>
                            </manifestEntries>
                            <manifest>
                                <addClasspath>true</addClasspath>
                                <classpathPrefix>lib/</classpathPrefix>
                                <mainClass>com.****ceMain</mainClass>
                            </manifest>
                        </archive>
                        <excludes>
                            <exclude>*.xml</exclude>
                            <exclude>*.properties</exclude>
                        </excludes>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-assembly-plugin</artifactId>
                    <version>2.4</version>
                    <configuration>
                        <appendAssemblyId>false</appendAssemblyId>
                        <descriptors>
                            <descriptor>assembly.xml</descriptor>
                        </descriptors>
                    </configuration>
                    <executions>
                        <execution>
                            <id>make-assembly</id>
                            <phase>package</phase>
                            <goals>
                                <goal>single</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-surefire-plugin</artifactId>
                    <configuration>
                        <skip>true</skip>
                        <includes>
                            <include>**/*Test.java</include>
                        </includes>
                    </configuration>
                </plugin>
            </plugins>
        </build>
    

    assembly.xml文件:

    <assembly
        xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">
        <id>distribution</id>
        <formats>
            <format>zip</format>
        </formats>
    
        <fileSets>
            <fileSet>
                <directory>src/main/bin</directory>
                <outputDirectory></outputDirectory>
            </fileSet>
            <fileSet>
                <directory>src/main/resources</directory>
                <outputDirectory>conf</outputDirectory>
            </fileSet>
            <fileSet>
                <directory>data</directory>
                <outputDirectory>data</outputDirectory>
            </fileSet>
            <fileSet>
                <directory>${project.build.directory}</directory>
                <outputDirectory>/</outputDirectory>
                <includes>
                    <include>*.jar</include>
                </includes>
            </fileSet>
        </fileSets>
        <dependencySets>
            <dependencySet>
                <outputDirectory>/lib</outputDirectory>
                <excludes>
                    <exclude>${pom.groupId}:${pom.artifactId}</exclude>
                </excludes>
            </dependencySet>
        </dependencySets>
    </assembly>
    

    想打成什么都行

    点赞 评论 复制链接分享
  • dawang212 沵若成风 2年前

为你推荐