Maven构建jide-oss jar包遇内部错误,求非重构解决方案
解决jide-oss仓库源码与资源混存的构建问题
问题核心
你的构建错误源于Maven资源处理与编译阶段的文件冲突:当src目录同时被标记为源码目录和资源目录时,资源处理过程(尤其是过滤操作)可能会破坏编译后的class文件结构,或因文件写入时序冲突导致class文件损坏,最终出现INTERNAL SERVER错误。
解决方案(无需重构项目)
通过调整pom.xml配置,分离源码编译与资源复制的逻辑,确保两类文件互不干扰:
1. 保留源码目录配置
继续使用build-helper-maven-plugin的add-source功能,指定源码目录,这部分无需修改:
<execution> <id>add-source</id> <phase>generate-sources</phase> <goals> <goal>add-source</goal> </goals> <configuration> <sources> <source>${basedir}/src</source> <source>${basedir}/src-jdk9</source> <source>${basedir}/src-apple</source> </sources> </configuration> </execution>
2. 重构资源处理逻辑(推荐方案)
移除build-helper-maven-plugin中的add-resource执行块,改用原生maven-resources-plugin精准控制资源复制,避免干扰编译产物:
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-resources-plugin</artifactId> <version>3.3.1</version> <executions> <!-- 处理src目录下的非Java资源 --> <execution> <id>copy-src-resources</id> <phase>process-resources</phase> <goals> <goal>copy-resources</goal> </goals> <configuration> <outputDirectory>${project.build.outputDirectory}</outputDirectory> <resources> <resource> <directory>${basedir}/src</directory> <includes> <include>**/*.properties</include> <include>**/*.png</include> <include>**/*.jpg</include> <include>**/*.xml</include> </includes> <excludes> <exclude>**/*.java</exclude> </excludes> <!-- 关闭过滤,防止破坏二进制资源和非模板化配置文件 --> <filtering>false</filtering> </resource> </resources> </configuration> </execution> <!-- 处理properties目录下的资源(保留过滤) --> <execution> <id>copy-properties-resources</id> <phase>process-resources</phase> <goals> <goal>copy-resources</goal> </goals> <configuration> <outputDirectory>${project.build.outputDirectory}</outputDirectory> <resources> <resource> <directory>${basedir}/properties</directory> <filtering>true</filtering> <includes> <include>**/*.properties</include> <include>**/*.png</include> <include>**/*.jpg</include> <include>**/*.xml</include> </includes> </resource> </resources> </configuration> </execution> </executions> </plugin>
3. 备选方案:修复build-helper资源配置
如果坚持使用build-helper-maven-plugin,需关闭src目录的资源过滤,并排除编译产物目录:
<execution> <id>add-resource</id> <phase>process-resources</phase> <goals> <goal>add-resource</goal> </goals> <configuration> <resources> <resource> <directory>${basedir}/src</directory> <includes> <include>**/*.properties</include> <include>**/*.png</include> <include>**/*.jpg</include> <include>**/*.xml</include> </includes> <excludes> <exclude>**/*.java</exclude> <exclude>${project.build.outputDirectory}/**</exclude> </excludes> <filtering>false</filtering> </resource> <resource> <directory>${basedir}/properties</directory> <filtering>true</filtering> <includes> <include>**/*.properties</include> <include>**/*.png</include> <include>**/*.jpg</include> <include>**/*.xml</include> </includes> </resource> </resources> </configuration> </execution>
4. 验证修复
执行mvn clean package后,检查生成的jar:
- 确认class文件无损坏(可通过反编译工具验证)
- 资源文件(properties、图片等)完整且内容正确
- 运行jar时无
INTERNAL SERVER错误
错误原因说明
之前的配置中,src目录同时参与编译和资源处理,加上默认的过滤逻辑,会导致:
- 资源复制过程误操作编译中的class文件,导致文件损坏
- 二进制资源(如图片)被过滤替换,破坏文件结构
- 资源复制与编译阶段的文件写入冲突,导致class文件不完整
内容的提问来源于stack exchange,提问作者sar
相关产品推荐
相关产品推荐

