Spring Boot 1.4.3 Embedded Tomcat NoSuchMethodError StringManager.getManager - spring

I have update my project to use Spring BOOT 1.4.3. The code compiles and runs without issues from Eclipse Neon 1.
But when I run from command line
mvn clean install -DskipTests
java -jar myweb\target\my-web-1.0-SNAPSHOT.jar
I get runtime error and tomcat is not starting
Caused by: java.lang.NoSuchMethodError: org.apache.tomcat.util.res.StringManager.getManager(Ljava/lang/Class;)Lorg/apache/tomcat/util/res/StringManager;
at org.apache.catalina.util.LifecycleBase.<clinit>(LifecycleBase.java:43) ~[tomcat-embed-core-8.5.6.jar!/:8.5.6]
Please can you tell why? How to find which tomcat is used at runtime, as my understand is that 8.5.6 is having compile scope(?)
Please help. If the suggestion is to use tomcat.version in properties of POM file or add tomcat-juli dependency, then please help me understand why it is required?
Impatient stackoverflow'ers dont just flog new comers only because you can do. You can easily ask if you want my POM, but I used just spring-boot-starter-web thats it.

For this kind of problem, it's often due to multiple jar having the same class inside your classpath, so :
Find where this class / method could come from, by opening the type popup (CTRL + SHIFT + T in Eclipse). It will display you every jar in your classpath that contains the class.
Open the class in each jar to see which one contains your method and which one don't.
Display the dependency hierarchy of your project with mvn dependency:tree
If the 2 jars are in your classpath, you might exclude the one that don't contain the method.

Related

Why third party dependency is required exclusively from OSGi container even if I have it in my maven dependencies?

I want to know why OSGi do not respect the maven dependenceis.
I want to create one app in OSGi(AEM). I want to communicate(CRUD) to the database with the help of JPA(eclipselink).
I created maven project with aem-archetype.
Added all required dependencies(of JPA) into my maven project's pom file.
No errors in Eclipse, I built the project via mvn clean install and installed it into AEM(CQ5) via mvn sling:install. All good till now. No Errors.
But when I go and see my bundle in the felix console, I see that it is not Active but in Installed state.The error reported is that it could not resolve the javax.persistence package.
I was puzzled, I searched and I read about it here -
You have to make sure that you place the same version in another
bundle and deploy first. https://forums.adobe.com/thread/2325007
I converted JPA jar to OSGi bundle and installed in my OSGi container, and the error was gone. Great!
But why OSGi is not watching out for the dependencies I wrote in pom.xml of my maven project. Why it needs JPA strictly from OSGi bundle?
Maybe this is due to any architectural benefit, but could anyone please explain me here about this behaviour of OSGi? And why/how this feature of OSGi is useful ?
The <dependency> section of your Maven POM only covers your compile time dependencies. That means when you run Maven to build your project those dependencies are used to compile the source code and build your bundle. Maven itself is not aware of AEM or OSGi or any other platform or framework (e.g. Spring).
Maven just compiles your code.
You, as a developer, are responsible that all those required compile time dependencies are also available at runtime.
What we usually do is to create an AEM content package Maven module and put all of our required third party dependencies (e.g. JPA bundles) into it. This content package is then deployed by Maven so that those dependencies are also available at runtime.
Reason is: what you are adding as dependency is getting added in build path of your project and being available for your classes.When you run mvn install,it checks presence of all dependency and creates a bundle/jar for you.By default this bundle has only your project classes not other dependencies.
You need to check in depfinder whether external dependencies are already there in OSGi container,if not you have to load them in OSGi container either by embedding external dependencies in your bundle with the help of maven-bundle-plugin present in pom.xml or by making a bundle of jar file(I wont recommend that)which you have done.
I hope this helps!

Read emails on Tomcat: ClassNotFoundException: javax.mail.MessagingException

My application is running on Tomcat 7.
I'm trying to read emails from inbox, and for that I use a normal Java class.
There is also a Servlet that calls the method readMails in the mentioned class.
Now I get an exception:
java.lang.ClassNotFoundException: javax.mail.MessagingException
...
I use IntelliJ IDEA with Maven, I changed the dependency of javax.mail a lot (see http://mvnrepository.com/artifact/javax.mail), but the exception keeps coming up.
I've also changed the Version of Tomcat (7 and 8), and the version of "Project SDK" (1.7 and 1.8) and "Project language level" (7 and 8).
I've read somewhere that there is a difference between reading emails via IMAP with normal Java application and running it on Tomcat.
In a previous project I read emails successfully with a normal Java application.
Can anyone help me with this exception?
JavaMail API is not included by default among Tomcat libraries.
Make sure that JavaMail dependency (mail-X.X.jar) is either packaged together with your application (in WEB-INF/lib) or is in a folder that Tomcat class loaders read (for example $CATALINA_HOME/lib), as described here:
http://tomcat.apache.org/tomcat-7.0-doc/class-loader-howto.html
Thanks, it works now.
I put the jar file (javax.mail: javax.mail-api-1.5.4.jar) downloaded by maven (.m2/repository/ ...) into WEB-INF/lib (in my project).
I also needed to put another jar file into WEB-INF/lib (com.sun.mail: javax.mail-1.5.4.jar) due to this exception:
java.lang.NoClassDefFoundError: com/sun/mail/util/MailLogger
javax.mail.Session.initLogger(Session.java:226)
javax.mail.Session.<init>(Session.java:210)
javax.mail.Session.getDefaultInstance(Session.java:321)
I added
<packaging>war</packaging>
to my pom.xml. This way maven puts the dependencies in the target folder.

maven provided dependency will cause NoClassDefFoundError in intellij?

IntelliJ doesn't seem to put the provided dependency on the classpath when I run it, however I can do this successfully in Eclipse.
As it would be a lot more convenient for me, how can I do this in IntelliJ?
I'm having the same problem. Intellij does not include provided dependencies in classpath. See this source. The best solution I found is to run it as maven app, using the exec:java goal. For example:
exec:java -Dexec.classpathScope=compile -Dexec.mainClass=com.splout.db.integration.NShardEnsemble -Dexec.args=4
Better solutions are welcome.
Does it work in Maven via command line? The behaviour seems correct. Eclipse used to handle classpath badly, so I guess it still does.
There is a difference if you run something in Test source root or Source root, since the scope provided is only available on the compilation and test classpath.
If you run a test, or a main method in Test source root, then it can use provided dependencies, but if you try to execute something (via IntelliJ, or exec-maven-plugin) in Source root, then it will fail on ClassNotFoundException.
IntelliJ now has an option to Include dependencies with provided scope in the Run Configuration:
Any library marked as scope - provided means that the library (as the name suggests) is supposed to be provided by the JDK or the container (e.g. tomcat) at runtime.
this answer is based on #Meo's answer.
ALT + Enter to create a unit test:
then run it :

equinox jetty NoClassDefFoundError: SslContextFactory

i have a osgi project in indigo ide, which use equinox 3.7.0 + jetty 7.5.1, now i upgrade ide to juno, which contain equinox 3.8.0 + jetty 8.1.3, so,
the tragedy go on:
when compiling, complain accesible restrictation on SslContextFactory's methods, i resolved it by editing it's access rules in build path.
when running, have a error, say
java.lang.NoClassDefFoundError: org/eclipse/jetty/util/ssl/SslContextFactory
now i have no idea, thanks for ur help.
The access rules are there for a reason.... by hiding the build-time error, you just made the runtime error appear.
The proper solution is to import the package org.eclipse.jetty.util.ssl in your bundle.
If you use a tool such as Bndtools then these Import-Package dependencies will be detected and generated automatically.

Getting jar not in the pom.xml

I am confused why my web application is getting a Jar in its Maven Dependencies even if I think its not on the pom.xml file.
Here's my complete pom.xml which the applications gets objectify-2.2.3.jar
However I need to put a new version of this jar and I am not sure why my application gets this jar.
Do just a
mvn dependency:tree
on the console and check the output.
I suppose this jar is referenced by one of your direct dependencies.
Some IDEs can show the full dependency tree. I know this could be done with IntelliJ IDEAs maven view. I think Eclipse has a similar view.
There is also a maven plugin for this.

Resources