IDEA maven项目报错:程序包com.sun.image.codec.jpeg不存在

 

我的解决方法:

这段复制贴进报错项目模块的pom.xml文件对应的插件配置区域中

<plugin>
   <groupId>org.apache.maven.plugins</groupId>
   <artifactId>maven-compiler-plugin</artifactId>
   <version>3.6.0</version>
   <configuration>
      <source>${java.version}</source>
      <target>${java.version}</target>
      <encoding>${project.build.sourceEncoding}</encoding>
      <compilerArguments><verbose/><bootclasspath>${java.home}/lib/rt.jar;${java.home}/lib/jce.jar</bootclasspath>
      </compilerArguments>
   </configuration>
</plugin>

 ————————————————————————————————————————————————亲测好用-----------(我用上面的方法就好用了)

下面是网上网友写的参考方法,

错误截图:

解决方法:在pom.xml文件中间加上以下代码:

代码:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

<plugin>

               <groupId>org.apache.maven.plugins</groupId>

               <artifactId>maven-compiler-plugin</artifactId>

               <version>3.6.0</version>

               <configuration>

                   <source>${java.version}</source>

                   <target>${java.version}</target>

                   <encoding>${project.build.sourceEncoding}</encoding>

                   <compilerArguments>

                       <verbose />

                       <bootclasspath>${java.home}/lib/rt.jar;${java.home}/lib/jce.jar</bootclasspath>

                   </compilerArguments>

               </configuration>

           </plugin>

————————————————————————————————————————

看了另一个帖子

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

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

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

1.不用jpeg这个类:

 
  1. ByteArrayOutputStream out = null;

  2. byte[] b = null;

  3. try {

  4. BufferedImage bi = ImageIO.read(is);

  5. Image Itemp = bi.getScaledInstance(wdith, height, BufferedImage.SCALE_SMOOTH);

  6. BufferedImage thumbnail = new BufferedImage(wdith, height, BufferedImage.TYPE_INT_RGB);

  7. thumbnail.getGraphics().drawImage(Itemp, 0, 0, null);

  8.  
  9. out = new ByteArrayOutputStream();

  10.  
  11. // 绘图

  12. JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);

  13. JPEGEncodeParam param = encoder.getDefaultJPEGEncodeParam(thumbnail);

  14. param.setQuality(1.0f, false);

  15. encoder.encode(thumbnail);

  16. out.flush();

  17. b = out.toByteArray();

  18. out.close();

  19. bi.flush();

  20. bi = null;

  21. } catch (IOException e) {

  22. logger.error(Util.stackTrace2String(e));

  23. }finally{

  24. if(out != null){

  25. try {

  26. out.close();

  27. } catch (IOException e) {

  28. e.printStackTrace();

  29. }

  30. }

  31. }

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

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

 
  1. <plugin>

  2. <artifactId>maven-compiler-plugin</artifactId>

  3. <version>2.3.2</version>

  4. <configuration>

  5. <source>1.6</source>

  6. <target>1.6</target>

  7. <encoding>UTF-8</encoding>

  8. <optimize>true</optimize>

  9. <debug>true</debug>

  10. <showDeprecation>true</showDeprecation>

  11. <showWarnings>false</showWarnings>

  12. <compilerArguments>

  13. <verbose />

  14. <bootclasspath>${java.home}/lib/rt.jar;${java.home}/lib/jce.jar</bootclasspath>

  15. </compilerArguments>

  16. </configuration>

  17. </plugin>

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

 
  1. <plugin>

  2. <groupId>org.apache.maven.plugins</groupId>

  3. <artifactId>maven-compiler-plugin</artifactId>

  4. <version>3.3</version>

  5. <configuration>

  6. <source>1.7</source>

  7. <target>1.7</target>

  8. <encoding>utf8</encoding>

  9. <compilerArguments>

  10. <extdirs>${env.JAVA_HOME}/jre/lib</extdirs>

  11. </compilerArguments>

  12. </configuration>

  13. </plugin>

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

 
  1. <plugin>

  2. <groupId>org.apache.maven.plugins</groupId>

  3. <artifactId>maven-compiler-plugin</artifactId>

  4. <version>3.3</version>

  5. <configuration>

  6. <source>1.7</source>

  7. <target>1.7</target>

  8. <encoding>utf8</encoding>

  9. <compilerArguments>

  10. <extdirs>${basedir}/src/main/webapp/WEB-INF/lib</extdirs>

  11. </compilerArguments>

  12. </configuration>

  13. </plugin>

5.遇到的坑:

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

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

猜你喜欢

转载自blog.csdn.net/zy103118/article/details/109767550