Error: ClassCastException occured while adding dependency jar in pom.xml - maven

Can any one suggest how to resolve the ClassCastException while adding dependency jar in pom.xml?
I have created a new maven project having returning the object in runtime and then execute the ovverride method definition as based upon client request.
Ex: actionPerform(actionType) -- this method return the 'Object'
public static CommonActions action(ActionTypes actionType)
{
return (CommonActions)actionPerform(actionType);
}
Code is working fine and then successfully executing. There is no ClassCastExceptions while adding this jar into library tab on project properties using eclipse.
Getting ClassCastExceptions on above return statement while adding the below depenedency in pom.xml
<dependency>
<groupId>com.amadeus.selenium.merci</groupId>
<artifactId>appium-amadeus-utilities</artifactId>
<version>1.4-SNAPSHOT</version>
<scope>runtime</scope>
</dependency>
I am using maven version 3.0.4
Please suggest how I resolve the ClassCastException at runtime while adding dependency jar in pom.xml.

Related

Dependency listed in pom file not found in deployed project

I asked a question here that I think I may have found the root of. I have a Spring Boot app using a datasource, net.sourceforge.jtds.jdbc.Driver, that is supposed to be included transitively by Spring Boot 2.0.2 with spring-boot-starter-jpa. However, when I run
jar tf my.jar | grep jtds
the driver class isn't found (we don't have a maven executable on the server to list the classpath). Everything I do to inspect the classpath reflects that the jar isn't there.
I've done this in 2 scenarios: 1) When I didn't explicitly add the jar to my pom, I got the error reported in my previous post. 2) When I do add it explicitly to the pom, I get this error:
java.lang.IllegalStateException: Cannot load driver class: net.sourceforge.jtds.jdbc.Driver
Can someone tell me what's going on?? I am confounded as to why this class can't be found and loaded.
Please mind, that in the Spring Boot Parent POM the jtds dependency is only included in test scope.
If you want to use classes of this dependency also in your production code, please change the Maven scope to compile.
Ok, the problem was solved by adding the dependency with a runtime scope.
In child pom where jar is packaged, you should have
spring-boot-maven-plugin. and dependency as below:
<dependency>
<groupId>net.sourceforge.jtds</groupId>
<artifactId>jtds</artifactId>
</dependency>
In parent pom :
<dependency>
<groupId>net.sourceforge.jtds</groupId>
<artifactId>jtds</artifactId>
<version>${jtds.version}</version>
</dependency>

In Maven project, a class is found in local jar file at compile time, but not run time. why?

In a Maven project, I can include the classes with no problem.
However, during the runtime, I get ClassNotFoundException when I try to create an instance of that class.
Part of the pom.xml file:
<dependency>
<groupId>acmeGamesGroupId</groupId>
<artifactId>acmegames</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>${acmegameslibs}\acme-1.0.jar</systemPath>
</dependency>
Why can a class be found during compile-time, but not in the run-time? What do I need to do in the pom.xml file? help.
You need more info. What is your execution environment: native java, tomcat, what? But my guess is your app is delivered as a jar file.
Unexpectedly the Java class loader cannot find classes in embedded jar files

Grails Fixtures: grails run-app works, but mvn grails:run-app not

I have installed the Grails Fixtures plugin (http://www.grails.org/plugin/fixtures) for loading some initial datas into my database for dev and test environment. I also use Grails with Maven integration.
I have added my data loading code into the BootStrap.groovy:
import grails.util.Environment
class BootStrap {
def fixtureLoader
def init = { servletContext ->
if (Environment.current == Environment.DEVELOPMENT || Environment.current == Environment.TEST) {
//def fixtureLoader = new FixtureLoader(grailsApplication)
fixtureLoader.load("init")
}
}
}
When I run my Grails app with "grail run-app" it works perfectly, but if I use the Maven Grails command "mvn grails:run-app -Dgrails.env=development" then it doesn't work. It throws following error:
Error executing bootstraps; nested exception is java.lang.NullPointerException: Cannot invoke method load() on null object
It seems that the "fixtureLoader" bean is not correctly initialized if I use the Maven Grails command "mvn grails:run-app".
Do you have any idea? Or maybe its a bug...
Add it as a dependency in pom.xml instead of BuildConfig.groovy. Maven looks at the pom to resolve dependencies (in this case a plugin).
<dependency>
<groupId>org.grails.plugins</groupId>
<artifactId>fixtures</artifactId>
<version>1.0.7</version>
<scope>runtime</scope>
<type>zip</type>
</dependency>
Note: scope runtime makes the artifact available in test scope as well.

pom dependency fails in Gradle (ok in Maven)

I'm writing a standalone EJB client for JBoss 7.1 and as suggested I'm using the following dependency:
<dependency>
<groupId>org.jboss.as</groupId>
<artifactId>jboss-as-ejb-client-bom</artifactId>
<type>pom</type>
<version>7.1.1.Final</version>
</dependency>
This works as expected in Maven, however when used in Gradle like so:
dependencies {
compile 'org.jboss.as:jboss-as-ejb-client-bom:7.1.1.Final'
}
It fails with:
Could not find group:org.jboss, module:jboss-remote-naming, version:1.0.2.Final.
What is the reason for different behavior of Gradle vs. Maven?
Well the dependency you declare in Maven points to a pom packaging component, and the one in Gradle points to a jar. However there is no jar with this project since it is a pom packaging component so Gradle obviously fails.
http://search.maven.org/#browse%7C351478366
Using Gradle you probably have to either declare a dependency to the pom somehow (not sure if that is possible) or add the dependencies from the pom to your project yourself.
http://search.maven.org/remotecontent?filepath=org/jboss/as/jboss-as-ejb-client-bom/7.1.3.Final/jboss-as-ejb-client-bom-7.1.3.Final.pom
Use the #pom type:
dependencies {
compile 'org.jboss.as:jboss-as-ejb-client-bom:7.1.1.Final#pom'
}

NoClassDefFoundError with jetty-maven-plugin

I am getting a:
he Cause java.lang.NoClassDefFoundError Msg:net/spy/memcached/MemcachedClient
When executing jetty:run -e in eclipse. Why isn't this dependency being added into the classpath?
Which classpath do you expect it to be added to? If something in your project is trying to load it, ensure you have a project dependency that has that class in it. It looks like it comes from ServiceMix. If you've added something to Jetty itself to make it require that class, then add the dependency to the jetty plugin.
Your code is missing a runtime dependency. I searched Maven Central for the missing class
http://search.maven.org/#search|ga|1|fc%3A%22net.spy.memcached.MemcachedClient%22
Try adding the following to your POM:
<dependency>
<groupId>org.apache.servicemix.bundles</groupId>
<artifactId>org.apache.servicemix.bundles.spymemcached</artifactId>
<version>2.5_2</version>
<packaging>bundle</packaging>
</dependency>
The dependency had a provided scope. Change this.

Resources