在linux下运行javaMail程序报No X11 DISPLAY variable was...

 收藏 
 java.awt.HeadlessException:
No X11 DISPLAY variable was set, but this program performed an operation which requires it.
        at java.awt.GraphicsEnvironment.checkHeadless(GraphicsEnvironment.java:159)
        at java.awt.List.<init>(List.java:216)
        at java.awt.List.<init>(List.java:171)
        at com.mail.MailSendWork.<init>(MailSendWork.java:40)
        at com.mail.MailWorker.run(MailWorker.java:30)
        at edu.emory.mathcs.backport.java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1061)
        at edu.emory.mathcs.backport.java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:575)
        at java.lang.Thread.run(Thread.java:595)


在 java classname 中间加上 -Djava.awt.headless=true

再次执行还是报错

java.awt.HeadlessException
        at java.awt.GraphicsEnvironment.checkHeadless(GraphicsEnvironment.java:159)
        at java.awt.List.<init>(List.java:216)
        at java.awt.List.<init>(List.java:171)
        at com.mail.MailSendWork.<init>(MailSendWork.java:40)
        at com.mail.MailWorker.run(MailWorker.java:30)
        at edu.emory.mathcs.backport.java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1061)
        at edu.emory.mathcs.backport.java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:575)
        at java.lang.Thread.run(Thread.java:595)

看来不好使,删掉。在环境变量中加入 export DISPLAY=localhost:0 再次执行 ,OK!


本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/szy365/archive/2009/10/29/4743012.aspx

你可能感兴趣的:(在linux下运行javaMail程序报No X11 DISPLAY variable was...)