> String name = propsName.replace('.', '/').concat(".properties")
that doesn't look right to me.
resource names are not paths.
Main Topics
Browse All TopicsI am having problems running my Junit tests via Ant. I can't seem to get Ant to see the properties file it needs to load a dll my project needs. All my tests work using the Junit GUI in Elcipse, so I'm pretty sure it's not a problem with the tests themselves. I think my problem is something classpath-related, but I can't seem to find the problem.
jar strucure: /root/folder/../Foo.proper
I could really use a second set of eyes, so any help is appreciated. Thanks in advance!
--Charly
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
I looked at the jar file I am building and it's folder structure is exactly the same as where I am copying it. In my compile target, I am taking all the files in my resources directory and copying them over to my build/classes directory with their folder structure intact.
When I build the jar manually and run it, it is able to find the properties file without problems. It just seems like while I am running everything in Ant that I get into problems.
I looked over that string manipulation part as well, and it looks like the original author was translating the fully qualified class name into a folder hierarchy, and tacking on a ".properties" at the end like so:
foo.bar.SomeClass
turns into
foo/bar/SomeClass.properti
It seems to work for the most part, but I'm thinking that is part of my problem. The author was banking on the fact that the folder structure was going to be exactly the same as the class name right off the root directory. It seems to work for the usual case, but is inflexible.
My most recent line of thought on this is that the root folder where the unit tests are being run at in Ant has an extra directory or two at the top? So when it looks for /foo/bar/SomeClass.propert
Just in case I am omitting something you need, I will include the entire build file below. Thanks for helping me.
--Charly
If the properties file is inside the jar when it is run, isn't that in the classpath? How come it can find it when I run the jar from the command line, but not when I run it with Ant? I am confused.
If I have the root directory of foo/bar/classes in the classpath, does it recursively add everything beneath it like foo/bar/classes/pkg1/pkg2/
Thanks again.
--Charly
yes it will find it in the jar.
you just need to make sure the properties file is available somewhere in the classpath (in your case the one used by the system class loader).
It will use the package structure from the resource name when doing the search
ie. it looks for resources the same way it looks for class files.
You problem may be related to the fact that you're using the system classloader to search for the resource, not sure what classpath thats uses with ant.
Another thing I don't understand is that I am running all my tests against a newly created jar file. So if it can find files inside the jar file why can't Ant's classloader find those files?
I really want to automate all of my tests so that everytime the project is built it gets it's tests run, but it is seeming more difficult than I thought...
--Charly
Thanks for your continued help objects, I really appreciate it.
Ok, so I tried the code below and still no dice, so I think I'll try and explain what is happening in the hopes that it becomes clearer to us both. Here is the poor, sad life of the JCustomOpc.properties file...
Before the build is run, I have ./resources/javafish/clien
When the build is run:
Ant adds all the jars in ./lib to it's classpath
Ant copies properties file over to ./build/classes/javafish/c
Ant packages the jar file with everything from ./build/classes
Ant adds the new jar file to it's classpath
Ant adds all the files in ./build/test/classes in it's classpath.
Ant copies properties file over to ./build/test/classes/javaf
Ant then runs the Junit tests and is unable to find JCustomOpc.properties.
> Ant copies properties file over to ./build/test/classes/javaf
that step appears unnecessary as the properties are already in the jar
regards loading try:
props.load(JCustomOpc.clas
or
ResourceBundle bundle = ResourceBundle.getBundle("
objects:
I am posting the code for all the different attempts I have been making. I still can't seem to get it to work. It's frustrating since I used properties files elsewhere in some of my tests (which I got to work) and that way doesn't seem to work for this problem.
There seems to be many different ways to read in a properties file. Which is the best practice way to do it?
CEHJ:
PropertyLoader is a class in the library I am using to read in a properties file which has the location of a dll it needs. The first code snippet I posted shows how they originally did it. It used the system classloader instead of the contextual one, so objects and I think we are running into problems with the information being in the wrong classloader.
I attached my jars tf
Oh, I forgot to mention that in my build file, in order to load the test.properties file (the setup which works), I had to add a <sysproperty/> tag in the junit task like the code below.
I read that is the same as passing in the argument to the JVM: -Dtest.properties=test.pro
Thank you again for both your help.
--Charly
CEHJ:
Now I think that the problem might not just be the properties file. After trying your suggestion, I hard-coded in the property I am looking for, and I am still getting the same errors.
It looks like the dll my library needs isn't getting on the classpath. I tried to add the dll to my classpath but I got a whole bunch more errors. What's the best way to do that?
Sorry I keep jumping around like this. I am not very experienced with using external dlls and such. Thanks for your patience.
--Charly
Well, I think we are getting closer to the real problem. After doing some digging, I managed to set the java.library.path environment variable in the jvm that junit forks during the build.
I finally got it to run correctly,albeit with the hard-coded path to the library. Now all I need is to figure out what is going wrong trying to look it up in the properties file, which is back to the original problem! heh
So now that we know it can find the library correctly, what would be a good next step trying to figure out why we can't find the properties file inside the jar?
--Charly
I know,but I think it didn't work due to the java.library.path not containing a reference to my ./lib directory like CEHJ pointed out.
It must have been getting the string from the properties file, but was then unable to load the library. I just wasn't sharp enough at the time to piece it all together and figure it out.
I didn't ignore your post, honest.
--Charly
You know what, you're right. I removed the java.library.path modifications in the build file and it still works. Wow, I feel like a tool now. I don't know what I did wrong when I originally tried your solution, but it does work like you said.
Looking over things again, it looks like your original post forgot the s in clients. I'm not blaming you or anything, I should have caught that, but I missed it for whatever reason last night. :/ Oh well...
Well, if I ever -do- need to modify the java.library.path later on, I guess I'll know how to now. :)
Business Accounts
Answer for Membership
by: objectsPosted on 2008-12-07 at 18:07:26ID: 23118356
Are your properties files being copied correctly into the directory in your classpath?