javax/mail/MessagingException in Spring 4 MVC - java

I have an application (Spring 4 MVC+Hibernate 4+MySQL+Maven integration example using annotations) , integrating Spring with Hibernate using annotation based configuration.
I have this error when starting the appl.
GRAVE: Excepción enviando evento inicializado de contexto a instancia de escuchador de clase org.springframework.web.context.ContextLoaderListener
java.lang.NoClassDefFoundError: javax/mail/MessagingException
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2615)
at java.lang.Class.getDeclaredMethods(Class.java:1860)
at org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:609)
at org.springframework.util.ReflectionUtils.doWithMethods(ReflectionUtils.java:521)
at org.springframework.util.ReflectionUtils.doWithMethods(ReflectionUtils.java:507)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.determineCandidateConstructors(AutowiredAnnotationBeanPostProcessor.java:241)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.determineConstructorsFromBeanPostProcessors(AbstractAutowireCapableBeanFactory.java:1069)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1042)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:510)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:772)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:839)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:538)
at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:446)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:328)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:107)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:5001)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5517)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1574)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1564)
at java.util.concurrent.FutureTask.run(FutureTask.java:262)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.ClassNotFoundException: javax.mail.MessagingException
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1854)
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1703)
... 30 more
I have this in the pom.xml
<dependency>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
<version>1.4</version>
</dependency>
and I've checked the repository and is there:
/Users/paquirrin/.m2/repository/javax/mail/mail/1.4
I've updated the maven project 1000 times, but it doesn't work!
I run the project in a tomcat7 at localhost

Seems you are using the wrong dependency. Try the following:
<dependency>
<groupId>javax.mail</groupId>
<artifactId>mailapi</artifactId>
<version>1.4.3</version>
</dependency>
Make sure to refresh the dependencies, and rebuild the project.

The artifact has been already moved from javax.mail >> javax.mail-api.
So, it is better not to use this given below.
<!-- https://mvnrepository.com/artifact/javax.mail/mail -->
<dependency>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
<version>1.4</version>
</dependency>
Instead, use this latest dependency :
<!-- https://mvnrepository.com/artifact/javax.mail/javax.mail-api -->
<dependency>
<groupId>javax.mail</groupId>
<artifactId>javax.mail-api</artifactId>
<version>1.5.6</version>
</dependency>
After adding this dependency, then do these steps:
Go to Project Menu >> Activate Build Automatically Option >> Then Click on Clean Option there.
After that, do Maven Clean and Maven Install.
Delete the war and the extracted war folder from tomcat/webapps and redeploy the war again.
Through this, the problem may be solved.

You should not have a need to add the mail api's to your classpath, since spring will include them transitively (given you are using spring-boot).
In case you are using spring-framework without boot, you can (as suggested in the documentation), also ensure the JavaMail library (com.sun.mail:javax.mail) is on the classpath.
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
<version>4.3.27.RELEASE</version>
</dependency>
<dependency>
<groupId>com.sun.mail</groupId>
<artifactId>javax.mail</artifactId>
<version>1.6.2</version>
</dependency>

There is a requirement for some jars according to Spring 4 docs in order to make it work. You are probably missing some of them.
The following additional jars to be on the classpath of your application in order to be able to use the Spring Framework’s email library.
The JavaMail mail.jar library
The JAF activation.jar library
All of these libraries are freely available on the web.
Or there might be something with Maven. Sometimes it helps if you remove .m2 folder and then run mvn install on your project to download all the dependencies with the right versions.

Related

Unable to connect to Elastic Search

I am building a simple REST API which queries ElasticSearch. I am not using the ElasticSearch REST API way rather than I am using the TCP way.
My goal is to make REST API using spring boot which will communicate with ElasticSearch via TCP.
I am using ElasticSearch sever 5.6
I have a ElasticSearchClientFactory which contains the code to establish connection with ElasticSearch server.
ElasticSearchClientFactory.java ' buildClient
void buildClient() {
Settings settings = Settings.builder().put("cluster.name", elasticSearchProperties.getClusterName()).build();
TransportClient transportClient = new PreBuiltTransportClient(settings);
if (!StringUtils.isEmpty(elasticSearchProperties.getHostname())
&& !StringUtils.isEmpty(elasticSearchProperties.getPort() + "")) {
try {
transportClient.addTransportAddress(
new InetSocketTransportAddress(InetAddress.getByName(elasticSearchProperties.getHostname()),
elasticSearchProperties.getPort()));
transportClient.connectedNodes();
this.client = transportClient;
} catch (UnknownHostException e) {
LOGGER.error("Unable to Connect to ElasticSearch,UnknownHost" + elasticSearchProperties.getHostname());
}
} else {
LOGGER.error("Missing ElasticSearch configuration hostname and portNumber");
throw new DataAccessException(CommonConstants.DAE001, "Unable to connect to ElasticSearch");
}
}
pom.xml contains following related dependencies related to ElasticSearch
<dependency>
<groupId>org.elasticsearch</groupId>
<artifactId>elasticsearch</artifactId>
<version>5.5.2</version>
</dependency>
<dependency>
<groupId>org.elasticsearch.client</groupId>
<artifactId>transport</artifactId>
<version>5.5.2</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.7</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.7</version>
</dependency>
Following logs printing at server startup-
2017-09-14 16:52:28:840 search org.springframework.boot.SpringApplication [main] ERROR - Application startup failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'elasticSearchClientFactory' defined in file [D:\projects\verizon\mesh_workspace\search\target\classes\com\sapient\mesh\productlisting\config\ElasticSearchClientFactory.class]: Invocation of init method failed; nested exception is java.lang.NoSuchMethodError: io.netty.util.internal.ObjectUtil.checkPositive(ILjava/lang/String;)I
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1583)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:545)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:732)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:861)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:541)
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:761)
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:371)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:315)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1186)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1175)
at com.sapient.mesh.SearchApplication.main(SearchApplication.java:20)
Caused by: java.lang.NoSuchMethodError: io.netty.util.internal.ObjectUtil.checkPositive(ILjava/lang/String;)I
at io.netty.util.NettyRuntime$AvailableProcessorsHolder.setAvailableProcessors(NettyRuntime.java:44)
at io.netty.util.NettyRuntime.setAvailableProcessors(NettyRuntime.java:87)
at org.elasticsearch.transport.netty4.Netty4Utils.setAvailableProcessors(Netty4Utils.java:82)
at org.elasticsearch.transport.netty4.Netty4Transport.<init>(Netty4Transport.java:138)
at org.elasticsearch.transport.Netty4Plugin.lambda$getTransports$0(Netty4Plugin.java:93)
at org.elasticsearch.client.transport.TransportClient.buildTemplate(TransportClient.java:174)
at org.elasticsearch.client.transport.TransportClient.<init>(TransportClient.java:265)
at org.elasticsearch.transport.client.PreBuiltTransportClient.<init>(PreBuiltTransportClient.java:130)
at org.elasticsearch.transport.client.PreBuiltTransportClient.<init>(PreBuiltTransportClient.java:116)
at org.elasticsearch.transport.client.PreBuiltTransportClient.<init>(PreBuiltTransportClient.java:106)
at com.sapient.mesh.productlisting.config.ElasticSearchClientFactory.buildClient(ElasticSearchClientFactory.java:62)
at com.sapient.mesh.productlisting.config.ElasticSearchClientFactory.afterPropertiesSet(ElasticSearchClientFactory.java:53)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1642)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1579)
... 16 common frames omitted
In java NoSuchMethodError usually tells that you have multiple instances of same library (or sometime you have only one, but it's a wrong one).
If I were you I would:
check maven tree with mvn dependency:tree -Dverbose. In the tree you going to see 2 instances of same library (probably 2 different versions). You need to manually exclude a dependency in pom.xml from the entry that has this lib as a dependency. Well, sometime extra lib can come from a server (e.g. glassfish) instead of maven, in that case check below.
Put a breakpoint to NettyRuntime.java:44, connect in a debug mode and when you hit it, evaluate the path of wrong library. To evaluate the path you need to ask a classLoader where the lirary is located. You can do this, evaluate code in debug mode*. (io.netty.util.internal.ObjectUtil class.getClassLoader()).getResource("io.netty.util.internal.ObjectUtil.class")) this will provide you a path to a library, from that point you would know what you need to exclude and where it came from
*Evaluate code or Evaluate expression is an option that should be available in debug mode in your IDE (Eclipse/Jetbrains/Netbeans or w/e you use, should support it)

spring-boot: response compression while executed from Maven command line

I'm interested in enabling HTTP response compression for my Java 8 / spring-boot 1.3.2 / Maven 3.3 based application.
Following the spring-boot reference documentation from http://docs.spring.io/spring-boot/docs/1.3.x/reference/htmlsingle/#how-to-enable-http-response-compression, I have added the following change to my application.properties:
server.compression.enabled=true
While the application started successfully before the above addition, with it the application fails to start with the following error when using the Maven command below:
mvn clean spring-boot:run
...
...
2016-01-26 09:48:48.802 ERROR 15204 --- [ main] o.s.boot.SpringApplication : Application startup failed
org.springframework.context.ApplicationContextException: Unable to start embedded container; nested exception is java.lang.IllegalStateException: Compression is enabled, but GzipHandler is not on the classpath
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:133) ~[spring-boot-1.3.2.RELEASE.jar:1.3.2.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:532) ~[spring-context-4.2.4.RELEASE.jar:4.2.4.RELEASE]
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:118) ~[spring-boot-1.3.2.RELEASE.jar:1.3.2.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:766) [spring-boot-1.3.2.RELEASE.jar:1.3.2.RELEASE]
at org.springframework.boot.SpringApplication.createAndRefreshContext(SpringApplication.java:361) [spring-boot-1.3.2.RELEASE.jar:1.3.2.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:307) [spring-boot-1.3.2.RELEASE.jar:1.3.2.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1191) [spring-boot-1.3.2.RELEASE.jar:1.3.2.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1180) [spring-boot-1.3.2.RELEASE.jar:1.3.2.RELEASE]
at com.miletwentyfour.client.Application.main(Application.java:43) [classes/:na]
Caused by: java.lang.IllegalStateException: Compression is enabled, but GzipHandler is not on the classpath
at org.springframework.boot.context.embedded.jetty.JettyEmbeddedServletContainerFactory.createGzipHandler(JettyEmbeddedServletContainerFactory.java:192) ~[spring-boot-1.3.2.RELEASE.jar:1.3.2.RELEASE]
at org.springframework.boot.context.embedded.jetty.JettyEmbeddedServletContainerFactory.addHandlerWrappers(JettyEmbeddedServletContainerFactory.java:168) ~[spring-boot-1.3.2.RELEASE.jar:1.3.2.RELEASE]
at org.springframework.boot.context.embedded.jetty.JettyEmbeddedServletContainerFactory.getEmbeddedServletContainer(JettyEmbeddedServletContainerFactory.java:148) ~[spring-boot-1.3.2.RELEASE.jar:1.3.2.RELEASE]
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.createEmbeddedServletContainer(EmbeddedWebApplicationContext.java:160) ~[spring-boot-1.3.2.RELEASE.jar:1.3.2.RELEASE]
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:130) ~[spring-boot-1.3.2.RELEASE.jar:1.3.2.RELEASE]
... 8 common frames omitted
My next step, per the reference documentation section 64.18.2, was to add the following dependency to the pom.xml:
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-servlets</artifactId>
<version>9.3.7.v20160115</version>
</dependency>
Using mvn:dependency:tree I can verify that jetty-servlets is included in the application as a compile time scoped dependency. Yet, the application fails to start with the same error output as above.
Can anyone please point out what I am missing and/or what do I need to do to get response compression to work successfully when launching the application from a Maven command line?
You need following maven dependancy:
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-server</artifactId>
<version>9.3.7.v20160115</version>
</dependency>
Andy Wilkinson was correct and provided the needed information I was missing.
For the benefit of others, I was mixing Spring Boot 1.3 with the 9.3.x flavors of spring-jetty. Once I used the latest of spring-jetty 9.2.x -- I used 9.2.14.v20151106 -- my application started as normal.
To summarize, here the changes I made:
application.properties:
server.compression.enabled=true
pom.xml:
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-servlets</artifactId>
<version>9.2.14.v20151106</version>
</dependency>

mapping classes in simple jpa project

I whant to configure a simple JPA project, i using Wildfly 8, and the datasource is configured in standalone.xml.
<datasource jta="true" jndi-name="java:jboss/datasources/postgresql" pool-name="postgreSql" enabled="true" use-ccm="true">
<connection-url>jdbc:postgresql://localhost:5432/sell</connection-url>
<driver-class>org.postgresql.Driver</driver-class>
<driver>postgres</driver>
<security>
<user-name>postgres</user-name>
<password>sell</password>
</security>
</datasource>
in Web project i configure the persistence.xml file like this
http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
<persistence-unit name="sellAppPersistenceUnit"
transaction-type="RESOURCE_LOCAL">
<jta-data-source>java:jboss/datasources/postgresql</jta-data-source>
<class>br.com.sell.app.orm.Usuario</class>
</persistence-unit>
but, when i add a br.com.sell.app.orm.Usuario i got a error on project startup, the error indicates a hibernate problem org/hibernate/proxy/HibernateProxy, but i don't use hibernate.
13:17:50,738 ERROR [org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer] (ServerService Thread Pool -- 58) HHH000142: Javassist Enhancement failed: br.com.sell.app.orm.Usuario: java.lang.RuntimeException: by java.lang.NoClassDefFoundError: org/hibernate/proxy/HibernateProxy
at javassist.util.proxy.ProxyFactory.createClass3(ProxyFactory.java:515)
at javassist.util.proxy.ProxyFactory.createClass2(ProxyFactory.java:492)
at javassist.util.proxy.ProxyFactory.createClass1(ProxyFactory.java:428)
at javassist.util.proxy.ProxyFactory.createClass(ProxyFactory.java:400)
at org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer.getProxyFactory(JavassistLazyInitializer.java:162)
at org.hibernate.proxy.pojo.javassist.JavassistProxyFactory.postInstantiate(JavassistProxyFactory.java:67)
at org.hibernate.tuple.entity.PojoEntityTuplizer.buildProxyFactory(PojoEntityTuplizer.java:224)
at org.hibernate.tuple.entity.AbstractEntityTuplizer.<init>(AbstractEntityTuplizer.java:212)
at org.hibernate.tuple.entity.PojoEntityTuplizer.<init>(PojoEntityTuplizer.java:80)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
at org.hibernate.tuple.entity.EntityTuplizerFactory.constructTuplizer(EntityTuplizerFactory.java:135)
at org.hibernate.tuple.entity.EntityTuplizerFactory.constructDefaultTuplizer(EntityTuplizerFactory.java:188)
at org.hibernate.tuple.entity.EntityMetamodel.<init>(EntityMetamodel.java:403)
at org.hibernate.persister.entity.AbstractEntityPersister.<init>(AbstractEntityPersister.java:520)
at org.hibernate.persister.entity.SingleTableEntityPersister.<init>(SingleTableEntityPersister.java:148)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
Why i can solve this problem?
the pom.xml file:
http://maven.apache.org/xsd/maven-4.0.0.xsd">
4.0.0
br.com.sell.app
sellApp
0.0.1-SNAPSHOT
pom
sellApp
Backend rest sell app
<modules>
<module>sellAppEndpoint</module>
<module>sellAppWeb</module>
<module>sellAppCors</module>
<module>sellAppDto</module>
<module>sellAppOrm</module>
<module>sellAppJpa</module>
</modules>
<dependencies>
<!-- para importar pacotes javax.* para o REST -->
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>7.0</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>3.3.0.SP1</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>5.0.0.Final</version>
</dependency>
</dependencies>
Your problem seems to be due to declaring inconsistent dependencies - hibernate-entitymanager in version 5.0.0 requires hibernate-core 5.0.0, but you force to use hibernate-core in version 3.3.0.SP1. The class org.hibernate.proxy.HibernateProxy does not exist in version 3.3.0.SP1. As hibernate-entitymanager declares transitive dependency on hibernate-core, you can just remove the dependency on hibernate-core.
Furthermore, Wildfly 8 already includes hibernate (version 4.3), as it must provide Java EE functionality by specification. You may just use hibernate on Wildfly, which is more standard, unless you don't require special features of hibernate 5.0. In that case remove also hibernate-entitymanager dependency from pom.xml and your code should still work.

NoSuchMethodError on startup in Java Jersey app

I've been getting a very strange error when trying to start a Jersey app on Tomcat. The same code works on other computers. I tried reinstalling tomcat, all my maven dependencies, even Eclipse and Java itself, no luck. It seems like a bad Jersey version is being loaded, I think?
Any pointers in the right direction will be appreciated.
Here's the effective pom: http://pastebin.com/NacsWTjz
And the actual pom: http://pastebin.com/H6sHe4ce
2015-02-13 13:43:40,870 [localhost-startStop-1] ERROR org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/middleware-server] - StandardWrapper.Throwable
java.lang.NoSuchMethodError: javax.ws.rs.core.Application.getProperties()Ljava/util/Map;
at org.glassfish.jersey.server.ApplicationHandler.<init>(ApplicationHandler.java:304)
at org.glassfish.jersey.server.ApplicationHandler.<init>(ApplicationHandler.java:285)
at org.glassfish.jersey.servlet.WebComponent.<init>(WebComponent.java:311)
at org.glassfish.jersey.servlet.ServletContainer.init(ServletContainer.java:170)
at org.glassfish.jersey.servlet.ServletContainer.init(ServletContainer.java:358)
at javax.servlet.GenericServlet.init(GenericServlet.java:158)
at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1231)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1144)
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1031)
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4901)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5188)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1409)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1399)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Note: Please see above comments for further discussion and tips.
This error usual means that you have a both a JAX-RS 1 and JAX-RS 2 jar on the classpath. Jersey 2 uses JAX-RS 2 (javax.ws.rs-api-2.0.1.jar), but if you have the jsr311-api.jar also, which is JAX-RS 1, there is a javax.ws.rs.core.Application in each jar. But the jsr311-api Application doesn't have the method getProperties() (hence NoSuchMethodError).
I've come to the conclusion that all you need to do is add the above exclusion to the swagger dependency. The Jackson 2.0 provider (which depends on JAX-RS 1) seems to be overridden by a 2.4.1 provider (which uses the new version). So we don't need to add it ourselves. When it's overridden, it seems to leave behind the jsr311-api.jar. So if we exclude it, no one can attempt to use it, which looks to be the current problem
<dependency>
<groupId>com.wordnik</groupId>
<artifactId>swagger-core_2.10</artifactId>
<version>1.3.11</version>
<exclusions>
<exclusion>
<groupId>javax.ws.rs</groupId>
<artifactId>jsr311-api</artifactId>
</exclusion>
</exclusions>
</dependency>
We are using jersey-json 1.9 which has a dependency on jersey-core which also happen to have a javax.ws.rs.core.Application class.
So our fix is to exclude the jersey-core from jersey-json:
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-json</artifactId>
<version>1.9</version>
<exclusions>
<exclusion>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-core</artifactId>
</exclusion>
</exclusions>
</dependency>
the problem is related about "com.sun.jersey:jersey-core:jar:1.18.3" (or any 1.* version) because old versions of Jersey didn't have that "public Map getProperties()" method.
And one of your dependencies use Jersey version 1 (you can check that in running mvn dependency:tree and search all jersey-core version used)
Me I have resolved the problem deleting all com.sun.jersey dependancies (old api) and using the new one org.glassfish.jersey API
https://mvnrepository.com/artifact/org.glassfish.jersey.core

no such method jsch.JSch.setLogger

The below behavior occurs when i call the getSftpUtil(). I have also ensured that all the appropriate jars are in the maven project's external libraries and are available in the WEB-INF/lib folder of the project
code
net.sf.opensftp.SftpUtil util = SftpUtilFactory.getSftpUtil();
stacktrace
SftpUtilFactory: Trying to get SftpUtil class name from the system property net.sf.opensftp.SftpUtil
SftpUtilFactory - Trying to get SftpUtil class name from the system property net.sf.opensftp.SftpUtil
SftpUtilFactory: The system property net.sf.opensftp.SftpUtil is not set.
SftpUtilFactory - The system property net.sf.opensftp.SftpUtil is not set.
SftpUtilFactory: Use the default one.
SftpUtilFactory - Use the default one.
Caused by: java.lang.NoSuchMethodError: com.jcraft.jsch.JSch.setLogger(Lcom/jcraft/jsch/Logger;)V
at net.sf.opensftp.impl.SftpUtil.<clinit>(SftpUtil.java:110)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:169)
at net.sf.opensftp.SftpUtilFactory.getSftpUtil(SftpUtilFactory.java:184)
Based on jcraft's change log, setLogger is a method added to JSch.java in jsch-0.1.30. So the jar under your WEB-INF/lib should be an older version.
You can run
mvn dependency:tree
to see which of your dependencies is using the older version, and then exclude it with something like this:
<dependency>
<groupId>...</groupId>
<artifactId>...</artifactId>
<version>...</version>
<exclusions>
<exclusion>
<groupId>com.jcraft</groupId>
<artifactId>jsch</artifactId>
</exclusion>
</exclusions>
</dependency>
You probably have another dependency refer to a more recent version of jsch, so your problem should be solved at this point. However, if that's not the case, you can add this to pom.xml:
<dependency>
<groupId>com.jcraft</groupId>
<artifactId>jsch</artifactId>
<version>0.1.50</version>
</dependency>
Well, I guess you are missing this dependency or the proper version:
<groupId>com.jcraft</groupId>
<artifactId>jsch</artifactId>
<version>0.1.49</version> <!--latest version -->

Categories

Resources