BeanComparator generates a NoClassDefFoundError - java

just trying to use a BeanComparator but I get some errors that I do not manage to resolve:
BeanComparator comparator = new BeanComparator("age");
Collections.sort(myList, comparator);
comparator = new BeanComparator("name");
Collections.sort(myList, comparator);
comparator = new BeanComparator("sickness");
Collections.sort(myList, comparator);
Running this code generates the following error:
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/collections/comparators/ComparableComparator
at org.apache.commons.beanutils.BeanComparator.<init>(BeanComparator.java:81)
at testBeanComparator.TestBeanComparator.main(TestBeanComparator.java:23)
This is a basic java application that I set to isolate the BeanComparator issue.
I included the jar with maven:
<dependency>
<groupId>commons-beanutils</groupId>
<artifactId>commons-beanutils-bean-collections</artifactId>
<version>1.8.3</version>
</dependency>
Any idea what causes this mess?
Thx in advance.

make sure you have commons-beanutils.jar along with that commons-logging.jar and commons-collections.jar. I tried following commons-beanutils-1.9.2 , commons-logging-1.2, commons-collections-3.2.1

When you are building the maven project with the dependency in eclipse will build the jar and the output jar file is maven local repository as the location you mentioned.
After building the jar if you need to execute the jar file you should add the commons-beanutils in the class path to execute the jar.
ie) java -jar -cp
As you said dependency is missed so try to add the dependency and you can verify that by right click on project and click build path and click maven dependencies.
If you are building by running mvn command manually then you will get an error when your dependency is missing while building jar file.

Related

Get NoClassDefFound Error in Apache Maven 3.8.6 (JDK-19+Gson2.10)

I am new to java and maven. I am learning and trying to make a system to help me build up JSON data by GOOGLE's gson and maven. This is my using command order:
mvn -f my-app\pom xml clean compile
mvn -f my-app\pom xml install
cd my-app\target
java -jar my-app-1.0.jar
After I run it it show me this error.
in GSONExample.java Line 13:
Gson gson = new Gson();
The following is my using software/IDE version.
Source Editor: VS Code
JDK: JDK-19
apache-maven: 3.8.6
Gson: 2.10 (https://github.com/google/gson/releases)
I have already gone through other websites and StackOverflow to find solutions.
GSON is not being imported into the maven project Changed scope role and still crash
error even though it is defined in my classpath /WEB-INF/lib can't find in my situation
Now below a part of my pom.xml
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.10</version>
</dependency>
I also had try to import it(Gson) to local and try to fix it out.
mvn install:install-file -Dfile=C:\gson-2.10.jar -DgroupId=com.myself.gson -DartifactId=example-gson -Dversion=2.10 -f my-app\pom.xml
After I use the command, I changed pom.xml as follow. It can compile and install. But still show me "NoClassDefFound"
<dependency>
<groupId>com.myself.gson</groupId>
<artifactId>example-gson</artifactId>
<version>2.10</version>
</dependency>
May anyone provide any solution to this? Thanks in advance.
I had tried
changed scope to provided in pom.xml
put Gson in src\main\resources\lib and change pom.xml
Local gson-2.10.jar and change pom.xml
put gson-2.10.jar in C:\Program Files\apache-maven-3.8.6\lib
The problem is this command:
java -jar my-app-1.0.jar
Most likely your current Maven pom.xml creates a JAR file which contains only the classes of your project, but not the classes of dependencies, such as Gson. This is also not specific to Gson but applies to any dependencies you are trying to use. You can either:
use java -cp and specify the path to your JAR as well as the paths to all the JARs of dependencies you are using, for example java -cp gson-2.10.jar;my-app-1.0.jar com.mycompany.app.GSONExample
configure Maven to build a "JAR with dependencies", see this question whose answers describe multiple ways of how this can be achieved

Installing JCOSap using maven on springboot

I have an issue when I use maven for installing an external jar from SAP.I'm using springboot and I've gotten 2 scenarios with no success.
1- Using maven dependency directly from folder I get an exception and the jar is not added in BOOT-INF/lib folder. But on eclipse the jar is added in Maven Dependency
<dependency>
<groupId>com.sap.conn.jco</groupId>
<artifactId>sapjco3</artifactId>
<version>3.0.19</version>
<scope>system</scope>
<systemPath>/home/eder/workspace/obsekium/TesteSelenium/sapjco3.jar</systemPath>
</dependency>
Caused by: java.lang.NoClassDefFoundError: com/sap/conn/jco/ext/DestinationDataProvider
2- Using "mvn install:install-file" Maven changes jar's name and it causes an exception
Factory method 'sapConector' threw exception; nested exception is java.lang.ExceptionInInitializerError: JCo initialization failed with java.lang.ExceptionInInitializerError: Illegal JCo archive "sapjco3-3.0.19-3.0.19.jar". It is not allowed to rename or repackage the original archive "sapjco3.jar".
How do I solve this issue?
You can try to use the following dependency and check whether it works.
<dependency>
<groupId>com.sap.jco</groupId>
<artifactId>sapjco</artifactId>
<version>3.0.14</version>
</dependency>
You can find the details from the following link.
https://mvnrepository.com/artifact/com.sap.jco/sapjco/3.0.14
If you want, you can download the jar file and you can set the dependency as system path in maven.

java.lang.NoClassDefFoundError: running Mahout example on a hadoop Cluster

I'm following the Mahout In Action tutorial for kmeans clustring, i use the same code found here:
with the same pom.xml also.
On my local machine using eclipse every thing works fine, so i build the jar file (clustering-0.0.1-SNAPSHOT.jar) and bring it to the cluster (Hortonworks 2.3) when trying to run it using: hadoop jar clustering-0.0.1-SNAPSHOT.jar com.digimarket.clustering.App (I named my project differently) I get this error:
java.lang.NoClassDefFoundError:
org/apache/mahout/common/distance/DistanceMeasure
I know it's a dependency issue, I found questions asked by users who had this issue before but couldn't understand how they solved it.
here and here
This is the content of mahout directory in my cluster:
ls /usr/hdp/2.3.4.0-3485/mahout/
bin
conf
doc
lib
mahout-examples-0.9.0.2.3.4.0-3485.jar
mahout-examples-0.9.0.2.3.4.0-3485-job.jar
mahout-integration-0.9.0.2.3.4.0-3485.jar
mahout-math-0.9.0.2.3.4.0-3485.jar
mahout-mrlegacy-0.9.0.2.3.4.0-3485.jar
mahout-mrlegacy-0.9.0.2.3.4.0-3485-job.jar
Thanks.
It looks like you have a dependency that is not available to your code on your cluster.
Based on the pom.xml from that project you should be using:
<properties>
<mahout.version>0.5</mahout.version>
<mahout.groupid>org.apache.mahout</mahout.groupid>
</properties>
...
<dependencies>
<dependency>
<groupId>${mahout.groupid}</groupId>
<artifactId>mahout-core</artifactId>
<version>${mahout.version}</version>
</dependency>
...
</dependencies>
The class org.apache.mahout.common.distance.DistanceMeasure is included in the mahout-core-0.*.jar I have mahout-core-0.7.jar and the class is present in there.
You can download that jar and include it with the -libjars flag or you can put it on the hadoop classpath.

java.lang.ClassNotFoundException: org.apache.hadoop.conf.Configuration

I keep getting this error.I've included the hadoop commons and the core libs in the classpath but still i keep getting this error.Help would be highly appreciated
Here's how to troubleshoot: Look inside the jar that you're executing to see if that class file is actually there:
jar tvf target/my-jar-with-dependencies.jar | grep hadoop/conf/Configuration.class
If it's not, you need to add it to your classpath or change the way your jar is packaged.
Are you using Maven or some similar build tool? You may have a dependency with a 'scope', which means that it will only be compiled into your jar in certain circumstances.
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-client</artifactId>
<version>${hadoop.version}</version>
<scope>provided</scope>
</dependency>
In this example, the scope tag tells Maven that you're using this dependency for building, but it indicates that the dependency will be provided during runtime, so you'll either need to remove this tag or add the hadoop jar using -cp=/path/to/jar.jar during runtime. Another example of a scope like this is 'test', which indicates that the jar is only needed in the path during unit tests.
make sure the classpath in your jar. You can check it like mark said;
jar tvf target/my-jar-with-dependencies.jar | grep hadoop/conf/Configuration.class
add dependency to hadoop-core.

java.lang.NoSuchMethodError: javax.media.opengl.GLDrawableFactory.initSingleton()V

I am trying to use the JZY3D libraries in my Java project.
Starting with the basic, I set up the following main():
public static void main(final String[] args) {
new GLCapabilities(GLProfile.getDefault());
}
The jogl-all.jar, gluegen-rt.jar and gluegen.jar files are in the build path. I get the following exception:
Exception in thread "main" java.lang.NoSuchMethodError: javax.media.opengl.GLDrawableFactory.initSingleton()V
at javax.media.opengl.GLProfile.initProfilesForDefaultDevices(GLProfile.java:1444)
at javax.media.opengl.GLProfile.access$100(GLProfile.java:76)
at javax.media.opengl.GLProfile$1.run(GLProfile.java:174)
at java.security.AccessController.doPrivileged(Native Method)
at javax.media.opengl.GLProfile.initSingleton(GLProfile.java:140)
at javax.media.opengl.GLProfile.initSingleton(GLProfile.java:199)
at javax.media.opengl.GLProfile.getProfileMap(GLProfile.java:1914)
at javax.media.opengl.GLProfile.get(GLProfile.java:815)
at javax.media.opengl.GLProfile.getDefault(GLProfile.java:602)
at javax.media.opengl.GLProfile.getDefault(GLProfile.java:613)
at eu.crisis_economics.abm.model.SpecsCompetitionStrategyCFO.main(SpecsCompetitionStrategyCFO.java:312)
It seems like there is a problem with the 3d libraries, but I cannot figure out what.
The jogl-all.jar, gluegen-rt.jar and gluegen.jar files are in the build path. I get the following exception:
Remove gluegen.jar from the build path.
Make sure these two jars are added to the classpath at runtime as well!
You only need jogl-all.jar and gluegen-rt.jar (rt == runtime) at compile time and runtime.
Also you need to have a copy of the matching native jars gluegen-rt-natives-os.and.arch.jar and jogl-all-natives-os.and.arch.jar for the platform you use next to the gluegen-rt.jar and jogl-all.jar
http://jogamp.org/jogl/doc/deployment/JOGL-DEPLOYMENT.html#NativeJARFiles
Have you tried the Maven dependency instead of add those jars by hand?
I made a clean maven project, add a new user library with the following files:
org.jzy3d-0.9.jar
dependencies/misc/opencsv-2.1.jar
dependencies/misc/org.convexhull.jar
dependencies/misc/swt.jar
dependencies/misc/swt-debug.jar
After that, I add the following maven dependencies:
<dependency>
<groupId>org.jogamp.gluegen</groupId>
<artifactId>gluegen-rt-main</artifactId>
<version>2.0.2</version>
</dependency>
<dependency>
<groupId>org.jogamp.jogl</groupId>
<artifactId>jogl-all-main</artifactId>
<version>2.0.2</version>
</dependency>
Build & Run with no exceptions.
A much cleaner solution is:
Clone Jzy3D repository (https://github.com/jzy3d/jzy3d-api)
install jzy3d-master
add the jzy3d-api dependency for your project

Categories

Resources