• Post Reply Bookmark Topic Watch Topic
  • New Topic

POM javax.mail issue  RSS feed

 
Michael Piaser
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The mail functions are no longer working on my system. I talked to another programmer and he said he also had this problem and fixed it by changing the Scope from Provided to Run-time. Unfortunately this didn't work for me. This was done in the Dependency Properties of the POM file (via Eclipse). The problem I am having is when I change the Scope to run-time, I get a compile error saying that javax.mail is not found. I specified mail-1.4.4.jar in the Java Build Path library which I have in my C:\users\michael\.m2\repository\javax\mail\mail folder.

When I run with the scope of Provided or Compile, the program compiles but I get a NullPointerException

I don't understand how this should work or where to go from here.. Any ideas would be appreciated.
 
Tim Cooke
Marshal
Posts: 4051
239
Clojure IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It appears that Maven is pulling in the dependency correctly. A NullPointerException indicates a problem in your code. Either you have an error in your code, or maybe the usage pattern of the library has changed between versions. Can you show us exactly where the NPE is being thrown?
 
Michael Piaser
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Before I go down the hole of trying to diagnose the null pointer exception, my real question is what does the Scope mean and why do I get a compile error when it is set to run-time. The other programmer was having this same problem and changed the scope to run-time and it fixed it. He does not have the compile error and we can't figure out why I do.
 
Tim Cooke
Marshal
Posts: 4051
239
Clojure IntelliJ IDE Java
 
Michael Piaser
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks - the documentation is a little helpful. It seems to say that if I select run-time, then Java expects the javax.mail to be defined on the jboss server (which it should be since nothing has changed there). If I select provided, it means that javax.mail should be included during the compile process. It has always been set to provided and until recently it worked. So I think I have to go down the rabbit hole and try to figure out the null pointer exception. That is typically a pain in the neck but.....Stay tuned.....
 
Michael Piaser
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The null pointer rabbit hole still seems wrong. I can compile when I set the option as provided but I can't compile when I set the option as run-time. I think run-time is the correct option to use which means I have to figure out why it won't compile.

The compile error is error: package javax.mail does not exist

there must be something in Eclipse/Maven when javax.mail is not defined but should be. It is obviously listed as a dependency (otherwise I wouldn't be able to set the provided or run-time option)
 
Tim Cooke
Marshal
Posts: 4051
239
Clojure IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Michael Piaser wrote:... until recently it worked ...

The first thing to determine is what has changed recently. Clearly something has.
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16060
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Scope provided means that Maven will include the library when compiling, but when you run the application, it's your responsibility to make sure that the library is on the classpath. You typically use this for web applications, to indicate to Maven that it should not put the library in the WEB-INF/lib directory of your web application, because the runtime environment, in this case JBoss, is going to provide the library.

Scope runtime is the opposite: it means Maven will not include the library when compiling; only when running the application. This is useful for, for example, JDBC drivers. You can't use the library directly in your source code, because it will not be on the classpath when compiling the source code. That's why you get this when you use this scope:
Michael Piaser wrote:The compile error is error: package javax.mail does not exist

So, runtime scope is not what you want.

I suspect the NullPointerException really has nothing to do with the Maven scope. What's the exact stack trace of the exception? Where in your code does the exception happen? The stack trace tells you exactly in which line of your code the exception happens. You're trying to call a method there on a variable that's null.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!