Bukkit API Soft Depend Importing - java

I have a softdepend in my plugin.yml:
softdepend: [Plugin]
I check if the plugin is not in the server using this:
if(getServer().getPluginManager().getPlugin("Plugin") != null) {
// do stuff
}
Even though I am checking if the plugin exists in the plugins folder before running my code, I have imports from this plugin that throw errors when the plugin is not on the server. I am getting a InvalidPluginException because of the imports I have from the softdepended plugin. I need these imports to run the code I use if the plugin is available in the plugins folder. NOTE: I do not want to disable the plugin if the softdepend plugin is not found.
How can I keep the imports from the softdepended plugin without it throwing this error.
I have tried looking for a similar question like this on the Bukkit Forums and Stack Overflow, I have had no luck.
The error looks like this:
org.bukkit.plugin.InvalidPluginException: java.lang.NoClassDefFoundError: be/maximvdw/featherboard/api/PlaceholderAPI$PlaceholderRequestEventHandler
at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:135) ~[craftbukkit.jar:git-Spigot-26dfd01-5cb9b70]
at org.bukkit.plugin.SimplePluginManager.loadPlugin(SimplePluginManager.java:329) ~[craftbukkit.jar:git-Spigot-26dfd01-5cb9b70]
at org.bukkit.plugin.SimplePluginManager.loadPlugins(SimplePluginManager.java:251) [craftbukkit.jar:git-Spigot-26dfd01-5cb9b70]
at org.bukkit.craftbukkit.v1_8_R2.CraftServer.loadPlugins(CraftServer.java:291) [craftbukkit.jar:git-Spigot-26dfd01-5cb9b70]
at net.minecraft.server.v1_8_R2.DedicatedServer.init(DedicatedServer.java:199) [craftbukkit.jar:git-Spigot-26dfd01-5cb9b70]
at net.minecraft.server.v1_8_R2.MinecraftServer.run(MinecraftServer.java:522) [craftbukkit.jar:git-Spigot-26dfd01-5cb9b70]
at java.lang.Thread.run(Unknown Source) [?:1.8.0_25]
Caused by: java.lang.NoClassDefFoundError: be/maximvdw/featherboard/api/PlaceholderAPI$PlaceholderRequestEventHandler
at (java:21) ~[?:?]
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[?:1.8.0_25]
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source) ~[?:1.8.0_25]
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source) ~[?:1.8.0_25]
at java.lang.reflect.Constructor.newInstance(Unknown Source) ~[?:1.8.0_25]
at java.lang.Class.newInstance(Unknown Source) ~[?:1.8.0_25]
at org.bukkit.plugin.java.PluginClassLoader.(PluginClassLoader.java:76) ~[craftbukkit.jar:git-Spigot-26dfd01-5cb9b70]
at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:131) ~[craftbukkit.jar:git-Spigot-26dfd01-5cb9b70]
... 6 more
Caused by: java.lang.ClassNotFoundException: be.maximvdw.featherboard.api.PlaceholderAPI$PlaceholderRequestEventHandler
at java.net.URLClassLoader$1.run(Unknown Source) ~[?:1.8.0_25]
at java.net.URLClassLoader$1.run(Unknown Source) ~[?:1.8.0_25]
at java.security.AccessController.doPrivileged(Native Method) ~[?:1.8.0_25]
at java.net.URLClassLoader.findClass(Unknown Source) ~[?:1.8.0_25]
at org.bukkit.plugin.java.PluginClassLoader.findClass(PluginClassLoader.java:101) ~[craftbukkit.jar:git-Spigot-26dfd01-5cb9b70]
at org.bukkit.plugin.java.PluginClassLoader.findClass(PluginClassLoader.java:86) ~[craftbukkit.jar:git-Spigot-26dfd01-5cb9b70]
at java.lang.ClassLoader.loadClass(Unknown Source) ~[?:1.8.0_25]
at java.lang.ClassLoader.loadClass(Unknown Source) ~[?:1.8.0_25]
at (java:21) ~[?:?]
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[?:1.8.0_25]
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source) ~[?:1.8.0_25]
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source) ~[?:1.8.0_25]
at java.lang.reflect.Constructor.newInstance(Unknown Source) ~[?:1.8.0_25]
at java.lang.Class.newInstance(Unknown Source) ~[?:1.8.0_25]
at org.bukkit.plugin.java.PluginClassLoader.(PluginClassLoader.java:76) ~[craftbukkit.jar:git-Spigot-26dfd01-5cb9b70]
at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:131) ~[craftbukkit.jar:git-Spigot-26dfd01-5cb9b70]
... 6 more
[15:44:32]

Instead of enabling the plugin when the dependency is there, disable the plugin if it isn't there.
if (getServer().getPluginManager().getPlugin("Plugin") != null) {
// error message, whatever else you need here
getServer().getPluginManager().disablePlugin(this);
}
EDIT: I just realized that this might not be what you're trying to do. If you're trying to use code from a certain plugin that might not be on the server, for example in a listener, make 2 listener classes: one containing code that uses that plugin, and another that contains no code from that plugin. Then when you register the listeners, do something like this:
if (getServer().getPluginManager().getPlugin("Plugin") != null) {
getServer().getPluginManager().registerEvents(new ListenerWithDependencyCode(), this);
} else {
getServer().getPluginManager().registerEvents(new ListenerWithoutDependencyCode(), this);
}

Related

JMeter: NoClassDefFoundError error when used jackson jar

I'm creating a custom Java sampler in JMeter. It's working just fine. However, when I wanted it to return a result in JSON, JMeter didn't found the .jar for the jackson-databind library, which is needed for the creation of the JSON.
I put it to the /lib/ext folder in the JMeter main directory. I also copied to /lib, to no avail. (I know that /lib/ext shouldn't be used for dependency jars, but JMeter doesn't find my utility jars in /lib in my experience.)
I tried adding the path to the variables search_paths, user.classpath and plugin_dependency_paths in jmeter.properties. I tried with absolute path, relative path, with slash, with backslash, but neither helped.
I tried setting the JMETER_HOME variable to the address of my installation. It worked, yet it didn't help.
I tried running in two environments. The first is within Eclipse (I copied JMeter to a workspace folder, then imported the project), with JMeter 4.0. I got this error in the log:
java.lang.NoClassDefFoundError: com/fasterxml/jackson/databind/ObjectMapper
at (creating ObjectMapper here)
at (creating ResponseJSON here)
at org.apache.jmeter.protocol.java.sampler.JavaSampler.sample(JavaSampler.java:197) ~[ApacheJMeter_java.jar:4.0 r1823414]
at org.apache.jmeter.threads.JMeterThread.executeSamplePackage(JMeterThread.java:490) ~[ApacheJMeter_core.jar:4.0 r1823414]
at org.apache.jmeter.threads.JMeterThread.processSampler(JMeterThread.java:416) ~[ApacheJMeter_core.jar:4.0 r1823414]
at org.apache.jmeter.threads.JMeterThread.run(JMeterThread.java:250) ~[ApacheJMeter_core.jar:4.0 r1823414]
at java.lang.Thread.run(Thread.java:745) [?:1.8.0_101]
I also ran JMeter 3.3 from the .bat file, adding the jars to the same place. I got this error on the console:
Unknown error checking for existence of class: com.fasterxml.jackson.databind.ObjectMapper
java.lang.NoClassDefFoundError: com/fasterxml/jackson/core/Versioned
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at org.apache.logging.log4j.util.LoaderUtil.loadClass(LoaderUtil.java:141)
at org.apache.logging.log4j.util.LoaderUtil.isClassAvailable(LoaderUtil.java:115)
at org.apache.logging.log4j.core.util.Loader.isClassAvailable(Loader.java:310)
at org.apache.logging.log4j.core.config.yaml.YamlConfigurationFactory.<init>(YamlConfigurationFactory.java:47)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.apache.logging.log4j.core.util.ReflectionUtil.instantiate(ReflectionUtil.java:188)
at org.apache.logging.log4j.core.config.ConfigurationFactory.addFactory(ConfigurationFactory.java:190)
at org.apache.logging.log4j.core.config.ConfigurationFactory.getInstance(ConfigurationFactory.java:164)
at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:613)
at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:634)
at org.apache.logging.log4j.core.LoggerContext.start(LoggerContext.java:229)
at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:152)
at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:45)
at org.apache.logging.log4j.LogManager.getContext(LogManager.java:194)
at org.apache.logging.log4j.spi.AbstractLoggerAdapter.getContext(AbstractLoggerAdapter.java:122)
at org.apache.logging.slf4j.Log4jLoggerFactory.getContext(Log4jLoggerFactory.java:43)
at org.apache.logging.log4j.spi.AbstractLoggerAdapter.getLogger(AbstractLoggerAdapter.java:46)
at org.apache.logging.slf4j.Log4jLoggerFactory.getLogger(Log4jLoggerFactory.java:29)
at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:358)
at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:383)
at org.apache.jmeter.JMeter.<clinit>(JMeter.java:109)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at java.lang.Class.newInstance(Unknown Source)
at org.apache.jmeter.NewDriver.main(NewDriver.java:246)
Caused by: java.lang.ClassNotFoundException: com.fasterxml.jackson.core.Versioned
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 43 more
I didn't try to debug the classloader, but probably that'll be the next step when I finished posting it here.
I have this version of the file, same as in my POM:
https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-databind/2.9.4
Part of jackson-databind dependencies is specifically jackson-core jar you are probably missing and include missing class in your error: com.fasterxml.jackson.core.Versioned
See Jackson Installation:
The three JAR files (projects) in the Jackson JSON API are:
Jackson Core
Jackson Annotations
Jackson Databind

Java WebStart java.lang.NullPointerException at java.awt.Window.getWindows

i'm currently attaching to a java webstart application (anything from here: https://docs.oracle.com/javase/tutorial/uiswing/examples/misc/index.html#security) using the Java Attach API.
That works without problems, but now i want to iterate over all available Frames using
for (Frame f : java.awt.Frame.getFrames())
But this results in
java.lang.NullPointerException
at java.awt.Window.getWindows(Unknown Source)
at java.awt.Window.getWindows(Unknown Source)
at java.awt.Frame.getFrames(Unknown Source)
at com.asc.screen.scan.javascan.javascanagent.util.GuiWalkerTexasRanger.walkGui(GuiWalkerTexasRanger.java:151)
at com.asc.screen.scan.javascan.javascanagent.ComponentRegistry.initialScan(ComponentRegistry.java:124)
at com.asc.screen.scan.javascan.javascanagent.ComponentRegistry.init(ComponentRegistry.java:76)
at com.asc.screen.scan.javascan.javascanagent.JavaScanAgent.loadFilter(JavaScanAgent.java:291)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at sun.rmi.server.UnicastServerRef.dispatch(Unknown Source)
at sun.rmi.transport.Transport$1.run(Unknown Source)
at sun.rmi.transport.Transport$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Unknown Source)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(Unknown Source)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(Unknown Source)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$0(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
...
Maybe i'm missing something here, but shouldn't it be possible to access all frames within the applet? This method works fine for non applet applications.
The problem is that the error is thrown inside the java code, so there is no way for me to avoid or handle this nullpointer, and i'm not getting any frames back.
Thanks in advance.

Java exception error after exporting javafx jar

I have a javafx application that I've been developing in eclipse and it is working fine on the IDE. However, when I export it into a jar, I get the following Exception:
java.lang.NoClassDefFoundError: javafx/application/Application
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)
Caused by: java.lang.ClassNotFoundException: javafx.application.Application
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 13 more
Exception in thread "main"
I've even created a MainTerminal class that doesn't use javaFX, instead just interacts within the terminal and after I exported the jar using MainTerminal as the main class and it worked fine. It seems I'm not being able to export some dependency or something but I checked the buildpath and it seemed alright to me.
I feel quite dumb about this but I just found out what my problem was. I was exporting my project as a Jar instead of a runnable Jar, that's why it was throwing an exception when I tried executing it.

Java applet calling WCF Service fails with noclassdef exception at runtime

I have a java applet which uses a proxy service to a WCF Service to display data. The applet compiles and runs perfectly in Eclipse but when I build and export a Jar file then run it in a html page it fails with
java.lang.NoClassDefFoundError: javax/xml/rpc/ServiceException.
I have included jaxrpc.jar in my build path and my jar file contains all necessary classes.
The stack trace seems to be complaining about the line where I instantiate the proxy service from within the applet class. Does anyone know if there is an issue calling WCF service from a java applet?
Stack Trace:
java.lang.RuntimeException: java.lang.NoClassDefFoundError: javax/xml/rpc/ServiceException
at com.sun.deploy.uitoolkit.impl.awt.AWTAppletAdapter.instantiateApplet(Unknown Source)
at sun.plugin2.applet.Plugin2Manager.initAppletAdapter(Unknown Source)
at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.NoClassDefFoundError: javax/xml/rpc/ServiceException
at ListProducts.ListProducts.<init>(ListProducts.java:25)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at java.lang.Class.newInstance0(Unknown Source)
at java.lang.Class.newInstance(Unknown Source)
at com.sun.deploy.uitoolkit.impl.awt.AWTAppletAdapter$1.run(Unknown Source)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$200(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
Caused by: java.lang.ClassNotFoundException: javax.xml.rpc.ServiceException
at sun.plugin2.applet.Applet2ClassLoader.findClass(Unknown Source)
at sun.plugin2.applet.Plugin2ClassLoader.loadClass0(Unknown Source)
at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Unknown Source)
at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 27 more
This has been troubling me all day.
I think your issue is loading rpc jar, not call to wcf.
This post can be helpfull:
http://www.coderanch.com/t/259357/Applets/java/Applet-Axis-Client-Errors
It recomemds to sign your jar, verify you can access all your jars via browser, ensure you have all dependent.jars.
If all this will not help - i'd try to solve it as "
NoClassDefFoundError from spplet" issue.
Ok. I got this working by doing several things:
First I had to sign several of the jar files I was using:
jaxrpc.jar
axis.jar
commons-discovery-0.2.jar
but not:
javax.wsdl_1.6.2.v201012040545.jar
org.apache.commons.logging_1.0.4.v201101211617.jar
Secondly - all these files had to exist in the same directory as the html page, as I didn't specify a directory in codebase property for the applet tag.
Thirdly, within my main applet (ListProducts.class) I had to use AccessController.doPrivileged() around the code that first calls the proxy service:
EDIT: This step may not be necessary, as it now seems to work when I remove the doPrivileged block.
AccessController.doPrivileged(new PrivilegedAction() {
public Object run() {
try {
//instantiate proxy service and make rpc's
//do other stuff with results...
} catch (RemoteException e) {
// catch error
}
return null;
}
});
This combination of things got the java applet doing what it should. It was a painful slow process to discover which jar files were missing and then signing the appropriate ones.

Java Web Start ClassNotFoundException

I'm trying to launch a runnable JAR file via web start, but am encountering an error with java not being able to find an external JAR (I think). When running the JNLP file, JWS starts, but then states that the application cannot be opened due to this error:
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.sun.javaws.Launcher.executeApplication(Unknown Source)
at com.sun.javaws.Launcher.executeMainClass(Unknown Source)
at com.sun.javaws.Launcher.doLaunchApp(Unknown Source)
at com.sun.javaws.Launcher.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.NoClassDefFoundError: org/apache/commons/net/ftp/FTPClient
at DevChat.canConnect(DevChat.java:326)
at DevChat.<init>(DevChat.java:89)
at DevChat.main(DevChat.java:348)
... 9 more
Caused by: java.lang.ClassNotFoundException: org.apache.commons.net.ftp.FTPClient
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at com.sun.jnlp.JNLPClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 12 more
The external JAR file mentioned, apache commons, is embedded in the runnable JAR and the JAR runs fine on it's own, just not in JWS. Suggestions?

Categories