转载: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. jstl标签不起作用不管用,jstl标签直接输出表达式

    jstl标签不起作用不管用,jstl标签直接输出表达式 解决办法: 在jsp页面头上 引入: <%@ page isELIgnored="false"%> 便能够解决.

  2. scrapy-splash抓取动态数据例子一

    目前,为了加速页面的加载速度,页面的很多部分都是用JS生成的,而对于用scrapy爬虫来说就是一个很大的问题,因为scrapy没有JS engine,所以爬取的都是静态页面,对于JS生成的动态页面都无 ...

  3. Spark Streaming updateStateByKey和mapWithState源码解密

    本篇从二个方面进行源码分析: 一.updateStateByKey解密 二.mapWithState解密 通过对Spark研究角度来研究jvm.分布式.图计算.架构设计.软件工程思想,可以学到很多东西 ...

  4. [Android Pro] 调用系统相机和图库,裁剪图片

    private static final int PHOTO_REQUEST_TAKEPHOTO = 1;// 拍照 private static final int PHOTO_REQUEST_GA ...

  5. Android 5.0 怎样正确启用isLoggable(一)__使用具体解释

    isLoggable是什么 在Android源代码中,我们常常能够看到例如以下代码: //packages/apps/InCallUI/src/com/android/incallui/Log.jav ...

  6. div 隐藏和显示

    转自:http://aideehorn.iteye.com/blog/417558 div的visibility可以控制div的显示和隐藏,但是隐藏后页面显示空白: style="visib ...

  7. 【转载】Android控件属性大全

    控件属性: android属性 Android功能强大,界面华丽,但是众多的布局属性就害苦了开发者,下面这篇文章结合了网上不少资料, 第一类:属性值为true或falseandroid:layout_ ...

  8. Android布局及控件的属性说明

    android常用的一些属性说明   android:id --- 为控件指定相应的ID android:text --- 指定控件当中显示的文字,需要注意的是,这里尽量使用strings.xml文件 ...

  9. vue - .gitignore

    描述:npm官方屏蔽上传文件编写文件. 举例(屏蔽的文件/文件夹记得分行) 屏蔽文件:yarn.txt 屏蔽文件夹:/dist/

  10. vfork & fork

    转载 http://coolshell.cn/articles/12103.html 在知乎上,有个人问了这样的一个问题——为什么vfork的子进程里用return,整个程序会挂掉,而且exit()不 ...