[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] /var/jenkins_home/workspace/demo/src/main/java/top/yexuejc/util/ImageUtils.java:[22,31] error: package com.sun.image.codec.jpeg does not exist
[ERROR] /var/jenkins_home/workspace/demo/src/main/java/top/yexuejc/util/ImageUtils.java:[23,31] error: package com.sun.image.codec.jpeg does not exist
[ERROR] /var/jenkins_home/workspace/demo/src/main/java/top/yexuejc/util/ImageUtils.java:[202,12] error: cannot find symbol
[ERROR] class ImageUtils
maven打包说是找不到包com.sun.image.codec.jpeg
What? 我在IDEA里面重复试了n次都能正常打包啊??? google、百度说什么rt.jar指定位置问题(修正方法如下)
<plugins>
<!-- 解决:java: 程序包com.sun.image.codec.jpeg不存在
这个类文件的位置在jre/lib/rt.jar,而我们设置的java_home下面的lib/dt.jar中没有这个文件,
导致编译失败。通过配置maven-compiler-plugin插件可以解决此问题。
-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>${java-version}</source>
<target>${java-version}</target>
<encoding>UTF-8</encoding>
<compilerArguments>
<verbose/>
<!--注意自己的 java.home=C:/Program Files/Java/jdk1.8.0_144/jre-->
<!-- <bootclasspath>${java.home}\lib\rt.jar;${java.home}\lib\jce.jar</bootclasspath> linux下 ; 是 : 所以使用下面方法-->
<bootclasspath>${java.home}/lib/rt.jar${path.separator}${java.home}/lib/jce.jar</bootclasspath>
</compilerArguments>
</configuration>
</plugin>
也有说是jdk版本问题的换到1.6版本就不会报错
。都什么年代了?java14都老了😂
还是继续找,终于看到了几篇不一样的🙏
com.sun.image.codec.jpeg.JPEGCodec 这个包是属于sun公司的私有类,openJdk上没有,so 怎么能找到呢😂
既然找不到这个类,那么解决方案就多了啊,不使用这个类
我使用javax.imageio.ImageIO
作为替换
/**
* @params 图片文件 tag
* BufferedImage tag = new BufferedImage(100, 100, BufferedImage.TYPE_INT_RGB);
* @params formatName 文件格式 png
* @params srcfile 文件对象 new File("/tmp/a.png");
*/
ImageIO.write(tag, formatName, srcfile);
参考:https://www.iteye.com/blog/tjmljw-1939973