将项目部署到jenkins上的时候发生错误。告诉我这个工具类有一个包导入不了,经过查看后知道,这两个包是:
import com.sun.image.codec.jpeg.JPEGCodec; import com.sun.image.codec.jpeg.JPEGImageEncoder;
它们是sun的私有包,在jdk1.7以后就不在提供使用了。所以将下方的代码就行改写后可成功执行。
错误:
[ERROR] /home/jenkins/.jenkins/workspace/FCG/src/main/java/com/spring/security/captcha/CaptchaUtil.java:[22,32] package com.sun.image.codec.jpeg does not exist
[ERROR] /home/jenkins/.jenkins/workspace/FCG/src/main/java/com/spring/security/captcha/CaptchaUtil.java:[23,32] package com.sun.image.codec.jpeg does not exist
[ERROR] /home/jenkins/.jenkins/workspace/FCG/src/main/java/com/spring/security/captcha/CaptchaUtil.java:[107,9] cannot find symbol
[ERROR] symbol: class JPEGImageEncoder
[ERROR] location: class com.spring.security.captcha.CaptchaUtil
[ERROR] /home/jenkins/.jenkins/workspace/FCG/src/main/java/com/spring/security/captcha/CaptchaUtil.java:[107,36] cannot find symbol
[ERROR] symbol: variable JPEGCodec
原代码为:
ServletOutputStream out = response.getOutputStream();
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
encoder.encode(bi);
out.flush();
代码改写为:
ServletOutputStream out = response.getOutputStream();
//JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
//encoder.encode(bi);
ImageIO.write(bi, "jpeg", out);
out.flush();