Thank you.

I have used the following solution:
<target name="init">
  <mkdir dir="${build}"/>
  <mkdir dir="${build}/${config}"/>
  <echo file="${build}/${config}/.properties" 
append="false">ant.project.name=${ant.project.name}
ant.project.description=${description}</echo>
</target>


and

    protected final static String propsFile="config/.properties";
    protected final static String projName="ant.project.name";
    protected final static String projDescription="ant.project.description";
    protected Properties props;
    public Properties getProps() { return props; }

        /* properties */
        InputStream 
in=this.getClass().getClassLoader().getResourceAsStream(propsFile);
        if (in!=null) {
            try {
                props=new Properties();
                props.load(in);
            } catch (IOException e) {
                setError(e);
            }
        }

Thank you
Misha

Michael Shea wrote:
> I believe that the question is about accessing this property from a java
> program (compiled to a jar) that was built using ant, rather than from
> an ant build script - however your link, Jan
> (http://ant.apache.org/manual/properties.html#built-in-props ), is still
> relevant.
> 
> Some work needs to be done to accomplish this - it's not just something
> that ant will "do for you" automatically. I think that what should be
> done here is that the "ant.project.name" property should be written into
> the MANIFEST.MF file of the jar (via  ant's jar task), and then
> retrieved at runtime in the java program via 
> java.util.jar.Manifest.getAttributes().
> 
> Relevant links:
> http://ant.apache.org/manual/CoreTasks/jar.html
> http://java.sun.com/j2se/1.5.0/docs/api/java/util/jar/Manifest.html
> <http://ant.apache.org/manual/CoreTasks/jar.html>
> 
> Mike Shea.
> 
> [email protected] wrote:
>> http://ant.apache.org/manual/properties.html#built-in-props
>> ant.project.name    the name of the project that is currently executing;
>>                     it is set in the name attribute of <project>.
>>
>> Jan
>>  
>>
>>  
>>> -----Ursprüngliche Nachricht-----
>>> Von: Misha Koshelev [mailto:[email protected]] Gesendet: Montag, 26.
>>> April 2010 23:26
>>> An: [email protected]
>>> Betreff: Ant project name description passed to Java file during
>>> compilation or Jar process?
>>>
>>> Dear Sirs or Madams:
>>>
>>> I would like to automatically pull the ant project name and/or
>>> description from my java program.
>>>
>>> Is this somehow possible?
>>>
>>> Much help appreciated.
>>>
>>> Specifically, would be great to have this during either
>>> i) javac task
>>> or ii) jar task
>>>
>>> I realize that you can use java -Da=b but when my JAR is deployed,
>>> this seems like it would be lost...
>>>
>>> Thank you
>>> Misha
>>>
>>> p.s. Please reply-all
>>> -- 
>>> Misha Koshelev
>>> MD/PhD Student
>>>
>>> Human Neuroimaging Laboratory
>>> One Baylor Plaza
>>> S104
>>> Baylor College of Medicine
>>> Houston, TX 77030
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: [email protected]
>>> For additional commands, e-mail: [email protected]
>>>
>>>
>>>     
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: [email protected]
>> For additional commands, e-mail: [email protected]
>>
>>
>>   
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to