• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

Changing log4j version gives error in Session class. WHy?

 
Ranch Hand
Posts: 264
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I am trying to upgrade my log 4j version from 1.x to 2.x

Earlier log4j entry in pom.xml


Now I am trying to upgrade it to 2.x



But the problem is, I get compilation problems in Some other class (i.e javax.mail or something like that)

But why is that compiler is not able to find these classes after I find log4j version.

Can someone explain me please?

Even i tried to add bridge log4j jars, so that if there is a possibility that these jars are inturn using 1.x log4j, then they may be satisifed, but even that doesnt help.
Compilation-error.JPG
Compilation error I get after I change the log4j version
Compilation error I get after I change the log4j version
 
Marshal
Posts: 79707
381
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What did the compiler error messages say? Please copy'n'paste the errors rather than posting screenshots.
 
Yogesh Gandhi
Ranch Hand
Posts: 264
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:What did the compiler error messages say? Please copy'n'paste the errors rather than posting screenshots.



Session cannot be resolved to a type
InternetAddress cannot be resolved

etc etc
 
Campbell Ritchie
Marshal
Posts: 79707
381
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How did you import those types? How did you add the log4j types to the application? Did you use the CLASSPATH?
 
Yogesh Gandhi
Ranch Hand
Posts: 264
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:How did you import those types? How did you add the log4j types to the application? Did you use the CLASSPATH?



It was a working maven project. I was able to compile it completely earlier.

When I change the log4j dependencies from 1.x to 2.x, why the heck these classes start giving compilation error.
I am surpised because there are in no way related to the log4j in any way or is it?
 
Saloon Keeper
Posts: 28126
198
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It appears that the compile/edit classpath of your IDE project is damaged. Possibly there is a syntax error somewhere in your POM from when you edited it. If not, you may have to re-sync Maven and your IDE (Eclipse can be bad about that).

It's quite likely that if you ran Maven from the command line, the app would compile and build OK if the POM is OK.

No, changing the version of Log4J should definitely not cause errors like you showed us.

By the way, I believe that Log4J has stabilised at 2.17.2 now.
 
Sheriff
Posts: 22803
131
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Those classes are from JavaMail. Apparently its API module is a dependency of Log4J 1.x (see https://mvnrepository.com/artifact/log4j/log4j/1.2.15). You'll need to include it manually.
I was surprised by this, but I think it was a mistake. The previous version (https://mvnrepository.com/artifact/log4j/log4j/1.2.14) didn't have any dependencies, the next version (https://mvnrepository.com/artifact/log4j/log4j/1.2.16) made it an optional dependency. I'm guessing that version 1.2.15 added a new appender that needed JavaMail, but the developers forgot to make JavaMail optional.
 
Rob Spoor
Sheriff
Posts: 22803
131
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
By the way, depending on your type of application, you should include the JavaMail dependency with scope provided. In any JEE compliant container like JBoss, WebLogic, GlassFish, etc., JavaMail is part of the container's core library set. You don't need to include it in your application, in the same way you don't need to include the Servlet API or Bean Validation API. If you're deploying on Tomcat you probably need it as a compile time dependency (no scope necessary), if you have a standalone application you definitely need it as a compile time dependency.
 
Tim Holloway
Saloon Keeper
Posts: 28126
198
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Let me see if I can sort things out a bit.

I was under the impression that your screenshot was part of the application source code. If that is true, then you might have a version conflict with what log4j17.2 wants and need to upgrade your application source. If not, then the following should apply:

As Rob said, full-stack JEE servers should already have JavaMail as an integral library to the server and the Maven scope would be "provided". If you had an explicit (non-transitive) POM dependency, make sure that it looks for a compatible version.

Lightweight JEE servers such as Tomcat and Jetty do not include JavaMail as a built-in service, so the Maven scope there should be "compile" (which is the default). Compile scope means that not only will the implementation library you're depending on be referenced for compiling (just like "provided" scope), but that additionally, a copy of that JAR will be included in the generated WAR's /WEB-INF/lib directory.
 
Whip out those weird instruments of science and probe away! I think it's a tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic