Java NoClass Found Error - java

I'm trying to use Bliki to access and parse wiki pages.
I just downloaded the zip file and put the bliki-core-3.0.19.jar into my eclipse build path.
However, when I tried to connect using sample code. there was an error.
The sample code is here:
public static void test(){
String pageName = "File:Mona Lisa.jpg";
User user = new User("", "", "http://en.wikipedia.org/w/api.php");
Connector con = new Connector();
user = con.login(user);
List<Page> pages = user.queryImageinfo(new String[]{pageName});
if(pages != null)
System.out.println(pages.size());
}
And I got errors as:
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/httpclient/HttpMethod
at info.bliki.api.User.<init>(User.java:98)
at info.bliki.api.User.<init>(User.java:71)
at main.wiki.WikiCall.test(WikiCall.java:23)
at main.wiki.WikiCall.main(WikiCall.java:32)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.httpclient.HttpMethod
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
... 4 more
It seems like I'm missing the http jar for the connection, but there's no one the zip file and i thought the bliki-core.jar should contain it.
Any suggestions?

I'm not familiar with Bliki but from your stacktrace it looks like you are missing the Http Client from Apache Commons.
You should add the jar to your project and that should solve the problem.
Get the jar from here: http://hc.apache.org/

This issue is that even once you have added HttpClient you will likely get other errors as the Bliki library depends on a number of 3rd party libraries.
If you are not familiar with the Maven build tool it may be worth having a look as one feature is that it will transitively resolve dependencies.
As a quick start:
In Eclipse do:
File > New > Other > Maven Project
Select the 'Create Simple Project' checkbox.
Enter my.bliki.project as the group id and bliki-test as the Artifact id.
Replace the contents of the generated pom.xml with the below.
Right click on the project and select 'Maven > Update project.
You now have a project with Bliki and all 3rd p;arty dependencies on the buildpath (expand the Maven Dependencies folder to see what they are).
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>my.bliki.project</groupId>
<artifactId>bliki-test</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>info.bliki.wiki</groupId>
<artifactId>bliki-core</artifactId>
<version>3.0.19</version>
</dependency>
</dependencies>
</project>

Related

maven tries to retrieve wrong snapshot version from repository because of bad maven-metadata.xml

I'm using maven to fetch dependencies from our company's internal repositories. We use Artifactory. Everything works ok, but sometimes I have a recurring problem. After mvn -U clean compile I get an error.
Could not resolve dependencies for project company_groupId:company_dependency-articfactId:jar:0.0.1-SNAPSHOT: Could not find artifact company_groupId:company_dependency-articfactId:jar:2.0.17-20210429.123648-56 in snapshots2 (https://company.repository/snapshots)
When I look which jars repository actually contains, it appears it has 3 files in company_dependency-articfactId/0.0.1-SNAPSHOT
maven-metadata.xml
company_dependency-articfactId-2.0.17-20210430.091957-56.jar
company_dependency-articfactId-2.0.17-20210430.091957-56.pom
So, maven searches for date 20210429 and what repository actually contains is date 20210430 .
I thought maybe something removes dependencies, but the I looked inside maven-metadata.xml .
Comments added for better understanding.
<?xml version="1.0" encoding="UTF-8"?>
<metadata modelVersion="1.1.0">
<groupId>company_dependencyId</groupId>
<artifactId>company_dependency-articfactId</artifactId>
<version>2.0.17-SNAPSHOT</version>
<versioning>
<snapshot>
<timestamp>20210430.091957</timestamp> <!-- ok version -->
<buildNumber>56</buildNumber>
</snapshot>
<lastUpdated>20210430092512</lastUpdated>
<snapshotVersions>
<snapshotVersion>
<extension>jar</extension>
<value>2.0.17-20210429.123648-56</value> <!-- WRONG version -->
<updated>20210429123648</updated>
</snapshotVersion>
<snapshotVersion>
<extension>pom</extension>
<value>2.0.17-20210430.091957-56</value> <!-- ok version -->
<updated>20210430091957</updated>
</snapshotVersion>
</snapshotVersions>
</versioning>
</metadata>
As you can see, jar version of snapshot actually points to the wrong jar, which doesn't exist.
I looked at other dependencies and they're ok. So it's not something, which happens to all artifacts at a specific date.
I've no idea what could have caused this. Maybe somebody has already encountered such an issue?
Also I have couple of specific questions.
Could this mismatch between pom and jar versions of snapshots occur naturally? Like a script, which uploads next version for pom, but not for jar?
Could it be some kind of an error, when we have already uploaded pom, but couldn't upload jar for some reason? I mean it probably could happen, but is it reasonable to think that actually happens regularly?
Maybe it's a normal thing to upload pom and jar separately?
I haven't experienced anything like that before, so any help is much appreciated.
There's a couple of bugs in Artifactory, which could have caused this. For example https://www.jfrog.com/jira/browse/RTFACT-21321 https://www.jfrog.com/jira/browse/RTFACT-6514 or https://www.jfrog.com/jira/browse/RTFACT-21321 .
The problem could be solved by recreating metadata as J Fabian Meier suggested.
Got same problem. After some research it seams to be a known & already fixed bug https://issues.apache.org/jira/browse/MNG-6754.
Upgrading your maven should fix it.

Jar file referencing Maven jar file doesn't work consistently

I have a Swing application that uses classes from Maven artifact math.geom2d:javaGeom:0.11.1. To create a jar file in A GitHub Release I use a modified "fatJar" build.gradle task, so the geom2d classes are included in the jar file. For the jar file for my application on Maven, I don't include the geom2d classes, so these classes don't show up in that jar file, but they are referenced as dependencies.
What is odd is that on my machine this (smaller) jar file works fine consistently, so I thought everything was OK, even if strange! I decided to try it on my wife's machine and it crashes with a NoClassDefFoundError. I thought maybe it was because she didn't have Maven installed... tried installing it, but no difference! Help would be appreciated!
Here is the pom.xml on Maven for my app:
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.jpaulmorrison</groupId>
<artifactId>drawfbp</artifactId>
<version>2.18.4</version>
<name>DrawFBP</name>
<description>Diagramming Tool for Flow-Based Programming</description>
<url>https://github.com/jpaulm/drawfbp</url>
<licenses>
<license>
<name>GNU Lesser General Public License, Version 3.0</name>
<url>https://www.gnu.org/licenses/lgpl-3.0.txt</url>
</license>
</licenses>
<developers>
<developer>
<id>jpaulmorr</id>
<name>
John Paul Rodker Morrison (Software architect/developer)
</name>
<email>jpaulmorr#gmail.com</email>
</developer>
<developer>
<id>bobcorrick</id>
<name>Bob Corrick (Software architect/developer)</name>
<email>bobcorrick#outlook.com</email>
</developer>
</developers>
<scm>
<connection>scm:git:https://github.com/jpaulm.git</connection>
<developerConnection>scm:git:https://github.com/jpaulm.git</developerConnection>
<url>https://github.com/jpaulm.git</url>
</scm>
<dependencies>
<dependency>
<groupId>math.geom2d</groupId>
<artifactId>javaGeom</artifactId>
<version>0.11.1</version>
<scope>compile</scope>
</dependency>
</dependencies>
</project>
Thanks #samvel1024 ! I now have a better handle on what is going on:
the jar file without the geom2d classes could run because I had geom2d in my classpath - it doesn't any more!
I create a fatJar using a task in build.gradle, but uploadArchives creates a new jar file, which isn't "fat"!
so, I would either like to add the fatJar task to my uploadArchives function,
OR
suppress the 'jar' task in uploadArchives, so it doesn't mess up the "fat" jar that I already have! I have tried "jar.enabled = boolean variable", but I can't set it to "false"...
Either of these two options should be easy in a sensible language, but I can't get either to work! Help would be appreciated!
If you are going to use maven for building the jar, then you need to include all the dependencies as you have in your gradle build def.
If you want the jar to be runnable with java -jar my.jar then, additionally you need to use some build plugin to do that for you.
You can find more details here
Turned out to be so simple! Turned out to be the second option above:
"... suppress the 'jar' task in uploadArchives, so it doesn't mess up the "fat" jar that I already have! ..."
Add -x jar to the command line for uploadArchives!
Thanks anyway, #samvel1024 !

Error calling to the cloud jclouds

So I am trying to download files on a rackspace server to my local server. It is laid out here. For some odd reason, I am trying to make the initial call to the cloud and it is giving me some serious feedback. No idea where to go from here. I've tried all sorts of different Maven dependencies to fix the problem, but none have come close. Am I overlooking something? TIA!
My code:
public static void main (String[] args){
CloudFilesApi cloudFilesApi = ContextBuilder.newBuilder(PROVIDER)
.credentials(USERNAME, KEY)
.buildApi(CloudFilesApi.class);
}
And here are my errors (without Guice):
Exception in thread "main" java.lang.NoClassDefFoundError: com/google/inject/Stage
at org.jclouds.ContextBuilder.<clinit>(ContextBuilder.java:151)
at com.unidev.download.Main.main(Main.java:10)
Caused by: java.lang.ClassNotFoundException: com.google.inject.Stage
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
... 2 more
Here are my dependencies (now):
<dependencies>
<!-- Rackspace US dependencies -->
<dependency>
<groupId>org.apache.jclouds.provider</groupId>
<artifactId>rackspace-cloudfiles-us</artifactId>
<version>${jclouds.version}</version>
</dependency>
Code snippet for dependency tree(updated): https://codeshare.io/bfbKg
I guess it is a Maven issue... When I was building the Maven project and using the dependencies via the pom file, it was somehow building incorrectly. Instead, I started a Java file and built a lib folder, pulled all the jars I needed and then just tied them in via the build path... and it is working well now...

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.

NoClassDefFoundError with Maven and a Java Wiki Library

I'm using a library to make Wikipedia API calls, called the Java Wiki Bot Framework. I'm also using Maven for builds, and I've added the framework to the pom.xml just as the github page says. However, when I try to instantiate any of the classes in the library, it gives me this error:
Exception in thread "main" java.lang.NoClassDefFoundError: net/sourceforge/jwbf/core/actions/HttpActionClient
at com.FactFinder.WikiParser.makeBot(WikiParser.java:21)
at com.FactFinder.WikiParser.<init>(WikiParser.java:16)
at com.FactFinder.App.main(App.java:15)
Caused by: java.lang.ClassNotFoundException: net.sourceforge.jwbf.core.actions.HttpActionClient
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
... 3 more
My pom.xml
Apparently this is an error that crops up when your jar can't find a class, but I've checked the classpath, and it looks fine. The jar is included in the proper folder, and I've verified that it includes the classes I tried to use. I considered contacting the library author, but I figured its probably more my problem than his.
Why are you using the Snapshot version 4.0.0-SNAPSHOT? I would strongly suggest to use a final version to avoid issues, of which 3.1.0 seems to be the latest and most popular one:
<dependency>
<groupId>net.sourceforge</groupId>
<artifactId>jwbf</artifactId>
<version>3.1.0</version>
</dependency>
[UPDATE]
Follow naming conventions; package name: com.factfinder (all lowercase). Fix in both your code, pom, and directory names.
Add the version for the maven-jar-plugin
Note that I tried using your pom - it seemed to work for me ...
Are you sure you don't get any other warnings or errors during your maven build? can you do a clean package?
Check line 53 of your POM:
<classpathPrefix>lib\</classpathPrefix>
Should be:
<classpathPrefix>lib/</classpathPrefix>

Categories

Resources