程序包com.sun.image.codec.jpeg不存在 的几种解决方案和遇到的坑

maven打包出现XXXX.java:[3,32] 程序包com.sun.image.codec.jpeg不存在

总结一下有几种解决方案:

1.不用jpeg这个类:

    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();
                }
            }
        }

2.想办法打包的时候包含进rt.jar

比如利用maven-compiler-plugin里面的bootclasspath:

<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>

3.打包的时候包含rt.jar的文件夹:

<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-compiler-plugin</artifactId>
				<version>3.3</version>
				<configuration>
					<source>1.7</source>
					<target>1.7</target>
					<encoding>utf8</encoding>
					<compilerArguments>
						<extdirs>${env.JAVA_HOME}/jre/lib</extdirs>
					</compilerArguments>
				</configuration>
			</plugin>

4.你也可以把rt.jar放到webapp/WEB-INF/lib路径下面,然后就只要:

<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-compiler-plugin</artifactId>
				<version>3.3</version>
				<configuration>
					<source>1.7</source>
					<target>1.7</target>
					<encoding>utf8</encoding>
					<compilerArguments>
						<extdirs>${basedir}/src/main/webapp/WEB-INF/lib</extdirs>
					</compilerArguments>
				</configuration>
			</plugin>

5.遇到的坑:

A.<bootclasspath><extdirs>两个标签,如果配置多个数据,mac,linux用冒号(:),而windows用分号(;)

B.<bootclasspath><extdirs>两个标签,windows路径用\,mac,linux用/


参考:

https://www.cnblogs.com/sagech/p/5025412.html

评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值