项目开发中在对图片进行裁切处理的时候,有时候是会使用到 com.sun 包下的类时。
假设项目使用ant编译,会出现错误 com.sun.image.codec.jpeg does not exist 这是由于在JDK1.7+时,Oracle不同意使用sun.*的jar
详细參见http://www.oracle.com/technetwork/java/faq-sun-packages-142232.html 。
项目代码已经写好,且直接执行能够正常使用,仅仅是使用ant编译会出现错误,如今不打算更换项目的详细实现代码。不能更换JDK版本号,所以做例如以下处理就可以:
在ANT中明白指定使用这个rt.jar 。例如以下:
<!-- 使用ant编译。在使用到com.sun包下类时。须要指定rt.jar文件的位置 -->
<path id="JAVA.rt"> <pathelement location="${frameone.runtime}/common/rt.jar" /> </path>
<path id="Project.classpath"> <path refid="JAVA.rt" /> <fileset dir="${project.lib.dir}" includes="*.jar" /> </path>
<target name="build-project" depends="init"> <echo message="${ant.project.name}: ${ant.file}" /> <javac includeantruntime="false" debug="true" debuglevel="${debuglevel}" destdir="${dist.classes.dir.cms}" source="${source}" target="${target}" encoding="UTF-8"> <src path="${src.dir}" /> <classpath refid="Project.classpath" /> </javac> </target>
事实上上面的方法,可能会不起作用。我们能够指定javac 參数来忽略这种错误,例如以下:
<javac includeantruntime="false" debug="true" debuglevel="${debuglevel}" destdir="${build.dir}/WEB-INF/classes" source="${source}" target="${target}" encoding="UTF-8">
<src path="${src.dir}" />
<compilerarg line="-XDignore.symbol.file"/>
<classpath refid="Project.classpath" />
</javac>