ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Misha Koshelev <misha...@gmail.com>
Subject Re: AW: Ant project name description passed to Java file during compilation or Jar process?
Date Tue, 27 Apr 2010 17:59:17 GMT
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.
> 
> Jan.Materne@rzf.fin-nrw.de 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:mk144210@bcm.edu] Gesendet: Montag, 26.
>>> April 2010 23:26
>>> An: user@ant.apache.org
>>> 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: user-unsubscribe@ant.apache.org
>>> For additional commands, e-mail: user-help@ant.apache.org
>>>
>>>
>>>     
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
>> For additional commands, e-mail: user-help@ant.apache.org
>>
>>
>>   
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Mime
View raw message