转载: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. http://www.cnblogs.com/jqyp/archive/2010/08/20/1805041.html

    http://www.cnblogs.com/jqyp/archive/2010/08/20/1805041.html

  2. 一起talk C栗子吧(第二十七回:C语言实例--插入排序)

    各位看官们,大家好.上一回中咱们说的是冒泡排序的样例.这一回咱们说的样例是:插入排序. 闲话休 提,言归正转.让我们一起talk C栗子吧. 看官们,我们这回说的插入排序和前一回说的冒泡排序一样.也是 ...

  3. 给ubuntu设置静态ip —— How to set static IP Address in Ubuntu Server 16.04

    原文: http://www.configserverfirewall.com/ubuntu-linux/ubuntu-set-static-ip-address/ ----------------- ...

  4. 最简单的方式用上https

    1.在这个网站申请ssl证书 https://www.sslforfree.com 2.下载的证书使用这个脚本处理一下 #!/bin/bash HOST_NAME=$1 cp certificate. ...

  5. 2017.12.25 Mybatis物理分页插件PageHelper的使用(二)

    参考来自: 官方文档的说明:https://github.com/pagehelper/Mybatis-PageHelper/blob/master/wikis/zh/HowToUse.md 上篇博客 ...

  6. Lidgren.Network – an introduction to networking in C# games

    Lidgren.Network – an introduction to networking in C# games http://genericgamedev.com/tutorials/lidg ...

  7. 基于jQuery的TreeGrid组件

    /** * @author 陈举民 * @version 1.0 * @link http://chenjumin.iteye.com/blog/419522 */ TreeGrid = functi ...

  8. vector iterator not incrementable For information on how your program can cause an an assertion Failure, see the Visual c + + documentation on asserts

    #include <list> using namespace std; int _tmain(int argc, _TCHAR* argv[]) { list<int> sl ...

  9. Python中的关键字的用法

    Python有哪些关键字 -Python常用的关键字 and, del, from, not, while, as, elif, global, or, with, assert, else, if, ...

  10. html+css+js实现科学计算器

    代码地址如下:http://www.demodashi.com/demo/13751.html 项目描述 纯html+css+js实现一个科学计算器,支持平方开方指数对数等基本函数,支持键盘输入,有简 ...