javax.persistence.spi.PersistenceUnitInfo.getSharedCacheMode() Ljavax/persistence/SharedCacheMode; - spring

I have persistence-api-1.0.2,hibernate-jpa-2.0-api-1.0.1.Final and other related jars in the lib directory. However, when I am deploying war file, I am getting the following error
nested exception is java.lang.NoSuchMethodError:
javax.persistence.spi.PersistenceUnitInfo.getSharedCacheMode()
Ljavax/persistence/SharedCacheMode;
How can I resolve this issue?
Update
Jars in lib folder

Why would you have JPA API 1.0 (which is what persistence-api-1.0.2 is) and JPA API 2.0 (hibernate-jpa-2.0-api) in the CLASSPATH at the same time??
Decide which version of JPA you are using before you do anything else

Related

Tomcat not starting after changing packaging from jar to war

Firstly, after changing the packaging from jar to war for spring boot application, I am not able to do maven build. Getting below error:
Caused by: org.springframework.beans.factory.BeanDefinitionStoreException: Failed to parse configuration class [com.goel.GameApplication]; nested exception is java.io.FileNotFoundException: Could not open ServletContext resource [/application.properties]
at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:189)
at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:331)
The above error comes when maven tries to run app tests. So I commented out the test and ran maven build and I was able to get a war file.
But after deploying the same war file in tomcat(aws), I am getting the same error.
I have followed the 3 step approach properly.Ref: https://www.javadream.in/convert-jar-to-war-in-spring-boot/
I have checked that the build-path does not exclude resource or application.properties
I have tried moving from spring IDE to Eclipse IDE.
I have opened the war file and have verified that the application.properties file is present under WEB-INF/classes/application.properties.
I have read and tried many other things but nothing helped. Any pointers will be helpful. Thanks in advance.
Please do let me know if more info is required,
Java Version: 1.8 ,
Maven Version: 3.6.3 ,
spring-boot-starter-parent: 2.5.4
Exploded war file
Screenshot for SSGApplication

slf4j Logger, LoggerFactory not working at runtime from a child jar

I am a facing an issue while using slf4j Logger and LoggerFactory in a child jar (suppose CHILD.jar).
I am deploying one EAR in WebSphere. The EAR structure is like below-
Parent ear>
META-INF
Project Specific dependency jars
Project Sub Modules bundled as jars
commons-logging-1.0.4.jar
common-logging-api-1.1.jar
CHILD.jar
In CHILD.jar's MANIFEST.MF we are not giving any CLASSPTH entry as this CHILD.jar is used by several other applications and those other applications may not use any same slf4j implementor.
Below is the MANIFEST file structure-
Manifest-Version: 1.0
Build-Jdk: 1.7.0
Built-By: C12560
Archiver-Version: Plexus Archiver
Created-By: Apache Maven 3.0.4
In our application, we are keeping all the jar at the same hierarchy where the CHILD.jar is present.
Now while deploying, no exception is thrown. At runtime, it is throwing InvocationTargetException (and NoClassDefFoundError) in all those classes where we have used org.slf4j.Logger and org.slf4j.LoggerFactory.
If we comment out all these logger entries, the application is working fine and no exception is thrown at runtime.
Even if we use org.apache.log4j.Logger instead of org.slf4j.Logger, the code is working at runtime(Note- log4j-1.2.13.jar is present in the same hierarchy as CHILD.jar).
Queries-
Is slf4j not getting its implementor?
Any jar I have to include in the hierachy same as CHILD.jar?
Please note- I have tried including jcl-over-slf4j jar and log4j-over-slf4j.jar(and removed common-logging.jar) in the same hierarchy as CHILD.jar but it didn't work.
Any help is highly appreciated.
if you want to use jcl or log4j as implementor of slf4j, what you need is slf4j-jcl.jar or slf4j-log4j.jar.
Besides, when getting a NoClassDefFoundError, you should go through the full stacktrace. Usually it is caused by some other exception.

spring boot System.getProperty("java.class.path") doesn't include lib/ jars

I've got a spring boot app and I'm building a myApp.jar using the spring-boot antlib. When I jar -tf myApp.jar I see that I have a jar called lib/foo.jar. Yet when I print out System.getProperty("java.class.path") I don't see that jar file on the classpath. I also get a ClassNotFound exception from URLClassLoader when the code attempts to use this class for the first time. I'm using the JarLauncher since that's what the antlib defaults to.
Any ideas why this jar file would not be on the classpath?
You won't see a bundled JAR in System.getProperty('java.class.path'). The class path specifies where the JVM will look in the filesystem for classes you attempt to load.
Spring Boot uses fat JARs, which are loaded in a completely different way. Refer to the Spring Boot documentation.

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.

Grails 1.2.1 with Spring 3.0.0 dependency problem under Jetty

Just moved to Grails 1.2.1 (used 1.1.1 before). Changed application.properties, ran grails upgrade, fixed BuildConfig and Bootstrap - everything works just fine from grails console.
However, getting a problem when deploy packaged war under jetty 6.1.22:
1581 [main] ERROR org.springframework.web.context.ContextLoader - Context initialization failed org.springframework.beans.factory.access.BootstrapException: Error executing bootstraps; nested exception is java.lang.NoSuchMethodError: org.codehaus.groovy.grails.commons.spring.ReloadAwareAutowireCapableBeanFactory.setParameterNameDiscoverer(Lorg/springframework/core/ParameterNameDiscoverer;)V
My project is built with maven2. I researched the war dependencies and see that both spring 2.5.6 and 3.0.0.RELEASE are used there.
I then tried to suppress use of spring 2.5.6 and got a problem with Acegi plugin (using version 0.5.1):
2010-03-10 21:06:56.440:WARN::Nested in org.springframework.beans.factory.access.BootstrapException: Error executing bootstraps; nested exception is java.lang.NoSuchMethodError: org.springframework.web.context.ConfigurableWebApplicationContext.setId(Ljava/lang/String;)V
Any help would be greatly appreciated.
The problem is caused by the fact that in new version of Spring
ConfigurableWebApplicationContext is located in spring-web.jar, but the interface it inherits ConfigurableApplicationContext, which contains setId(String) method is in located in spring-context.jar.
If you have a library which has been compiled against older version of spring-context it will fail with NoMethodFound exception.
The solution is to locate and recompile that library against latest Spring version.
If you are using Spring version below 3.0 you could try to put full Spring bundle Jar instead of separate packages.

Resources