转载:http://superich2008.iteye.com/blog/2047830

失败提示信息为:程序包com.sun.image.codec.jpeg不存在
这个类文件的位置在jre/lib/rt.jar

而我们设置的java_home下面的lib/dt.jar中没有这个文件,导致编译失败。通过配置maven-compiler-plugin插件可以解决此问题。

<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
<encoding>UTF-8</encoding>
<optimize>true</optimize>
<debug>true</debug>
<showDeprecation>true</showDeprecation>
<showWarnings>false</showWarnings>
<compilerArguments>
<verbose />
<bootclasspath>${java.home}/lib/rt.jar;${java.home}/lib/jce.jar</bootclasspath>
</compilerArguments>
</configuration>
</plugin>

在windows下面用;分隔,linux下面用:分隔。

方案-:

  查询网上的解决方案,但是仍然报编译失败。后经过查找,最终定位问题。

  原因是由于编译的依赖JDK版本过高引起的。从JDK1.7开始,中com.sun.image.codec.jpeg这个类被删除,所以编译总是报错,解决方案,编译的JDK版本设置为JDK1.6或者以下版本,编译通过。

方案二:

  解决代码API引用问题。

  原始代码:

        ByteArrayOutputStream out = null;
byte[] b = null;
try {
BufferedImage bi = ImageIO.read(is);
Image Itemp = bi.getScaledInstance(wdith, height, BufferedImage.SCALE_SMOOTH);
BufferedImage thumbnail = new BufferedImage(wdith, height, BufferedImage.TYPE_INT_RGB);
thumbnail.getGraphics().drawImage(Itemp, 0, 0, null); out = new ByteArrayOutputStream(); // 绘图
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
JPEGEncodeParam param = encoder.getDefaultJPEGEncodeParam(thumbnail);
param.setQuality(1.0f, false);
encoder.encode(thumbnail);
out.flush();
b = out.toByteArray();
out.close();
bi.flush();
bi = null;
} catch (IOException e) {
logger.error(Util.stackTrace2String(e));
}finally{
if(out != null){
try {
out.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}

改变实现方式:

        ByteArrayOutputStream out = null;
byte[] b = null;
try {
BufferedImage bi = ImageIO.read(is);
// Image Itemp = bi.getScaledInstance(wdith, height, BufferedImage.SCALE_SMOOTH);
// BufferedImage thumbnail = new BufferedImage(wdith, height, BufferedImage.TYPE_INT_RGB);
// thumbnail.getGraphics().drawImage(Itemp, 0, 0, null); out = new ByteArrayOutputStream(); // 绘图
// JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
// JPEGEncodeParam param = encoder.getDefaultJPEGEncodeParam(thumbnail);
// param.setQuality(1.0f, false);
// encoder.encode(thumbnail); ImageIO.write(bi, "jpg", out); out.flush();
b = out.toByteArray();
out.close();
bi.flush();
bi = null;
} catch (IOException e) {
logger.error(Util.stackTrace2String(e));
}finally{
if(out != null){
try {
out.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}

即可解决报错问题。

maven项目编译:程序包com.sun.image.codec.jpeg不存在 这个类文件的位置在jre/lib/rt.jar的更多相关文章

  1. 程序包com.sun.image.codec.jpeg不存在 问题的完美解决

    原文地址:http://my.oschina.net/zb0423/blog/86507 在使用Hudson进行打包的过程中,因为我们使用了一个pdf文件产生缩略图的功能,倒置添加的源码文件在mave ...

  2. 项目中遇到的问题:IDEA maven项目报错:程序包com.sun.image.codec.jpeg不存在

    错误截图: 解决方法:在pom.xml文件中间加上以下代码: 代码: <plugin> <groupId>org.apache.maven.plugins</groupI ...

  3. maven 程序包com.sun.image.codec.jpeg

    在 Pom.xml 增加 <build> <plugins> <plugin> <artifactId>maven-compiler-plugin< ...

  4. 程序包com.sun.image.codec.jpeg不存在

    在pox.xml中引入依赖 <dependency><groupId>rt</groupId><artifactId>rt</artifactId ...

  5. 程序包com.sun.image.codec.jpeg不存在解决方法

    https://blog.csdn.net/u011627980/article/details/50436842

  6. maven 编译项目时:报com.sun.image.codec.jpeg不存在

    项目中用到图片处理相关的一些工具类,在eclipse开发工具内,程序并没有什么问题,都可以正常使用,项目也没有报错,但通过maven 进行编译打包时,则会报错: 程序包com.sun.image.co ...

  7. jenkins构建项目时报错缺少com.sun.image.codec.jpeg包解决方案

    错误日志:error: package com.sun.image.codec.jpeg does not exist 网上找的一个项目,使用的是jdk1.7,除此之外其他服务器配置或是环境配置都是j ...

  8. IDEA Maven项目 编译的问题

    IDEA中,点击项目的maven插件的 compile: 出现: [INFO] ------------------------------------------------------------ ...

  9. 错误: 程序包com.sun.istack.internal不存在

    eclipse下maven打包是出现如下错误: [ERROR] D:\code-old\daba_user_mvn\src\main\java\com\dada\transaction\service ...

随机推荐

  1. poj3592 Instantaneous Transference tarjan缩点+建图

    //给一个n*m的地图.坦克从(0 , 0)開始走 //#表示墙不能走,*表示传送门能够传送到指定地方,能够选择也能够选择不传送 //数字表示该格的矿石数, //坦克从(0,0)開始走.仅仅能往右和往 ...

  2. tee -a /var/log/jd.log

    原文: http://man.linuxde.net/tee --------------------------------------------------------------------- ...

  3. MAVEN 配置阿里巴巴镜像

    配置 修改maven根目录下的conf文件夹中的setting.xml文件,内容如下: <mirrors> <mirror> <id>alimaven</id ...

  4. limit是mysql的语法

    select * from table limit m,n 其中m是指记录开始的index,从0开始,表示第一条记录 n是指从第m+1条开始,取n条. , 即取出第3条至第6条,4条记录 转自:htt ...

  5. idea中git从码云克隆项目到本地

    1.首先需要在操作系统上安装Git分布式管理系统 此处自行百度............. 2.在Intellij IDEA中配置Git 打开Settings(File-->Settings) - ...

  6. 1年内4次架构调整,谈Nice的服务端架构变迁之路

    Nice 本身是一款照片分享社区类型的应用,在分享照片和生活态度的同时可以在照片上贴上如品牌.地点.兴趣等tag. Nice从2013.10月份上线App Store到目前每天2亿PV,服务端架构经过 ...

  7. Linux命令计算文件中某一列的平均值

    例如每秒执行一次top命令,把结果输出到某个文件中保存,现在需要统计这段时间内某个进程的平均CPU占用率,可使用以下命令 | grep "GameServer_r" | awk ' ...

  8. vue - webpack.dev.conf.js for CopyWebpackPlugin

    描述:将单个文件或整个目录复制到构建目录 官网地址:https://www.npmjs.com/package/copy-webpack-plugin // 复制到自定义静态源 new CopyWeb ...

  9. 微信小程序navigateBack如何带参数

    wx.navigateBack({//返回 delta:1 })   方法如下: 一. var pages = getCurrentPages(); var prevPage = pages[page ...

  10. Java环境变量设置辅助工具

    安装完JDK之后,很容易忘了设置系统的环境变.最近发现一个设置JDK的小工具,非常简单,推荐给大家: 下载地址:http://files.cnblogs.com/eastson/JavaPathSet ...