MissingResourceException: Can't find bundle base name - spring

When running a jar file that i created from a maven project as such:
java -jar basictool.jar
I get this error exception:
Exception in thread "main" 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 org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoader.java:58)
Caused by: java.util.MissingResourceException: Can't find bundle for base name com/kit/version, locale en_US
at java.util.ResourceBundle.throwMissingResourceException(UnknownSource)
at java.util.ResourceBundle.getBundleImpl(Unknown Source)
at java.util.ResourceBundle.getBundle(Unknown Source)
at com.factories.FactoryImpl.<init>(FactoryImpl.java:80)
at com.parsers.BasicParser.<init>(BasicParser.java:32)
at com.parsers.FileParser.<init>(FileParser.java:76)
at com.tools.BasicTool.main(BasicTool.java:75)
... 5 more
I created the jar file by using the maven jar creation wizard:
Right-click on project, select Export > Java > Runnable JAR file with options
Launch configuration: BasicTool - work
Export destination: C:\Users\Victor\Documents\basictool.jar
Library handling: Package required libraries into generated JAR
The version.properties file is kept inside of the src/main/resources, as com/kit/version.properties.
I have checked that the version.properties file is found inside of the jar file by running:
jar tf basictool.jar > output.txt
where i find the version.properties file as such:
resources/com/kit/version.properties
I attempt to load the resource like this:
ResourceBundle.getBundle("com/kit/version");
My machine and environment specifications are as followed:
Windows 7, Spring version: 3.7.2.
Note:
I found many questions similar to the one i have, but the answers i have found point to the properties file being properly named or placed in the correct location. From those answers i learned that version.properties is fine, since ResourceBundle.getBundle("com/kit/version") will first look for version.class then version.properties by default. It will also look for version_en_US.properties before ultimately looking for the base name version.properties.
I seem to be in line with the above, since the file version.properties is in the correct location and named correctly. I also seem to be in line with what other answers have offered :(
I would also like to point out that it finds the resource just fine when i run the program from spring, which brings me to suspect that something about the jar's creation process is the cause of the problem.
And it is also important to note that the properties file is in another maven project.
I hope i offered enough/clear details. Any help would be appreciated, thank you in advance!

If your application calls ResourceBundle.getBundle("com/kit/version"); from with in Eclipse everything works fine.
But when you create a jar file in the way you described (export -> java -> runnable jar), the version.properties is placed within the jar file at resources/com/kit/version.properties. Mind the "resources" in front of the path.
If you call this jar with java -jar basictool.jar outside Eclipse the version.properties cannot be found and java.util.MissingResourceExceptionis thrown.
If you change the path and call ResourceBundle.getBundle("resources/com/kit/version"); it won't work within Eclipse but java -jar basictool.jar will do.
It seems exporting the project from Eclipse causes the problem.
I would suggest to create the jar file to use without Eclipse with the maven-assembly-plugin.
An example can be found here.
This plugin creates a jar file without the resources directory and so the call of ResourceBundle.getBundle("com/kit/version"); works within and outside of Eclipse.

Related

Use Nd4j in an Intellij project

I'm trying to use Nd4j in a Kotlin project in Intellij IDEA. In Project Structure -> Libraries, I used the "From Maven" command to add the following libraries.
org.deeplearning4j:deeplearning4j-core:1.0.0-beta
org.nd4j:nd4j-native-platform:1.0.0-beta
org.datavec:datavec-api:1.0.0-beta
With those libraries I can compile my project, but when I run it fails with an exception.
Caused by: java.lang.RuntimeException: ND4J is probably missing dependencies. For more information, please refer to: http://nd4j.org/getstarted.html
at org.nd4j.nativeblas.NativeOpsHolder.<init>(NativeOpsHolder.java:51)
at org.nd4j.nativeblas.NativeOpsHolder.<clinit>(NativeOpsHolder.java:19)
... 10 more
Caused by: java.lang.UnsatisfiedLinkError: no jnind4jcpu in java.library.path
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1867)
at java.lang.Runtime.loadLibrary0(Runtime.java:870)
at java.lang.System.loadLibrary(System.java:1122)
at org.bytedeco.javacpp.Loader.loadLibrary(Loader.java:1220)
at org.bytedeco.javacpp.Loader.load(Loader.java:980)
at org.bytedeco.javacpp.Loader.load(Loader.java:879)
at org.nd4j.nativeblas.Nd4jCpu.<clinit>(Nd4jCpu.java:10)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:348)
at org.bytedeco.javacpp.Loader.load(Loader.java:938)
at org.bytedeco.javacpp.Loader.load(Loader.java:879)
at org.nd4j.nativeblas.Nd4jCpu$NativeOps.<clinit>(Nd4jCpu.java:1310)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:264)
at org.nd4j.nativeblas.NativeOpsHolder.<init>(NativeOpsHolder.java:29)
... 11 more
Caused by: java.lang.UnsatisfiedLinkError: no nd4jcpu in java.library.path
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1867)
at java.lang.Runtime.loadLibrary0(Runtime.java:870)
at java.lang.System.loadLibrary(System.java:1122)
at org.bytedeco.javacpp.Loader.loadLibrary(Loader.java:1220)
at org.bytedeco.javacpp.Loader.load(Loader.java:965)
... 21 more
Looking through the project folder I see that IDEA has downloaded lots of jar files for nd4j-native-platform, but there's no sign of any JNI libraries. What else do I have to do?
Intellij's "From Maven" feature doesn't support the classifiers that JavaCPP and ND4J (and other libraries that use native code) use. Maven will work great but if you really can't use it for some reason, you can manually add the nd4j-native-1.0.0-beta2-macosx-x86_64.jar file and openblas-0.3.0-1.4.2-macosx-x86_64.jar file. That should be enough to run simple things, but you'll have to manually do that for every other native dependency as you use more and more stuff (like OpenCV). That's why Maven is recommended.
If you include those 3 dependencies, there are zero reasons why it should fail unless you're on an unsupported OS for some reason.
We support everything from android to IBM power so that is unlikely though.
I'm also confused by what you mean about not seeing any JNI libraries. Those are all in the jar files. We use javacpp (which we also maintain) to manage those things.
You will find those libraries under ~/.javacpp/cache - you should not have any reason to touch those though.
Could you clarify what you are looking for there?
Beyond that, there is nothing else you have to do. I'm assuming something just didn't load correctly.
Our standalone pom works out of the box: https://github.com/deeplearning4j/dl4j-examples/blob/master/standalone-sample-project/pom.xml - maybe double check this, that or reload. I can only assume you created the project wrong somehow. File -> New Maven project should be all you need to do.

FHIR build fails with NoSuchMethodError: net.sf.saxon.Configuration.newConfiguration()

Following instructions at http://wiki.hl7.org/index.php?title=FHIR_Build_Process my FHIR build is failing. I modified the publish.bat to ensure it uses the correct JDK. Running it on Windows 7 64-bit machine with JDK 1.6 (also tried JDK 1.7) and both failing with same error.
Looks like some Saxon JAR hell somewhere. Any ideas?
...validate v2-tables 441sec 755MB
...validate v3-codesystems 443sec 889MB
Reference Platform Validation. 447sec 1067MB
...test adversereaction-example 447sec 1067MB
Exception in thread "main" java.lang.NoSuchMethodError: net.sf.saxon.Configuration.newConfiguration()Lnet/sf/saxon/Configuration
;
at net.sf.saxon.xpath.XPathFactoryImpl.<init>(XPathFactoryImpl.java:33)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at java.lang.Class.newInstance0(Class.java:355)
at java.lang.Class.newInstance(Class.java:308)
at javax.xml.xpath.XPathFactoryFinder.loadFromService(XPathFactoryFinder.java:401)
at javax.xml.xpath.XPathFactoryFinder._newFactory(XPathFactoryFinder.java:222)
at javax.xml.xpath.XPathFactoryFinder.newFactory(XPathFactoryFinder.java:143)
at javax.xml.xpath.XPathFactory.newInstance(XPathFactory.java:185)
at javax.xml.xpath.XPathFactory.newInstance(XPathFactory.java:99)
at org.hl7.fhir.tools.publisher.Publisher.testSearchParameters(Publisher.java:2796)
at org.hl7.fhir.tools.publisher.Publisher.testSearchParameters(Publisher.java:2785)
at org.hl7.fhir.tools.publisher.Publisher.validateRoundTrip(Publisher.java:2759)
at org.hl7.fhir.tools.publisher.Publisher.validateXml(Publisher.java:2656)
at org.hl7.fhir.tools.publisher.Publisher.execute(Publisher.java:378)
at org.hl7.fhir.tools.publisher.Publisher.main(Publisher.java:281)
A workaround... do a fresh build of the publisher tool jar from source.
Following instructions in the build/buildhowto.txt I was able to build the tool jar inside Eclipse, run the Publisher successfully from inside Eclipse and then export it as a fresh tool jar overwriting the one I pulled from SVN. The freshly build one then ran to completion from the command line.
Could be there's just a problem with the version of tools jar out there in SVN at the moment.
For the record I am working with Version 0.12-1953.
You have two classes net.sf.saxon.Configuration in your classpath. One containing the method newConfiguration() and one not.
The method is probably called from Saxon-HE 9.x, and the class net.sf.saxon.Configuration is found in saxon 8.x, while the class should have been found inside Saxon-HE 9.x, where it also is, and does have this method.
So, check your dependencies to see if saxon 8.x is called, and try replacing that with Saxon-HE 9.x, then your problem is solved

Setting osgi.configuration.area breaks my Equinox OSGI app

I have an application which uses Equinox as an osgi framework for a while now. Until now I used the system property osgi.install.area to specify where my bundles are like so
${osgi.install.area}/
plugins/
org.eclipse.osgi_3.7.0.v20110613.jar
... my app bundles
Equinox then automatically uses ${osgi.install.area}/configuration as the configuration area.
Everything works fine.
Now I need to move the configuration area out of ${osgi.install.area} because that may be read-only and I thought it was as simple as setting ${osgi.configuration.area} to a suitable path but when I do this the application no longer starts and I have the following stack trace in the logs:
java.lang.IllegalStateException: Unable to acquire application service. Ensure that the org.eclipse.core.runtime bundle is resolved and started (see config.ini).
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:74)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:344)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:179)
at org.eclipse.core.runtime.adaptor.EclipseStarter.main(EclipseStarter.java:150)
...
The path is used because at that location the log file is created and a directory "org.eclipse.osgi".
Paths to bundles are referenced in my config.ini like so:
osgi.bundles=de.mycomp.app-0.6.0.20121116-1834.jar#start, ...
The error message does not really give a hint where to look. It must be something rather simple but I am rather clueless at the moment.
Thanks in advance,
Robert
I tested changing the configuration area an existing osgi app and it worked, with the following argument below in the .ini file in the root of the install. Are you sure you are setting the config param correctly like this:
-Dosgi.configuration.area=c:\mytest
After doing that and running the app again, it created the folder and a new configuration.
Here is a copy of my .ini file that works, also it's important that osgi params come after and vm args.
-loglevel=trace
-vmargs
-Dosgi.configuration.area=c:\mytest
-Dorg.osgi.service.http.port=8094
-Declipse.ignoreApp=true
-Dosgi.noShutdown=true
-Dequinox.ds.print=true

Trouble installing Kyoto Tycoon - Java. Maven failing

I've downloaded Kyoto Tycoon via:
hxxps://bitbucket.org/EP/kyototycoon-java
When running mvn install I get plenty of warnings telling me it couldn't find several files:
http://pastebin.com/znpJ3d5n
When I first started running the install I was getting a lot of failures and no errors. After blindly going around and trying to install things separately, the output now looks like this. I have no experience with Maven so editing the pom.xml file is out of the question. I've tried using the ignore tests and compiling, and I get few jar files. This allows me to compile "Example.java" using:
javac -cp .:target/kyototycoon-0.2-SNAPSHOT.jar Example.java
I then try to run the code using:
java -cp .:target/kyototycoon-0.2-SNAPSHOT.jar Example
but I get an runtime error:
Exception in thread "main" java.lang.NoClassDefFoundError: Exception in thread "main" java.lang.NoClassDefFoundError: com/twitter/finagle/Codec
at kyototycoon.SimpleKyotoTycoonClient.<init>(SimpleKyotoTycoonClient.java:16)
at Example.main(Example.java:11)
Caused by: java.lang.ClassNotFoundException: com.twitter.finagle.Codec
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)
... 2 more
I'm assuming this all comes back the the maven install failing, but I'm not sure how to fix it.
Any direction is appreciated. There doesn't seem to be a large support group for Kyoto.
For anyone experiencing this same issue, I found that JAR files I needed were being created. They were being stored in ~/.m2/repository/kyototycoon/kytotycoon/. I created a disgusting looking classpath that included all of these JAR files and this allowed me to compile AND run the Example.java file.
If "editing the pom file is out of the question" I'd strongly recommend steering clear of Maven.
In any case, you can install local jars to your repository if the artifact isn't available from any repository.

Netbeans Including XML and Properties when building Spring projects with Maven

I am new to Maven and Spring. I'm using Netbeans 7 as my IDE, and setting up a Spring 3 project using Maven.
Everything seemed to set up smoothly, and I began running through the Spring User Guide. However, I'm getting a file not found exception when trying to load my context.xml file.
I have an App class located at com.myproject and the context.xml file is located at com.myproject.conf
I'm using the following line of code in App.java to try and load the context.xml file:
ApplicationContext context = new ClassPathXmlApplicationContext("context.xml");
But when I run the application, it results in:
Exception in thread "main" org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from class path resource [context.xml]; nested exception is java.io.FileNotFoundException: class path resource [context.xml] cannot be opened because it does not exist
Looking at the NetBeans output, it also looks like it's not picking up the log4j.properties file which is also located in com.myproject.conf
I looked at the jar that the build process created, and the entire com.myproject.conf package is missing, meaning the .xml and .properties are missing as well. I've tried moving these config files to the com.myproject package as well as just putting them at the root of the project which don't yield any different results.
So I'm making the assumption that my maven project isn't set up entirely correctly, or maybe a setting isn't correct within NetBeans.
It seems like you need to learn about resources in Maven projects (such as XML, bitmaps, etc...). These are stored in separate directories. See here.
Put the package in "Other Sources"
I have the same problem with a .property file to manage the Internationalization.
I create it in com.company.app.view.resources at the Source Packages directory.
When I build the project and then look at my war file (target).. I don't found the .property file in /WEB-INF/classes/com/company/app/view/resources
Then I put the package in "Other Sources" directory and it works for me.

Resources