I have been using the getResources() function of the ClassLoader class to load classes in a certain Plugin I am coding in Minecraft.
The package the main class is found in is: "rr.aesir". I tried every possibility with this package name with slashes before, after, dots, inbetween and everything returned an empty Enumeration. (Spigot version: 1.12.1). tried to call it from other classes aswell.
ClassLoader loader = this.getClass().getClassLoader();
Enumeration<URL> urls = this.loader.getResources("/rr/aesir");
String path = urls.nextElement().getPath();
This code is placed in my main class that extends JavaPlugin. I am getting an error saying NoSuchElementException. I have not called nextElement() anywhere in the class so it's not that I skipped any existing elements.
I am out of options, any help is accepted.
Complete Stack Trace:
[03:07:43 INFO]: [Aesir] Enabling Aesir v1.0
[03:07:43 INFO]: [Aesir] Aesir has been enabled.
[03:07:43 ERROR]: Error occurred while enabling Aesir v1.0 (Is it up to date?)
java.util.NoSuchElementException: null
at sun.misc.CompoundEnumeration.nextElement(Unknown Source) ~[?:1.8.0_151]
at rr.aesir.Aesir.load(Aesir.java:72) ~[?:?]
at rr.aesir.Aesir.onEnable(Aesir.java:47) ~[?:?]
at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:264) ~[spigot-1.12.1.jar:git-Spigot-da42974-8f47214]
at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:337) [spigot-1.12.1.jar:git-Spigot-da42974-8f47214]
at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:402) [spigot-1.12.1.jar:git-Spigot-da42974-8f47214]
at org.bukkit.craftbukkit.v1_12_R1.CraftServer.enablePlugin(CraftServer.java:384) [spigot-1.12.1.jar:git-Spigot-da42974-8f47214]
at org.bukkit.craftbukkit.v1_12_R1.CraftServer.enablePlugins(CraftServer.java:333) [spigot-1.12.1.jar:git-Spigot-da42974-8f47214]
at org.bukkit.craftbukkit.v1_12_R1.CraftServer.reload(CraftServer.java:755) [spigot-1.12.1.jar:git-Spigot-da42974-8f47214]
at org.bukkit.Bukkit.reload(Bukkit.java:525) [spigot-1.12.1.jar:git-Spigot-da42974-8f47214]
at org.bukkit.command.defaults.ReloadCommand.execute(ReloadCommand.java:25) [spigot-1.12.1.jar:git-Spigot-da42974-8f47214]
at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:141) [spigot-1.12.1.jar:git-Spigot-da42974-8f47214]
at org.bukkit.craftbukkit.v1_12_R1.CraftServer.dispatchCommand(CraftServer.java:651) [spigot-1.12.1.jar:git-Spigot-da42974-8f47214]
at org.bukkit.craftbukkit.v1_12_R1.CraftServer.dispatchServerCommand(CraftServer.java:637) [spigot-1.12.1.jar:git-Spigot-da42974-8f47214]
at net.minecraft.server.v1_12_R1.DedicatedServer.aP(DedicatedServer.java:444) [spigot-1.12.1.jar:git-Spigot-da42974-8f47214]
at net.minecraft.server.v1_12_R1.DedicatedServer.D(DedicatedServer.java:407) [spigot-1.12.1.jar:git-Spigot-da42974-8f47214]
at net.minecraft.server.v1_12_R1.MinecraftServer.C(MinecraftServer.java:679) [spigot-1.12.1.jar:git-Spigot-da42974-8f47214]
at net.minecraft.server.v1_12_R1.MinecraftServer.run(MinecraftServer.java:577) [spigot-1.12.1.jar:git-Spigot-da42974-8f47214]
at java.lang.Thread.run(Unknown Source) [?:1.8.0_151]
Picture of class structure:
Class structure inside project.
Remove the leading /.
To make code compile, also remove this. before loader.
ClassLoader loader = this.getClass().getClassLoader();
Enumeration<URL> urls = loader.getResources("rr/aesir");
String path = urls.nextElement().getPath();
Note that getPath() may not return the string you think it does.
url.toString() returns something like file:/C:/foo/bar/rr/aesir
url.getPath() returns /C:/foo/bar/rr/aesir
If you want an actual path, call Paths.get(url.toURI()).toString()
It returns C:\foo\bar\rr\aesir
If you are pre-Java 7, call new File(url.toURI()).toString()
That of course won't work if your code is running from a jar file.
I think that you're a bit misunderstanding what getResources exactly does, assuming that you want to list all the resources within the rr/aesir directory.
According to the javadoc:
Finds all the resources with the given name. A resource is some data (images, audio, text, etc) that can be accessed by class code in a way that is independent of the location of the code.
There can be multiple resources with a specific name, that's why it returns a enumeration. And does not list resources in the directory.
The solution in the following question is what you can use to list the resources:
How do I list the files inside a JAR file?
Related
So i tried to copy an image downloaded from the internet to my android studio mainactivity xml file via copying the image and pasting it onto the drawable resource folder, But for some reason, I got an error of "Failed to instantiate one or more classes" This is the first time I'm getting this error as my previous images copied the exact same way had no errors except for other images such as this one. Does it have something to do with PNG or JPG format?I tried to resync the project with Gradle files but its still the same. What should I do to solve this exception? Thank You.
1) the process of copying and pasting image to drawable
2) The error itself after pasting the image
java.lang.NullPointerException
at android.content.res.Resources_Delegate.getValue(Resources_Delegate.java:788)
at android.content.res.Resources.getValue(Resources.java:1286)
at android.support.v7.widget.AppCompatDrawableManager.createDrawableIfNeeded(AppCompatDrawableManager.java:236)
at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:199)
at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:190)
at android.support.v7.content.res.AppCompatResources.getDrawable(AppCompatResources.java:100)
at android.support.v7.widget.AppCompatImageHelper.loadFromAttributes(AppCompatImageHelper.java:54)
at android.support.v7.widget.AppCompatImageView.<init>(AppCompatImageView.java:66)
at android.support.v7.widget.AppCompatImageView.<init>(AppCompatImageView.java:56)
at sun.reflect.GeneratedConstructorAccessor1111.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at org.jetbrains.android.uipreview.ViewLoader.createNewInstance(ViewLoader.java:475)
at org.jetbrains.android.uipreview.ViewLoader.loadClass(ViewLoader.java:250)
at org.jetbrains.android.uipreview.ViewLoader.loadClass(ViewLoader.java:213)
at com.android.tools.idea.rendering.LayoutlibCallbackImpl.loadClass(LayoutlibCallbackImpl.java:193)
at android.view.BridgeInflater.loadCustomView(BridgeInflater.java:333)
at android.view.BridgeInflater.onCreateView(BridgeInflater.java:152)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:717)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:785)
at android.view.BridgeInflater.createViewFromTag(BridgeInflater.java:222)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:727)
at android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:858)
at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:70)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:834)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:821)
at android.view.LayoutInflater.inflate(LayoutInflater.java:518)
at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
at com.android.layoutlib.bridge.impl.RenderSessionImpl.inflate(RenderSessionImpl.java:324)
at com.android.layoutlib.bridge.Bridge.createSession(Bridge.java:429)
at com.android.ide.common.rendering.LayoutLibrary.createSession(LayoutLibrary.java:368)
at com.android.tools.idea.rendering.RenderTask$2.compute(RenderTask.java:567)
at com.android.tools.idea.rendering.RenderTask$2.compute(RenderTask.java:549)
at com.intellij.openapi.application.impl.ApplicationImpl.runReadAction(ApplicationImpl.java:863)
at com.android.tools.idea.rendering.RenderTask.createRenderSession(RenderTask.java:549)
at com.android.tools.idea.rendering.RenderTask.lambda$inflate$1(RenderTask.java:680)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Edit: Also, When i try to compile the code, my project would'nt start unless i delete the image file in my drawable folder due to this error : `Error:Execution failed for task ':app:mergeDebugResources'.
C:\Users\TP_baseline\AndroidStudioProjects\COMTProject(MeloWide)\app\src\main\res\drawable\icons8-Medal-80.png: Error: '-' is not a valid file-based resource name character: File-based resource names must contain only lowercase a-z, 0-9, or underscore`
Your image has dashes in the name. icons8-Medal-80.png
Replace it with an underscore or remove it.
Only lowercase alphanumeric (plus underscores) resource names are allowed, as indicated in the error.
The problem is arise in two condition
1)in android resource names must contain only lowercase a-z, 0-9, or underscore.
2)if your image is corrupted then provide this type of error.so check in your resource any image file is corrupted
Can any body suggest me which jar i shld use to resolve the below exception,
Exception in thread "main" java.lang.NoSuchMethodError: org.neo4j.graphdb.factory.GraphDatabaseSetting$BooleanSetting.<init>(Ljava/lang/String;)V
at org.neo4j.shell.ShellSettings.<clinit>(ShellSettings.java:37)
at sun.misc.Unsafe.ensureClassInitialized(Native Method)
at sun.reflect.UnsafeFieldAccessorFactory.newFieldAccessor(Unknown Source)
at sun.reflect.ReflectionFactory.newFieldAccessor(Unknown Source)
at java.lang.reflect.Field.acquireFieldAccessor(Unknown Source)
at java.lang.reflect.Field.getFieldAccessor(Unknown Source)
at java.lang.reflect.Field.get(Unknown Source)
at org.neo4j.kernel.configuration.AnnotatedFieldHarvester.findStatic(AnnotatedFieldHarvester.java:47)
at org.neo4j.kernel.configuration.AnnotationBasedConfigurationMigrator.<init>(AnnotationBasedConfigurationMigrator.java:40)
at org.neo4j.kernel.configuration.Config.<init>(Config.java:89)
at org.neo4j.kernel.InternalAbstractGraphDatabase.<init>(InternalAbstractGraphDatabase.java:218)
at org.neo4j.kernel.EmbeddedGraphDatabase.<init>(EmbeddedGraphDatabase.java:103)
at org.neo4j.graphdb.factory.GraphDatabaseFactory$1.newDatabase(GraphDatabaseFactory.java:88)
at org.neo4j.graphdb.factory.GraphDatabaseBuilder.newGraphDatabase(GraphDatabaseBuilder.java:207)
at org.neo4j.graphdb.factory.GraphDatabaseFactory.newEmbeddedDatabase(GraphDatabaseFactory.java:69)
at com.Neo4J.src.EmbeddedNeo4j.createDb(EmbeddedNeo4j.java:48)
at com.Neo4J.src.EmbeddedNeo4j.main(EmbeddedNeo4j.java:38).
I have already included the below jar,
neo4j-kernel-1.9.3.jar.
Thanks.
Make sure you have the matching neo4j-shell jar file.
The command javap -v -classpath neo4j-shell-1.9.3.jar org.neo4j.shell.ShellSettings | grep invoke indicates to me that there are only five methods called by ShellSettings. One is the Object default constructor, but that's during the constructor for ShellSettings, not the static class initialization <clinit>. The others are all from class org.neo4j.helpers.Settings. setting is called four times, in two different overloaded versions, matches and illegalValueMessage each once.
So in the 1.9.3 version of neo4j, the call to the constructor of GraphDatabaseSetting$BooleanSetting which is mentioned in your stack trace does not occur. therefore your ShellSettings class must come from some other version which is not binary compatible to 1.9.3. Use compatible versions, and you should be fine.
Update:
Now I found out something very strange, it works when i put the compiled test classes directly
into the "super-csv-dozer-2.1.0.jar" with the same structure as in the svn repo.
But as soon as i use my own package it wont work. I always used the entire path
like this: myPackage.csv.SurveyResponse.class
What am i missing? and why does it work in a normal Java Project but not in a Play Project?
I also tried it outside of eclipse in a different directory and dont have any checkouts from
the svn repo that could confuse the paths. Another thing i tried is to put the Writing.class into adifferent package but didnt help.
Original qustion:
Im trying to use SuperCSV with Dozer in a Play Project.
The official supercsv sample works fine in a separate Java Project.
But when I put the code and the needed SuperCSV Jars in a freshly created Play project I always
get a ClassNotfoundException for SurveyResponse.class in this line of code:
beanWriter.configureBeanMapping(myPackage.csv.SurveyResponse.class, FIELD_MAPPING);
Here a screenshot of my project structure:
http://oi44.tinypic.com/mrqp7s.jpg
I made sure that all the JARS are available, I put them unmanaged into the /lib folder,
they are available in eclipse and no errors appear during compilation.
I debugged the code and the SurveyResponse.class is found and the beanWriter is initialized.
So somehow Play must do some magic in the background to trigger this bug.
What could play be doing in the background to possibly trigger such odd behavior?
What could I try to do to fix this?
Changes I made to the sample so it works with Play:
I used exactly the same code as the offical supercsv example.
The only change i did is remove the Writing.main(..) method and set the methods Writing.writeWithDozerCsvBeanWriter()
and Writing.partialWriteWithCsvDozerBeanWriter() to public,so it can be accessed from the Application controller.
And of course I changed the package name in all classes to package myPackage.test;
Links to sample:
See in the comment, i cant add more than 2 links because of low reputation.
Controller:
public class Application extends Controller {
public static Result index() throws Exception {
Writing.writeWithDozerCsvBeanWriter();
Writing.partialWriteWithCsvDozerBeanWriter();
return ok(index.render("Your new application is ready."));
}
}
Code that triggers error in Writing class:
ICsvDozerBeanWriter beanWriter = null;
try {
beanWriter = new CsvDozerBeanWriter(new FileWriter("target/writeWithCsvDozerBeanWriter.csv"),
CsvPreference.STANDARD_PREFERENCE);
// configure the mapping from the fields to the CSV columns
//Here the exception occures:
beanWriter.configureBeanMapping(myPackage.csv.SurveyResponse.class, FIELD_MAPPING);
Stack trace:
play.api.Application$$anon$1: Execution exception[[MappingException: java.lang.ClassNotFoundException: myPackage.test.SurveyResponse]]
at play.api.Application$class.handleError(Application.scala:289) ~[play_2.10.jar:2.1.1]
at play.api.DefaultApplication.handleError(Application.scala:383) [play_2.10.jar:2.1.1]
at play.core.server.netty.PlayDefaultUpstreamHandler$$anon$2$$anonfun$handle$1.apply(PlayDefaultUpstreamHandler.scala:144) [play_2.10.jar:2.1.1]
at play.core.server.netty.PlayDefaultUpstreamHandler$$anon$2$$anonfun$handle$1.apply(PlayDefaultUpstreamHandler.scala:140) [play_2.10.jar:2.1.1]
at play.api.libs.concurrent.PlayPromise$$anonfun$extend1$1.apply(Promise.scala:113) [play_2.10.jar:2.1.1]
at play.api.libs.concurrent.PlayPromise$$anonfun$extend1$1.apply(Promise.scala:113) [play_2.10.jar:2.1.1]
at play.api.libs.concurrent.PlayPromise$$anonfun$extend$1$$anonfun$apply$1.apply(Promise.scala:104) [play_2.10.jar:2.1.1]
at scala.concurrent.impl.Future$PromiseCompletingRunnable.liftedTree1$1(Future.scala:24) [scala-library.jar:na]
at scala.concurrent.impl.Future$PromiseCompletingRunnable.run(Future.scala:24) [scala-library.jar:na]
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source) [na:1.6.0_37]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) [na:1.6.0_37]
at java.lang.Thread.run(Unknown Source) [na:1.6.0_37]
org.dozer.MappingException: java.lang.ClassNotFoundException: myPackage.test.SurveyResponse
at org.dozer.util.MappingUtils.throwMappingException(MappingUtils.java:82) ~[dozer-5.4.0.jar:na]
at org.dozer.util.DefaultClassLoader.loadClass(DefaultClassLoader.java:38) ~[dozer-5.4.0.jar:na]
at org.dozer.util.MappingUtils.loadClass(MappingUtils.java:224) ~[dozer-5.4.0.jar:na]
at org.dozer.loader.DozerBuilder$MappingBuilder.classA(DozerBuilder.java:129) ~[dozer-5.4.0.jar:na]
at org.dozer.loader.api.BeanMappingBuilder.mapping(BeanMappingBuilder.java:72) ~[dozer-5.4.0.jar:na]
at org.dozer.loader.api.BeanMappingBuilder.mapping(BeanMappingBuilder.java:67) ~[dozer-5.4.0.jar:na]
at org.supercsv.io.dozer.CsvDozerBeanWriter$MappingBuilder.configure(CsvDozerBeanWriter.java:178) ~[super-csv-dozer-2.1.0.jar:na]
at org.dozer.loader.api.BeanMappingBuilder.build(BeanMappingBuilder.java:42) ~[dozer-5.4.0.jar:na]
at org.dozer.DozerBeanMapper.addMapping(DozerBeanMapper.java:258) ~[dozer-5.4.0.jar:na]
at org.supercsv.io.dozer.CsvDozerBeanWriter.configureBeanMapping(CsvDozerBeanWriter.java:91) ~[super-csv-dozer-2.1.0.jar:na]
at myPackage.test.Writing.writeWithDozerCsvBeanWriter(Writing.java:88) ~[na:na]
at controllers.Application.index(Application.java:12) ~[na:na]
at Routes$$anonfun$routes$1$$anonfun$applyOrElse$1$$anonfun$apply$1.apply(routes_routing.scala:49) ~[na:na]
at Routes$$anonfun$routes$1$$anonfun$applyOrElse$1$$anonfun$apply$1.apply(routes_routing.scala:49) ~[na:na]
at play.core.Router$HandlerInvoker$$anon$6$$anon$2.invocation(Router.scala:164) ~[play_2.10.jar:2.1.1]
at play.core.Router$Routes$$anon$1.invocation(Router.scala:345) ~[play_2.10.jar:2.1.1]
at play.core.j.JavaAction$$anon$1.call(JavaAction.scala:31) ~[play_2.10.jar:2.1.1]
at play.core.j.JavaAction$$anon$2.apply(JavaAction.scala:74) ~[play_2.10.jar:2.1.1]
at play.core.j.JavaAction$$anon$2.apply(JavaAction.scala:73) ~[play_2.10.jar:2.1.1]
at play.libs.F$Promise$PromiseActor.onReceive(F.java:420) ~[play_2.10.jar:2.1.1]
at akka.actor.UntypedActor$$anonfun$receive$1.applyOrElse(UntypedActor.scala:159) ~[akka-actor_2.10.jar:na]
at akka.actor.ActorCell.receiveMessage(ActorCell.scala:425) ~[akka-actor_2.10.jar:na]
at akka.actor.ActorCell.invoke(ActorCell.scala:386) ~[akka-actor_2.10.jar:na]
at akka.dispatch.Mailbox.processMailbox(Mailbox.scala:230) ~[akka-actor_2.10.jar:na]
at akka.dispatch.Mailbox.run(Mailbox.scala:212) ~[akka-actor_2.10.jar:na]
at akka.dispatch.ForkJoinExecutorConfigurator$MailboxExecutionTask.exec(AbstractDispatcher.scala:502) ~[akka-actor_2.10.jar:na]
at scala.concurrent.forkjoin.ForkJoinTask.doExec(ForkJoinTask.java:262) ~[scala-library.jar:na]
at scala.concurrent.forkjoin.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:975) ~[scala-library.jar:na]
at scala.concurrent.forkjoin.ForkJoinPool.runWorker(ForkJoinPool.java:1478) ~[scala-library.jar:na]
at scala.concurrent.forkjoin.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:104) ~[scala-library.jar:na]
Caused by: java.lang.ClassNotFoundException: myPackage.test.SurveyResponse
at java.net.URLClassLoader$1.run(Unknown Source) ~[na:1.6.0_37]
at java.security.AccessController.doPrivileged(Native Method) ~[na:1.6.0_37]
at java.net.URLClassLoader.findClass(Unknown Source) ~[na:1.6.0_37]
at java.lang.ClassLoader.loadClass(Unknown Source) ~[na:1.6.0_37]
at java.lang.ClassLoader.loadClass(Unknown Source) ~[na:1.6.0_37]
at sbt.PlayCommands$$anonfun$53$$anonfun$55$$anon$2.loadClass(PlayCommands.scala:535) ~[na:na]
at java.lang.Class.forName0(Native Method) ~[na:1.6.0_37]
at java.lang.Class.forName(Unknown Source) ~[na:1.6.0_37]
at org.apache.commons.lang3.ClassUtils.getClass(ClassUtils.java:823) ~[commons-lang3.jar:3.1]
at org.apache.commons.lang3.ClassUtils.getClass(ClassUtils.java:889) ~[commons-lang3.jar:3.1]
at org.apache.commons.lang3.ClassUtils.getClass(ClassUtils.java:872) ~[commons-lang3.jar:3.1]
at org.dozer.util.DefaultClassLoader.loadClass(DefaultClassLoader.java:36) ~[dozer-5.4.0.jar:na]
... 28 common frames omitted
Extra information:
I still couldnt solve the problem, but here some extra infomation to narrow down the problem:
The csv header is successfully written to the file when i remove the configureBeanMapping Method call (see code below).
The SurveyResponse class is working too when i do a System.out.println() on a filled SurveyResponse object (see code below).
So its not a problem with the package or class name.
The modiefied Code that writes only the header:
//...more code
myPackage.csv.SurveyResponse response3 = new myPackage.csv.SurveyResponse(42, false, Arrays.asList(new Answer(1, null), new Answer(2,
"Carl Sagan"), new Answer(3, "Star Wars")));
final List<myPackage.csv.SurveyResponse> surveyResponses = Arrays.asList(response1, response2, response3);
ICsvDozerBeanWriter beanWriter = null;
try {
beanWriter = new CsvDozerBeanWriter(new FileWriter("target/writeWithCsvDozerBeanWriter.csv"),
CsvPreference.STANDARD_PREFERENCE);
// configure the mapping from the fields to the CSV columns
//beanWriter.configureBeanMapping(myPackage.csv.SurveyResponse.class, FIELD_MAPPING);
//Prints the value 42 successfully
System.out.println(response3.getAge());
// write the header
beanWriter.writeHeader("age", "consentGiven", "questionNo1", "answer1", "questionNo2", "answer2","questionNo3", "answer3");
//...more code
From what I understand from the error, Play is trying to load the wrong class. Look at this line :
java.lang.ClassNotFoundException: org.supercsv.mock.dozer.SurveyResponse
I think that SurverResponse is one of your own project classes and not part of SuperCSV. Try to prefix it with the full path such as :
beanWriter.configureBeanMapping(whateverpackage.models.SurveyResponse.class, FIELD_MAPPING);
SurveyResponse and Answer are test classes of the super-csv-dozer artifact - so they aren't packaged in the distribution (i.e they're not in Maven or in the zip file on SourceForge).
You can view the test source online or checkout the SVN repo (which it sounds like you've already done) and just copy them into your Play project.
Both files are in the following directory:
supercsv/super-csv-dozer/src/test/java/org/supercsv/mock/dozer/
I'm a little curious why you're not getting a compilation error when trying to use SurveyResponse in your code. My guess is that you have the super-csv-dozer project checked out and open in your IDE and your project is finding it.
I have a bundle ("com.elsten.bliss.platform") that uses another bundle ("net.contentobjects.jnotify"). net.contentobjects.jnotify loads native libraries to do its job, which are contributed by fragments. The native code is loaded in a static class initializer inside a class within the net.contentobjects.jnotify bundle:
static
{
System.loadLibrary("jnotify");
int res = nativeInit();
if (res != 0)
{
throw new RuntimeException("Error initializing fshook_inotify library. linux error code #" + res + ", man errno for more info");
}
init();
}
I can start and stop com.elsten.bliss.platform and it appears to work ok. The problem comes when updating com.elsten.bliss.platform. When I update, I get:
2013-04-04 11:58:20,356 [ERROR] Couldn't initialise JNotify: java.lang.UnsatisfiedLinkError: Native Library /home/gravelld/eclipse-workspaces/bliss/net.contentobjects.jnotify.linux.amd64/lib/libjnotify.so already loaded in another classloader (JnotifyFileSystemObserver.java:53, thread platformExecutor)
java.lang.UnsatisfiedLinkError: Native Library /home/gravelld/eclipse-workspaces/bliss/net.contentobjects.jnotify.linux.amd64/lib/libjnotify.so already loaded in another classloader
at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1715)
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1675)
at java.lang.Runtime.loadLibrary0(Runtime.java:840)
at java.lang.System.loadLibrary(System.java:1047)
at net.contentobjects.jnotify.linux.JNotify_linux.<clinit>(JNotify_linux.java:48)
at net.contentobjects.jnotify.linux.JNotifyAdapterLinux.<init>(JNotifyAdapterLinux.java:76)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:532)
at java.lang.Class.newInstance0(Class.java:374)
at java.lang.Class.newInstance(Class.java:327)
at net.contentobjects.jnotify.JNotify.<clinit>(JNotify.java:75)
at com.elsten.bliss.platform.storage.file.JnotifyFileSystemObserver.startWatching(JnotifyFileSystemObserver.java:43)
at com.elsten.bliss.platform.storage.file.NotifyFilesAtStartFileSystemObserver.start(NotifyFilesAtStartFileSystemObserver.java:117)
at com.elsten.bliss.platform2.PlumbedStorageSubsystem.start(PlumbedStorageSubsystem.java:69)
at com.elsten.bliss.client.impl.ConfigurationClientImpl$3.doRun(ConfigurationClientImpl.java:337)
at com.elsten.util.CatchThrowableRunnable.run(CatchThrowableRunnable.java:23)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
at java.util.concurrent.FutureTask.run(FutureTask.java:166)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1146)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:679)
Ok, so I know you can only have any one native library loaded by one classloader. But in this case, why is there more than one class loader? The net.contentobjects.jnotify is not updated, so I thought the existing classes should just continue on and be used by JnotifyFileSystemObserver.startWatching - it appears this method is reloading the class.
How do I avoid this?
Interestingly, that code if called twice should not raise an exception; the javadoc for java.lang.Runtime#loadLibrary() states that
If this method is called more than once with the same library name, the second and subsequent calls are ignored.
So, there might be more to it. Have you tried setting the singleton property in the Bundle-SymbolicName entry of the MANIFEST.MF?
I created a new maven project in Eclipse and on runtime I get this error:
Exception in thread "main" java.lang.NoClassDefFoundError: =
Caused by: java.lang.ClassNotFoundException: =
at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
Could not find the main class: =. Program will exit.
In other threads the class is mentioned where the problem occurs but here it simply says nothing.
The code is also used in a different project (with slight tweaks in terms of calling a method) but the rest of it is same.
If anyone can help me resolve this issue..it will be highly appreciated.
It looks like something is passing in = as the class name. It doesn't say nothing - it says =.
For example, when I run:
java =
I get:
Error: Could not find or load main class =
There's no colon, but it's otherwise the same.
Look at where you're trying to specify the class name, and see whether there's a stray = around. For example, suppose you had:
java -Dfoo = bar ClassName
instead of
java -Dfoo=bar ClassName
You'd see the same thing. I'm not familiar with Maven, but if you ever specify a set of arguments in it, I'd look at that part of the configuration file.
Deleting the workspace worked for me.