包javax.mail不存在

时间:2018-03-31 19:38:46

标签: grails javamail javax

我有grails项目。

show img

所有依赖项都是正确的,我可以在程序集上运行项目。 当我尝试启动应用程序时,出现错误:

"C:\Program Files\ojdkbuild\java-1.8.0-openjdk-1.8.0.91-3\bin\java" -XX:+TieredCompilation -XX:TieredStopAtLevel=1 -XX:CICompilerCount=3 -Djline.WindowsTerminal.directConsole=false -Dfile.encoding=UTF-8 -classpath C:\Users\Alex\AppData\Local\Temp\classpath1564081530.jar org.grails.cli.GrailsCli run-app --plain-output
|Running application...
E:\WORK\newggloor\src\main\java\email\EmailHelper.java:4: error: package javax.mail does not exist
import javax.mail.*;
^
E:\WORK\newggloor\src\main\java\email\EmailHelper.java:5: error: package javax.mail.internet does not exist
import javax.mail.internet.*;
^
E:\WORK\newggloor\src\main\java\email\EmailHelper.java:23: error: cannot find symbol
        Session session = Session.getInstance(props,
        ^
  symbol:   class Session
  location: class EmailHelper
E:\WORK\newggloor\src\main\java\email\EmailHelper.java:24: error: package javax.mail does not exist
                new javax.mail.Authenticator() {
                              ^
                                         ^
E:\WORK\newggloor\src\main\java\email\EmailHelper.java:35: error: cannot find symbol
                    InternetAddress.parse(email));
                    ^
  symbol:   variable InternetAddress
  location: class EmailHelper
E:\WORK\newggloor\src\main\java\email\EmailHelper.java:39: error: cannot find symbol
            Transport.send(message);
            ^
  symbol:   variable Transport
  location: class EmailHelper
E:\WORK\newggloor\src\main\java\email\EmailHelper.java:43: error: cannot find symbol
        } catch (MessagingException e) {
                 ^
  symbol:   class MessagingException
  location: class EmailHelper
12 errors

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':compileJava'.
> Compilation failed; see the compiler error output for details.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
Error |
Failed to start server (Use --stacktrace to see the full trace)

Process finished with exit code 1

I added the jar file as a library.已添加到模块newggloor_main。

2 个答案:

答案 0 :(得分:0)

你最好使用grails邮件插件。把它放到你的build.gradle:

compile "org.grails.plugins:mail:2.0.0.RC6"

答案 1 :(得分:0)

在build.gradle中添加依赖项

// https://mvnrepository.com/artifact/javax.mail/mail 编译组:'javax.mail',名称:'mail',版本:'1.4.7'