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が存在しないといういくつかの解決策と落とし穴に遭遇しました

 

 

 

XXXX.java:[3,32]パッケージcom.sun.image.codec.jpegがmavenパッケージに存在しません

要約すると、いくつかの解決策があります。

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> 2つのタグ、複数のデータを構成する場合、mac、linuxはコロン(:)を使用し、windowsはセミコロン(;)を使用します

B. <bootclasspath> <extdirs> 2つのタグ、\ for Windowsパス、\ for mac、linux /

 

 

おすすめ

転載: blog.csdn.net/zy103118/article/details/109767550