Maven web project error "import com.sun.image.codec.jpeg.*"

本文介绍了解决Maven Web项目中出现的‘com.sun.image.codec.jpeg’导入错误的方法。通过添加本地JDK的rt.jar和jce.jar文件到项目依赖中,或者将这些依赖直接写入POM.XML文件,可以有效避免该问题。对于自动化部署的需求,文章还提供了一个具体的Maven编译插件配置示例。

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>
But I could not find now.
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值