Maven web project error “import com.sun.image.codec.jpeg.*”
This was my third time to write blog on CSDN.
First of all, you should know which *.jar the class “com.sun.image.codec.jpeg” depended on.
It was “rt.jar” and “jce.jar” included in the local JDK.
If you run as “maven build” local maven(webapp)-tomcat projecet, there was a error about “com.sun.image.codec.jpeg”.
You can “Add Library local JDK” by “project->properties(Alt+Enter)->Java Build Path->Libraries->Add Library->JRE System Library”.If you want to pack as *.war automatically and deploy on Jenkins, there was a way to slove.
Due to that Maven Dependencies did not include local JDK, you should put “rt.jar” and “jce.jar” into POM.XML.
Add plugin, such as:
<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>
<fork>true</fork>
<compilerArguments>
<verbose />
<bootclasspath>
C:\Program Files (x86)\Java\jdk1.7.0_25\jre\lib\rt.jar;
C:\Program Files (x86)\Java\jdk1.7.0_25\jre\lib\jce.jar
</bootclasspath>
</compilerArguments>
<executable>
C:\Program Files (x86)\Java\jdk1.7.0_25\bin\javac.exe
</executable>
</configuration>
</plugin>
PS 1: In “source” and “target”, the “1.7”was version of the server’s JDK.
PS 2: The “C:\Program Files (x86)\Java\jdk1.7.0_25” was the path of the server’s JDK.
PS 3: If you deployed it on local Jenkins, the server’s JDK just was your own JDK.
Of course, if finding dependencies as those and add into pom.xml, project also can work.
<dependency>
<groupId>***</groupId>
<artifactId>rt</artifactId>
<version>*.*</version>
</dependency>
<dependency>
<groupId>***</groupId>
<artifactId>jce</artifactId>
<version>*.*</version>
</dependency>
本文介绍了解决Maven Web项目中出现的‘com.sun.image.codec.jpeg’导入错误的方法。通过添加本地JDK的rt.jar和jce.jar文件到项目依赖中,或者将这些依赖直接写入POM.XML文件,可以有效避免该问题。对于自动化部署的需求,文章还提供了一个具体的Maven编译插件配置示例。

792

被折叠的 条评论
为什么被折叠?



