maven项目编译:程序包com.sun.image.codec.jpeg不存在 这个类文件的位置在jre/lib/rt.jar
转载: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的更多相关文章
- 程序包com.sun.image.codec.jpeg不存在 问题的完美解决
原文地址:http://my.oschina.net/zb0423/blog/86507 在使用Hudson进行打包的过程中,因为我们使用了一个pdf文件产生缩略图的功能,倒置添加的源码文件在mave ...
- 项目中遇到的问题:IDEA maven项目报错:程序包com.sun.image.codec.jpeg不存在
错误截图: 解决方法:在pom.xml文件中间加上以下代码: 代码: <plugin> <groupId>org.apache.maven.plugins</groupI ...
- maven 程序包com.sun.image.codec.jpeg
在 Pom.xml 增加 <build> <plugins> <plugin> <artifactId>maven-compiler-plugin< ...
- 程序包com.sun.image.codec.jpeg不存在
在pox.xml中引入依赖 <dependency><groupId>rt</groupId><artifactId>rt</artifactId ...
- 程序包com.sun.image.codec.jpeg不存在解决方法
https://blog.csdn.net/u011627980/article/details/50436842
- maven 编译项目时:报com.sun.image.codec.jpeg不存在
项目中用到图片处理相关的一些工具类,在eclipse开发工具内,程序并没有什么问题,都可以正常使用,项目也没有报错,但通过maven 进行编译打包时,则会报错: 程序包com.sun.image.co ...
- jenkins构建项目时报错缺少com.sun.image.codec.jpeg包解决方案
错误日志:error: package com.sun.image.codec.jpeg does not exist 网上找的一个项目,使用的是jdk1.7,除此之外其他服务器配置或是环境配置都是j ...
- IDEA Maven项目 编译的问题
IDEA中,点击项目的maven插件的 compile: 出现: [INFO] ------------------------------------------------------------ ...
- 错误: 程序包com.sun.istack.internal不存在
eclipse下maven打包是出现如下错误: [ERROR] D:\code-old\daba_user_mvn\src\main\java\com\dada\transaction\service ...
随机推荐
- scrapy中ROBOTSTXT_OBEY = True的相关说明
在scrapy中创建项目以后,在settings文件中有这样的一条默认开启的语句: # Obey robots.txt rules ROBOTSTXT_OBEY = True 观察代码可以发现,默认为 ...
- CF(D. Fibonacci Sums)dp计数
题目链接:http://codeforces.com/contest/126/problem/D 题意:一个数能够有多种由互不同样的斐波那契数组成的情况: 解法:dp,easy证明:每一个数通过贪心能 ...
- Junit核心——测试集(TestSuite)
关于测试集,实质就是包含若干个测试类的集合,通过一个具体的实例,让我们来了解一下Junit的测试集 package org.yezi.junit; public class Calcaute { pu ...
- Flutter常用布局组件
Flutter控件本身通常由许多小型.单用途的控件组成,结合起来产生强大的效果,例如,Container是一种常用的控件,由负责布局.绘画.定位和大小调整的几个控件组成,具体来说,Container是 ...
- async -- await 解决数据异步获取
在React组件中,也比较一下 Promise 和 Async/Await 的方法异同. 传统地使用 Promise : import React, { Component } from 'react ...
- 【Python】学习笔记八:面向对象
举例 面向对象的合理解释就是:我是人这个类,对象化以后我就是一个个体OLIVER 对象化就是在人这个大类中,将某个人指名道姓,具体到某个人 下面是一个具体的实例一: #!/usr/bin/python ...
- Spark-Dependency
1.Spark中採用依赖关系(Dependency)表示rdd之间的生成关系.Spark可利用Dependency计算出失效的RDD.在每一个RDD中都存在一个依赖关系的列表 private var ...
- spring中添加redis缓存
1.单机版的添加 spring里面配置 <bean id="redisClient" class="redis.clients.jedis.JedisPool&qu ...
- C#设计模式学习笔记-单例模式随笔
最近学习 设计模式,从单例模式入手 啥是单例模式: 要实现一个单例类的话,首先,肯定是不能让用户自行生产的,那就是说明不能让用户new,所以,就必须把构造函数设置成为私有的 因为静态变量的生命周期跟整 ...
- EMQ(TLS)
1.TLS证书验证 为了保障安全.我们常常会使用HTTPS来保障请求不被篡改,作为MQTT使用TLS加密的方式来保障传输安全 EMQ默认使用的TLS加密的端口是8883端口,默认证书在EMQ目录下et ...