java.lang.NoSuchMethodError: org.hsqldb.DatabaseURL.parseURL maven runtime - java

Getting the following error. The problem is it happens intermittently when we restart our server. Sometimes the error comes and sometimes not. How to resolve this? I am using maven.
java.lang.NoSuchMethodError: org.hsqldb.DatabaseURL.parseURL(Ljava/lang/String;ZZ)Lorg/hsqldb/persist/HsqlProperties;
org.codehaus.groovy.runtime.InvokerInvocationException: java.lang.NoSuchMethodError: org.hsqldb.DatabaseURL.parseURL(Ljava/lang/String;ZZ)Lorg/hsqldb/persist/HsqlProperties;
Edit: It's not working. Old version is coming from hadoop-client:2.0.0-mr1-cdh4.2.0. I excluded hsqldb from this and checked in dependency tree and the old version is not showing up. But still I am getting the error at runtime.

You almost certainly have a dependency mismatch.
Make sure you know which version of hsqldb you expect to be using.
Check the list of dependencies that are in use by the app, by that I mean the actual JAR files in the built application, not the list of maven dependencies.
Most likely you have either the wrong version of the hsqldb jar or multiple different versions (ie the right version and a wrong version).
This can be caused by unexpected transitive dependencies being pulled in
To identify where the transitive dependencies are coming from, you can use the maven dependency:tree goal:
E.g.
mvn dependency:tree -Dverbose -Dincludes=hsqldb
Where hsqldb is the name of the artifact you are looking for.
http://maven.apache.org/plugins/maven-dependency-plugin/examples/resolving-conflicts-using-the-dependency-tree.html
Oncer you have identified where the multiple versions are coming from, you can exclude from those dependencies, e.g.:
<dependency>
<groupId>sample.ProjectA</groupId>
<artifactId>Project-A</artifactId>
<version>1.0</version>
<scope>compile</scope>
<exclusions>
<exclusion> <!-- declare the exclusion here -->
<groupId>sample.ProjectB</groupId>
<artifactId>Project-B</artifactId>
</exclusion>
</exclusions>
</dependency>
More details here: http://maven.apache.org/guides/introduction/introduction-to-optional-and-excludes-dependencies.html

I had this same error, and was
I was able to get this to work using gt-epsg-wkt instead of hsql.
<dependency>
<groupId>org.geotools</groupId>
<artifactId>gt-epsg-wkt</artifactId>
<version>${geotools.version}</version>
</dependency>

Related

Unresolved Dependency in Maven

Can anyone tell me please what's wrong with my dependency Hamcrest in Maven?
That's a pity but I can't attach screenshot here.
The screenshot from IntelliJ IDEA
One the right side one can see that the dependency hamcrest-all:1.3 is inside dependency junit:4.11.
Maybe something wrong with my pom.xml file?
There is also a problem with hamcrest version 1.3 - dependency hamcrest:hamcrest-all:1.3 not found.
When I try to update Maven indices, nothing happens.
There is a slight difference between the group ids. Notice in the maven repository group id is org.hamcrest
http://mvnrepository.com/artifact/org.hamcrest/hamcrest-all/1.3
Sometimes, not specifying the dependency's version can give this Error
Unresolved Dependency
just specify the version of the dependency
example:
instead of this:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-bootstrap</artifactId>
</dependency>
use this:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-bootstrap</artifactId>
<version>3.1.2</version>
</dependency>

NoSuchMethodError: com.google.common.base.Stopwatch.createStarted()Lcom/google/common/base/Stopwatch

My app is throwing NoSuchMethodError: com.google.common.base.Stopwatch.createStarted()Lcom/google/common/base/Stopwatch error. Not sure why, because 16.0.1 do contain that class, I've checked. From what I have researched, it looks like this is a bug?
I also have this code for refernence, though I think this is not the issue:
FirewallRule rule = new PeriodicFirewallCounterRule(60, TimeUnit.SECONDS, new IpAddressCountingPolicy());
((PeriodicFirewallCounterRule)rule).addHandler(new RateLimitationHandler(new UniqueLimitPolicy(10)));
FirewallFilter firewallFiler = new FirewallFilter(getContext(), list(rule));
firewallFiler.setNext(ma);
My app is using Restlet APISpark:
<dependency>
<groupId>org.restlet.gae</groupId>
<artifactId>org.restlet.ext.apispark</artifactId>
<version>${version.restlet}</version>
</dependency>
When running and accessing the REST api of the app, it throws this
error:
[INFO] Caused by: java.lang.NoSuchMethodError: com.google.common.base.Stopwatch.createStarted()Lcom/google/common/base/Stopwatch;
[INFO] at org.restlet.ext.apispark.internal.firewall.rule.counter.PeriodicCounter.<init>(PeriodicCounter.java:65)
[INFO] at org.restlet.ext.apispark.internal.firewall.rule.PeriodicFirewallCounterRule$1.load(PeriodicFirewallCounterRule.java:86)
[INFO] at org.restlet.ext.apispark.internal.firewall.rule.PeriodicFirewallCounterRule$1.load(PeriodicFirewallCounterRule.java:84)
[INFO] at com.google.common.cache.LocalCache$LoadingValueReference.loadFuture(LocalCache.java:3599)
[INFO] at com.google.common.cache.LocalCache$Segment.loadSync(LocalCache.java:2379)
[INFO] at com.google.common.cache.LocalCache$Segment.lockedGetOrLoad(LocalCache.java:2342)
[INFO] at com.google.common.cache.LocalCache$Segment.get(LocalCache.java:2257)
[INFO] ... 74 more
When using the extension org.restlet.ext.apispark, the guava dependency retrieved has the version 16.0.1.
Downloading: http://maven.restlet.com/com/google/guava/guava/16.0.1/guava-16.0.1.jar
Downloading: http://repo.maven.apache.org/maven2/com/google/guava/guava/16.0.1/guava-16.0.1.jar
Downloaded: http://repo.maven.apache.org/maven2/com/google/guava/guava/16.0.1/guava-16.0.1.jar (2176 KB at 711.7 KB/sec)
It comes within an application created from scratch with the following maven configuration:
<project (...)>
<modelVersion>4.0.0</modelVersion>
<groupId>org.restlet</groupId>
<artifactId>restlet-apispark-firewall</artifactId>
<name>${project.artifactId}</name>
<packaging>jar</packaging>
<version>1.0.0-snapshot</version>
<properties>
<java-version>1.7</java-version>
<restlet-version>2.3.1</restlet-version>
</properties>
<dependencies>
<dependency>
<groupId>org.restlet.jse</groupId>
<artifactId>org.restlet</artifactId>
<version>${restlet-version}</version>
</dependency>
<dependency>
<groupId>org.restlet.jse</groupId>
<artifactId>org.restlet.ext.apispark</artifactId>
<version>${restlet-version}</version>
</dependency>
</dependencies>
<repositories>
<repository>
<id>maven-restlet</id>
<name>Public online Restlet repository</name>
<url>http://maven.restlet.com</url>
</repository>
</repositories>
</project>
I integrated your code and it works fine on my side. No exception is thrown...
I think that an older version of Guava comes from another dependency. If you use Maven, you should identify where this old guava version comes from and perhaps add an exclude within the corresponding dependency. I hope that it will fix your problem...
Hope that helps you,
Thierry
This is the solution that fixed the error:
First exclude old Guava dependency then:
<dependency>
<groupId>org.restlet.gae</groupId>
<artifactId>org.restlet.ext.apispark</artifactId>
<version>${version.restlet}</version>
<exclusions>
<exclusion>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.5.1</version>
</dependency>
The class Stopwatch loaded by that ClassLoader does not contain that method, not sure if caused by multiple incompatible jars as Jens says or simply because 16.0.1 does not really have that method.
A simple check will be to parse the class with javap or a decompiler:
javap -p Stopwatch.class
And then check if that method is listed.
Edit: That method is there since 15.0, so i'd check the content of you classpath too.
Referring to NoSuchMethodError Oracle Documentation :
The NoSuchMethodError: is thrown if an application tries to call a specified method of a class (either static or instance), and that class no longer has a definition of that method.
Normally, this error is caught by the compiler; this error can only occur at run time if the definition of a class has incompatibly changed.
I think you got this Exception because you have more than one version of this jar in your classpath, and since the createStarted() method is available from the 15.0 version I whould say that you have an other old version of it, probably due to a dependency problem.
Moving to the latest version of Guava did it for me
In my case one of my Maven dependencies was picking up a newer version of Guava (16.0.1) that apparently does not have this method. When I added an exclusion to that dependency in my pom.xml, instead an older (correct) version of Guava was picked up by another of my dependencies and then it worked.
You can find this by printing your dependency tree via mvn dependency:tree and then looking at what is picking up the newer version of guava. You might need to add more than one exclusion to get it right.

Hibernate: error on asm jar working in one workspace , not in another workspace

This error:
java.lang.NoSuchMethodError: org.objectweb.asm.ClassWriter
while running Hibernate mostly occurs when the asm jar is not updated to the latest, and well be resolved by upgrading the asm jar version. That's not my question.
As well explained in this SO : Error : java.lang.NoSuchMethodError: org.objectweb.asm.ClassWriter.<init>(I)V
ie: by excluding current usage
<exclusion>
<groupId>asm</groupId>
<artifactId>asm</artifactId>
</exclusion>
<exclusion>
<groupId>asm</groupId>
<artifactId>asm-attrs</artifactId>
</exclusion>
and include
<dependency>
<groupId>asm</groupId>
<artifactId>asm</artifactId>
<version>3.1</version>
</dependency>
My specific question/looking for some kind of confirmation:
I created a maven project with Spring, Hibernate
Spring: 3.2.2.RELEASE, Hibernate: 3.2.7.ga [The asm jar version resolved by Maven is asm1.5.3]
This is running good, no issues.
Recently another person reported an error on the same project with the same dependencies with the error stating 'java.lang.NoSuchMethodError: org.objectweb.asm.ClassWriter'
I understand, upgrading the asm version to the latest version might address this issue.
But since we have the same project and dependencies, what else could be the trigger for this issue?
Note: AFAIK there are no new dependencies in the other workspace, other than may be a higher JRE (mine is 1.6)
Try to ask him clean local maven repo. Maybe there is some conflicts in dependencies versions.

Exception in java project [java.lang.IllegalAccessError: tried to access field org.slf4j.impl.StaticLoggerBinder.SINGLETON]

Exception in thread "main" java.lang.IllegalAccessError: tried to access field org.slf4j.impl.StaticLoggerBinder.SINGLETON from class org.slf4j.LoggerFactory
at org.slf4j.LoggerFactory.<clinit>(LoggerFactory.java:60)
at org.hibernate.cfg.Configuration.<clinit>(Configuration.java:151)
at com.erp.utility.Hibernatesession.getSession(Hibernatesession.java:24)
at com.erp.dao.Country_Dao.getcountryByname(Country_Dao.java:88)
at com.erp.service.Country_Service.getcountryByname(Country_Service.java:36)
at com.erp.storedata.Store_Data.main(Store_Data.java:24)
Use a newer version of the slf4j-api.jar. There was a breaking change between version 1.5.5 and earlier and 1.5.6 and later. Use a version after 1.5.6, and that error should go away. For reference, see http://www.slf4j.org/faq.html#IllegalAccessError.
Please add following file on your project:
slf4j-log4j12.jar
remove the file slf4j-api.jar from your build path.
Finally resolved this problem in my SpringBoot application. If updating version is not helping this might help. Sometimes other libraries might bring different versions of this dependencies. These are the steps:
By error stack trace figure out which dependency is giving this issue
Get maven dependency plugin tree. Using this tree details find out if this library is coming as part of the some other dependency. In my case, the logback-classic and log4j-over-slf4j were giving this problem. They came together under spring-boot-starter-web
Use <exclusions><exclusion></exclusion></exclusions> in your pom.xml in that dependency for the libraries that giving this issue. In my case it looks like this:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<artifactId>logback-classic</artifactId>
<groupId>ch.qos.logback</groupId>
</exclusion>
<exclusion>
<artifactId>log4j-over-slf4j</artifactId>
<groupId>org.slf4j</groupId>
</exclusion>
</exclusions>
</dependency>
References:
http://www.slf4j.org/faq.html#IllegalAccessError
http://www.slf4j.org/codes.html#multiple_bindings

Yui compressor StringIndexOutOfBoundsException on jboss

When minimising yui with 2.4.6, I get this problem:
java.lang.StringIndexOutOfBoundsException: String index out of range: 232
at java.lang.String.substring(String.java:1934)
at com.yahoo.platform.yui.compressor.JavaScriptCompressor.printSourceString(JavaScriptCompressor.java:267)
at com.yahoo.platform.yui.compressor.JavaScriptCompressor.parse(JavaScriptCompressor.java:330)
at com.yahoo.platform.yui.compressor.JavaScriptCompressor.<init>(JavaScriptCompressor.java:533)
It works when started through my IDE but when deployed to jboss it doesn't. This place: http://yuilibrary.com/forum/viewtopic.php?p=20086 has some discussion of the same problem.
Apparently the issue is around org/mozilla/javascript/Parser being in the two jars that are pulled in from my maven config:
<dependency>
<groupId>com.yahoo.platform.yui</groupId>
<artifactId>yuicompressor</artifactId>
<version>2.4.6</version>
</dependency>
Is there any way I can solve this using maven exclusions etc. or by upgrading my version of YUI. It seems daft that it just doesn't work and I don't want to have to write a custom classloader.
Please help!
Workaround: For JBoss AS 7.1.1.Final and YUICompressor 2.4.7
Exclude rhino from dependency:
<dependency>
<groupId>com.yahoo.platform.yui</groupId>
<artifactId>yuicompressor</artifactId>
<version>${yuicompressor.version}</version>
<exclusions>
<exclusion>
<groupId>rhino</groupId>
<artifactId>js</artifactId>
</exclusion>
</exclusions>
</dependency>
Why? See https://github.com/greenlaw110/greenscript/pull/29#issuecomment-4017147
Note: if you have a rhino in classpath by some other way, so seems like you'll get this error again.
I solved this problem by repackaging yuicompressor myself to include most of the rhino source. See my reply to Howard M. Lewis Ship.
The repackaged source can be found here : http://viscri.co.uk/labs/tapestry/yuicompressor-rhino-bugfix-5.0.jar. Just add this to your pom:
<dependency>
<groupId>yuicompressorbugfix</groupId>
<artifactId>yuicompressor-rhino-bugfix</artifactId>
<version>5.0</version>
</dependency>
If you don't run your own version of nexus, you'll have to install it on the machine that you want to build on. This is the command you need I think: http://maven.apache.org/guides/mini/guide-3rd-party-jars-local.html
You'll also need to exclude the yuicompressor version that tapestry pulls in:
<dependency>
<groupId>org.apache.tapestry</groupId>
<artifactId>tapestry-yuicompressor</artifactId>
<version>5.3.2</version>
<exclusions>
<exclusion>
<groupId>com.yahoo.platform.yui</groupId>
<artifactId>yuicompressor</artifactId>
</exclusion>
</exclusions>
This should work.
The selected answer's (as of 9/26/2014) jar doesn't exist anymore.
So, I created a fork of yuicompressor where entire rhino package is embedded into the yuicompressor package and namespaced it under yui.
https://github.com/timothykim/yuicompressor
Just clone the repo and run ant to obtain the jar.
Hope this helps anyone else who stumbles unto this problem.
Really, you're having class loader problems in JBoss?
You're going to have to do some kind of exclusion on the competing rhino JAR file. Why is Rhino on the classpath? It may be an optional feature of JBoss you can turn off and avoid the conflict that way.

Categories