[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

Question
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

7.7

Locate Properties File Inside Jar During Junit Tests with Ant

Asked by cbuch in ANT, Java Programming Language, Eclipse

Tags: Ant 1.7.1, Java 6, Junit 3, Eclipse 3.3.1

I 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.properties

I could really use a second set of eyes, so any help is appreciated. Thanks in advance!

--Charly
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
This is how the properties file is loaded in the library:
 
 
// load class properties
props = PropertyLoader.loadProperties(Foo.class);
 
public static Properties loadProperties(Class className) {
    return loadProperties(className.getName());
}
 
public static Properties loadProperties(final String propsName) {
    Properties props = null;
    InputStream in = null;
    try {
      ClassLoader cl = ClassLoader.getSystemClassLoader();
      String name = propsName.replace('.', '/').concat(".properties");
 
      in = cl.getResourceAsStream(name);
      if (in != null) {
        props = new Properties();
        props.load(in);
      }
    }
    catch (Exception e) {
      props = null;
    }
    finally {
      if (props == null) {
        System.err.print("Property file " + propsName + " doesn't exist. System terminated.");
        System.exit(0);
      }
    }
 
    return props;
  }
 
 
Except from build file in question:
 
 
<!-- Pattern of source files to copy into classpath-->
    <property name="source.files.tocopy"
        value="**/*.properties,**/*.dtd,**/*.xml,**/*.jpg" />
 
    <path id="compile.classpath">
        <fileset dir="lib">
                <include name="*.jar" />
        </fileset>
    </path>
 
    <!-- Generate Class-Path entry for the JAR's Manifest -->
    <pathconvert property="manifest.classpath" 
        pathsep=" " dirsep="\">
        <map from="${basedir}/" to="" />
        <fileset dir="lib">
                <include name="*.jar" />
        </fileset>
    </pathconvert>
 
    <!-- Run tests against the JAR -->
    <path id="test.compile.classpath">
        <path refid="compile.classpath" />
        <pathelement location="${target.jar}" />
    </path>
 
    <path id="test.classpath">
        <path refid="test.compile.classpath" />
        <pathelement location="${test.classes.dir}" />
    </path>
 
 
 
    <!-- - - - - - - - - - - - - - - - - - 
          target: test-compile                      
         - - - - - - - - - - - - - - - - - -->
    <target name="test-compile" depends="compile, test-init"
        description="Compiles our testing code">
 
        <javac destdir="${test.classes.dir}"
                        debug="true"
                        includeAntRuntime="true"
                        srcdir="test">
                <classpath refid="test.compile.classpath" />
        </javac>
 
        <copy todir="${test.classes.dir}">
                <fileset dir="test" includes="${source.files.tocopy}"/>
                <fileset dir="resources" includes="${source.files.tocopy}"/>
        </copy>
 
    </target>
 
 
    <!-- ================================= 
          target: test              
         ================================= -->
    <target name="test" depends="test-compile, optional-tests">
 
        <description>
                Runs our tests, generates reports, and stops 
                the build on failure.  Optionally runs one test.
        </description>
 
        <junit printsummary="false" 
                errorProperty="test.failed" 
                failureProperty="test.failed">
                <classpath>
                        <path refid="test.classpath" />
                </classpath>                    
                <sysproperty key="test.properties" value="${test.properties.file}"/>
                <formatter type="brief" usefile="false" />
                <formatter type="xml" />
                <test name="${testcase}" todir="${test.data.dir}" if="testcase" />
                <batchtest todir="${test.data.dir}" unless="testcase">
                        <fileset dir="${test.classes.dir}">
                                <patternset>
                                        <include name="**/test/*Test.class" />
                                        <exclude name="**/test/*Printer*.class" unless="test.properties.file" />
                                </patternset>
                        </fileset>
                </batchtest>
        </junit>
[+][-]12/07/08 06:07 PM, ID: 23118356Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]12/07/08 06:09 PM, ID: 23118359Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]12/07/08 06:58 PM, ID: 23118508Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]12/07/08 07:04 PM, ID: 23118534Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]12/07/08 07:09 PM, ID: 23118549Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]12/07/08 07:14 PM, ID: 23118570Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]12/07/08 07:24 PM, ID: 23118615Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]12/07/08 07:48 PM, ID: 23118666Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]12/07/08 07:53 PM, ID: 23118678Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]12/07/08 07:57 PM, ID: 23118689Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]12/07/08 07:58 PM, ID: 23118691Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]12/07/08 09:04 PM, ID: 23118872Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]12/07/08 09:12 PM, ID: 23118890Accepted Solution

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

About this solution

Zones: ANT, Java Programming Language, Eclipse
Tags: Ant 1.7.1, Java 6, Junit 3, Eclipse 3.3.1
Sign Up Now!
Solution Provided By: objects
Participating Experts: 2
Solution Grade: A
 
[+][-]12/08/08 01:08 AM, ID: 23119282Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]12/08/08 08:49 AM, ID: 23121807Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]12/08/08 09:47 AM, ID: 23122305Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]12/08/08 10:00 AM, ID: 23122433Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]12/08/08 10:53 AM, ID: 23122921Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]12/08/08 11:05 AM, ID: 23123058Assisted Solution

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 30-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]12/08/08 11:10 AM, ID: 23123100Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]12/08/08 01:04 PM, ID: 23124198Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]12/08/08 01:07 PM, ID: 23124232Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]12/08/08 01:27 PM, ID: 23124426Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]12/08/08 01:28 PM, ID: 23124453Assisted Solution

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 30-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]12/08/08 01:30 PM, ID: 23124465Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]12/08/08 01:33 PM, ID: 23124504Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]12/08/08 01:37 PM, ID: 23124550Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]12/08/08 02:01 PM, ID: 23124786Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]12/08/08 02:04 PM, ID: 23124817Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]12/08/08 02:20 PM, ID: 23124966Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]12/08/08 02:36 PM, ID: 23125101Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]12/08/08 03:31 PM, ID: 23125492Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]12/08/08 03:36 PM, ID: 23125530Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20091021-EE-VQP-81 - Hierarchy / EE_QW_3_20080625