ant编译,找不到类

项目开发中在对图片进行裁切处理的时候,有时候是会使用到 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 ,如下:

[html] view plain copy
 
  1. <!-- 使用ant编译,在使用到com.sun包下类时,需要指定rt.jar文件的位置 -->  
[html] view plain copy
 
  1. <path id="JAVA.rt">  
  2.         <pathelement location="${frameone.runtime}/common/rt.jar" />  
  3.     </path>  
[html] view plain copy
 
  1.   
[html] view plain copy
 
  1. <path id="Project.classpath">  
  2.     <path refid="JAVA.rt" />  
  3.     <fileset dir="${project.lib.dir}" includes="*.jar" />  
  4. </path>  
[html] view plain copy
 
  1. <target name="build-project" depends="init">  
  2.     <echo message="${ant.project.name}: ${ant.file}" />  
  3.     <javac includeantruntime="false" debug="true" debuglevel="${debuglevel}" destdir="${dist.classes.dir.cms}" source="${source}" target="${target}" encoding="UTF-8">  
  4.         <src path="${src.dir}" />  
  5.         <classpath refid="Project.classpath" />  
  6.     </javac>  
  7. </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>

猜你喜欢

转载自417687590.iteye.com/blog/2320395