Reputation: 4117
I am developing a plugin for Minecraft using Bukkit's API. I have to use Apache Commons NET library.
I am getting a ClassNotFoundException once the JAR is run.
I manually made my MANIFEST.MF file (set it to use my custom file when exporting the JAR) and put this inside of it:
Manifest-Version: 1.0
Class-Path: libs/commons-net-3.0.1.jar
Worked like a charm.
I created a folder in the Project Explorer within my plugin and named it "libs". I copied the .jar for the Apache Commons library into said folder.
I then right clicked my project, went to Java Build Path, Add JAR(s), MyPlugin > libs > the.jar
Once added, everything from within the coding works fine. All imports are read correctly and no issue arises.
Upon exporting the project, it is noticeably larger as the library is attached to the .jar
I get this error:
Caused by: java.lang.NoClassDefFoundError: org/apache/commons/net/ftp/FTPClient
at me.geekplaya.AdventureLobbies.FileUpload.upload(FileUpload.java:14)
at me.geekplaya.AdventureLobbies.AdventureLobbies.onCommand(AdventureLobbies.java:766)
at org.bukkit.command.PluginCommand.execute(PluginCommand.java:40)
... 12 more
Caused by: java.lang.ClassNotFoundException: org.apache.commons.net.ftp.FTPClient
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 org.bukkit.plugin.java.PluginClassLoader.findClass(PluginClassLoader.java:41)
at org.bukkit.plugin.java.PluginClassLoader.findClass(PluginClassLoader.java:29)
at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
... 15 more
.classpath
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
<classpathentry kind="lib" path="/Users/gray/Applications/Java Workspace/Server/craftbukkit.jar"/>
<classpathentry kind="lib" path="libs/commons-net-3.0.1.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>
Upvotes: 2
Views: 5622
Reputation: 30032
If you notice the line:
at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
This is a line that is loading a class using reflection. Try to go to the source in your stack trace and find what class it is trying to load.
Upvotes: 1
Reputation: 11140
You want to scrutinize that stacktrace. java.lang.NoClassDefFoundError is not java.lang.ClassNotFoundException. I think it is finding all the classes that are in the commons-net-3.0.1.jar but commons-net-3.0.1.jar has some dependency that is not being met. Crack the commons-net-3.0.1.jar open and see if you can locate a .class to satisfy the org.apache.commons.net.ftp.FTPClient. If its not in there, you'll have to find out where it comes from (probably some other JAR) and get it on the classpath as well.
Upvotes: 3
Reputation: 5
im not a pro, but i would think you have to add it to the classpath.if you have already done that then the path to the c
Upvotes: -2