今天在调整一个系统的构建方式,原先是是用eclipse直接构建的,现在要转换为用maven构建。项目目录结构和项目依赖都配置好之后,命令行下编译却有依赖包找不到的错误。
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] /root/EPMS/src/main/java/com/***/epms/doc/common/DocumentConst.java:[17,66] package com.sun.xml.internal.messaging.saaj.packaging.mime.internet does not exist
[ERROR] /root/EPMS/src/main/java/com/***/epms/doc/common/DocumentConst.java:[144,26] cannot find symbol
symbol : variable MimeUtility
location: class com.***.epms.doc.common.DocumentConst
[INFO] 2 errors
复制代码
看错误提示,这个依赖包应该是jdk自带的包。用eclipse查找了一下,发现这个包是在rt.jar里面的类。
确认了编译服务器上的JDK环境,rt.jar已经在CLASSPATH里面了,按道理应该能找到这个类的。
在eclipse下直接编译,结果是可以正常编译通过的,为啥在命令行下就没法引用到这个类啊?
后来看到http://maven.40175.n5.nabble.com/Why-can-t-Maven-find-com-sun-xml-internal-messaging-saaj-util-ByteOutputStream-class-td107361.html,才知道问题引起的原因。
Sun's *java compiler* detects when a special
"internal" class is being accessed, and refuses to import the class.
Eclipse uses a different compiler which presumably does not have this check.
Maven just uses the javac compiler available in the system execution
path. Therefore the problem is nothing to do with Maven at all. It's the
compiler that maven is invoking which is refusing to compile the source.
I can't see any public flags in the javac commandline to disable this
"blocking" of internal access, so unless you want to avoid using Sun's
javac compiler you'll just have to avoid using this internal class.
复制代码
用javax包里面的MimeUtility类就可以了
import javax.mail.internet.MimeUtility;
//import com.sun.xml.internal.messaging.saaj.packaging.mime.internet.MimeUtility;
复制代码