Java Tutorial/Ant/Properties

Материал из Java эксперт
Перейти к: навигация, поиск

Built in properties

   <source lang="java">

<?xml version="1.0"?> <project name="Apache Ant Properties Project" basedir=".">

 <target name="properties.built-in">
   <echo message="The base directory: ${basedir}"/>      
   <echo message="This file: ${ant.file}"/>
   <echo message="Ant version: ${ant.version}"/> 
   <echo message="Project name: ${ant.project.name}"/>     
   <echo message="Java version: ${ant.java.version}"/>     
 </target>

</project></source>





Define custom properties based on the existing properties

   <source lang="java">

<?xml version="1.0"?> <project name="Apache Ant Properties Project" basedir=".">

 <target name="properties.custom">
   <property name="fs" value="${file.separator}"/>
   <property name="ps" value="${path.separator}"/>
   <echo message="File: ${basedir}${fs}build.xml"/>
   <echo message="Path: ${basedir}${fs}build.xml${ps}${basedir}${fs}build.properties"/>
 </target>

</project></source>





environment properties

   <source lang="java">

<?xml version="1.0"?> <project name="Apache Ant Properties Project" basedir=".">

 <target name="properties">
   <property environment="env"/>
   <echo message="Built on: ${env.OS} ${env.PROCESSOR_ARCHITECTURE}"/>
   <echo message="ANT_HOME: ${env.ant_home}"/>
 </target>

</project></source>





Properties based on build.properties file

   <source lang="java">

<?xml version="1.0"?> <project name="Apache Ant Properties Project" basedir=".">

 <target name="properties">
   <property file="build.properties"/>
   
   <path id="build.classpath.id">
     <pathelement path="${build.classpath}"/>
   </path>
   <property name="build.classpath.property" refid="build.classpath.id"/>
   <echo message="Server URL: ${server.url}"/>
   <echo message="Build classpath: ${build.classpath}"/>
   <echo message="Build classpath converted: ${build.classpath.property}"/>
 </target>

</project> File: build.properties server.name=localhost server.port=8080 server.scheme=http server.manager.name=manager server.url=${server.scheme}://${server.name}:${server.port}/${server.manager.name}/ j2ee.home=C:/j2ee catalina.home=C:/jakarta-tomcat j2ee.jar=${j2ee.home}/lib/j2ee.jar jsp.jar=${catalina.home}/common/lib/jsp-api.jar servlet.jar=${catalina.home}/common/lib/servlet-api.jar mysql.jar=${catalina.home}/common/lib/mysql.jar build.classpath=${mysql.jar};${j2ee.jar};${jsp.jar};${servlet.jar}</source>





Reference defined properties

   <source lang="java">

<?xml version="1.0"?> <project name="Apache Ant Properties Project" basedir=".">

 <target name="properties.custom">
   <property name="project.dtd" location="project.dtd"/>
   <echo message="Location of project.dtd: ${project.dtd}"/>
 </target>

</project></source>