2016-10-28 12 views
0

私はアリスクリプトの初心者です。私はどのようなアイデアはありません、どのようにXMLファイルにAntスクリプトを使って記述しますか?antスクリプトを使用してxmlファイルに書き込む方法は?

私はTomcatcontext.xmlファイルにデータベース情報を書きたいです。 私はantスクリプトを書いて、ユーザーからデータベース情報を読みました。 は、私は今、私はcontext.xmlファイルに上記の情報を書き込むことができますどのようにこれらのプロパティ

{jdbc.myDatabase.driver} 
{jdbc.myDatabase.url} 
{jdbc.myDatabase.user} 
{jdbc.myDatabase.password} 

に店舗すべての必要な情報を持っています。 Context.xmlファイルは次のようになります。

<?xml version='1.0' encoding='utf-8'?> 
<Context> 
    <WatchedResource>WEB-INF/web.xml</WatchedResource> 
    <WatchedResource>${catalina.base}/conf/web.xml</WatchedResource> 
</Context> 

db情報を書き込んだ後は、次のようになります。

新しいファイルのcontext.xmlには、次のようになります。

<?xml version='1.0' encoding='utf-8'?> 
<Context> 
    <WatchedResource>WEB-INF/web.xml</WatchedResource> 
    <WatchedResource>${catalina.base}/conf/web.xml</WatchedResource> 

    <Resource name="jdbc/monitords" 
       auth="Container" 
       type="javax.sql.DataSource" 
       factory="org.apache.tomcat.jdbc.pool.DataSourceFactory" 
       driverClassName="oracle.jdbc.OracleDriver" 
       url="jdbc:oracle:thin:@192.168.15.194:1521:orcl" 
       username="tomcat_dbrds" 
       password="cmxinfa" 
       jdbcInterceptors="org.apache.tomcat.jdbc.pool.interceptor.ConnectionState;org.apache.tomcat.jdbc.pool.interceptor.StatementFinalizer;org.apache.tomcat.jdbc.pool.interceptor.SlowQueryReport(threshold=1500)" 
      /> 
</Context> 

私は任意の提案、有用なリンクをありがとうと思います。助けてください。

アップデート1:を追加しましたbild.xmlファイル

<project name="TestWebApp" default="collect-user-inputs" basedir="." xmlns:contrib="antlib:net.sf.antcontrib"> 
 
\t <!-- set global properties for this build --> 
 
\t <property name="resourcedir" location="resource"/> 
 
\t <property name ="tomcatServer" location ="apache-tomcat-server"/> 
 
\t <property name ="context_xml" location ="${tomcatServer}/conf"/> 
 
\t <property name="build" location="build"/> 
 
\t <property name="temp" location="_tmp"/> 
 
\t <property name="lib" location ="lib"/> 
 
\t <property name="installdir" location="install"/> 
 
\t <property name="outputdir" location="output"/> 
 
\t <property name="build.props" value="build.properties"/> 
 
\t <property name="ui.log4j.props" value="log4j.properties"/> 
 
\t <property name="dependencyfinder.home" value="."/> 
 
\t <property name="log.path" value=""/> 
 
\t 
 

 
\t 
 
\t <!-- Collects all the required inputs from the User --> 
 
\t <target name="collect-user-inputs" unless="${build.props.exists}"> 
 
\t \t <property name="jdbc.WebApp.driver" value="oracle.jdbc.driver.OracleDriver"/> 
 
     <input message="Enter hostname/IP for TestWebApp database" addproperty="jdbc.WebApp.url.host" defaultvalue="localhost"/> 
 
     <input message="Enter the port number for database server where TestWebApp schema was created" addproperty="jdbc.WebApp.url.port" defaultvalue="1521"/> 
 
\t <input message="Select Connection type for TestWebApp schema (1) SID, (2) Service Name" addproperty="jdbc.WebApp.conn.type" defaultvalue="SID" validargs="1,2"/> 
 
\t <contrib:if> 
 
\t \t \t <contrib:equals arg1="${jdbc.WebApp.conn.type}" arg2="1"/> 
 
\t \t \t <contrib:then> 
 
\t \t \t \t <property name="jdbc.WebApp.conn.type.name" value="SID"/> 
 
\t \t \t </contrib:then> \t \t \t 
 
\t \t \t <contrib:elseif> 
 
\t \t \t \t <contrib:equals arg1="${jdbc.WebApp.conn.type}" arg2="2"/> 
 
\t \t \t \t \t <contrib:then> 
 
\t \t \t \t \t \t <property name="jdbc.WebApp.conn.type.name" value="Service Name"/> 
 
\t \t \t \t \t </contrib:then> 
 
\t \t \t </contrib:elseif> \t \t \t 
 
\t \t </contrib:if> 
 
\t  
 
     <input message="Enter ${jdbc.WebApp.conn.type.name} for database server where TestWebApp schema was created" addproperty="jdbc.WebApp.url.sid" defaultvalue="orcl"/> 
 
     \t 
 
\t <contrib:if> 
 
\t \t \t <contrib:equals arg1="${jdbc.WebApp.conn.type}" arg2="1"/> 
 
\t \t \t <contrib:then> 
 
\t \t \t \t <contrib:var name="jdbc.WebApp.url" value="jdbc:oracle:thin:@${jdbc.WebApp.url.host}:${jdbc.WebApp.url.port}:${jdbc.WebApp.url.sid}"/> 
 
\t \t \t \t <echo message="WebApp jdbc.WebApp.url : ${jdbc.WebApp.url}" /> 
 
\t \t \t </contrib:then> \t \t \t 
 
\t \t \t <contrib:elseif> 
 
\t \t \t \t <contrib:equals arg1="${jdbc.WebApp.conn.type}" arg2="2"/> 
 
\t \t \t \t \t <contrib:then> 
 
\t \t \t \t \t \t <contrib:var name="jdbc.WebApp.url" value="jdbc:oracle:thin:@${jdbc.WebApp.url.host}:${jdbc.WebApp.url.port}/${jdbc.WebApp.url.sid}"/> 
 
\t \t \t \t \t \t <echo message="WebApp jdbc.WebApp.url : ${jdbc.WebApp.url}" /> 
 
\t \t \t \t \t </contrib:then> 
 
\t \t \t </contrib:elseif> \t \t \t 
 
\t \t </contrib:if> \t 
 

 
\t \t <input message="Enter TestWebApp database username" addproperty="jdbc.WebApp.user" defaultvalue=" _Monitor"/> 
 
\t \t <input message="Enter password for ${jdbc.WebApp.user}${line.separator}" addproperty="jdbc.WebApp.password"> 
 
\t \t \t <handler classname="org.apache.tools.ant.input.SecureInputHandler"/> 
 
\t \t </input> 
 

 
\t \t <echo message="Getting ORS name from ${jdbc.WebApp.user}@${jdbc.WebApp.url.host}:${jdbc.WebApp.url.port}/${jdbc.WebApp.url.sid}..."/> 
 
\t \t <tempfile property="temp.properties" prefix="temp_" suffix=".properties"/> 
 

 
\t \t <property file="${temp.properties}"/> 
 
\t \t <delete file="${temp.properties}"/> 
 
\t \t <condition property="schema_user_set" else="false"> 
 
\t \t \t <isset property="${jdbc.hub.user}"/> 
 
\t \t </condition> 
 
\t \t 
 
\t \t 
 
\t \t <condition property="isORSSchemaSet"> 
 
      <not> 
 
       <equals arg1="${jdbc.hub.user}" arg2="" trim="true"/> 
 
      </not> 
 
     </condition> 
 
\t \t <antcall target="failed_getting_ors_schema"/> \t 
 
\t \t 
 
\t \t 
 
\t \t <property name="jdbc.hub.driver" value="oracle.jdbc.driver.OracleDriver"/> 
 
     <input message="Enter hostname/IP ${jdbc.hub.user}" addproperty="jdbc.hub.url.host" defaultvalue="localhost"/> 
 
     <input message="Enter the port number of Database server ${jdbc.hub.user} is created " addproperty="jdbc.hub.url.port" defaultvalue="1521"/> 
 
\t <input message="Select Connection type for Database (1) SID (2) Service Name" addproperty="jdbc.hub.conn.type" defaultvalue="SID" validargs="1,2"/> 
 
\t <contrib:if> 
 
\t \t \t <contrib:equals arg1="${jdbc.hub.conn.type}" arg2="1"/> 
 
\t \t \t <contrib:then> 
 
\t \t \t \t <property name="jdbc.hub.conn.type.name" value="SID"/> 
 
\t \t \t </contrib:then> \t \t \t 
 
\t \t \t <contrib:elseif> 
 
\t \t \t \t <contrib:equals arg1="${jdbc.hub.conn.type}" arg2="2"/> 
 
\t \t \t \t \t <contrib:then> 
 
\t \t \t \t \t \t <property name="jdbc.hub.conn.type.name" value="Service Name"/> 
 
\t \t \t \t \t </contrib:then> 
 
\t \t \t </contrib:elseif> \t \t \t 
 
\t \t </contrib:if> 
 
     <input message="Enter the ${jdbc.hub.conn.type.name} of the database where ORS ${jdbc.hub.user} is created" addproperty="jdbc.hub.url.sid" defaultvalue="orcl"/> 
 
\t 
 
\t <contrib:if> 
 
\t \t \t <contrib:equals arg1="${jdbc.hub.conn.type}" arg2="1"/> 
 
\t \t \t <contrib:then> 
 
\t \t \t \t <contrib:var name="jdbc.hub.url" value="jdbc:oracle:thin:@${jdbc.hub.url.host}:${jdbc.hub.url.port}:${jdbc.hub.url.sid}"/> 
 
\t \t \t </contrib:then> \t \t \t 
 
\t \t \t <contrib:elseif> 
 
\t \t \t \t <contrib:equals arg1="${jdbc.hub.conn.type}" arg2="2"/> 
 
\t \t \t \t \t <contrib:then> 
 
\t \t \t \t \t \t <contrib:var name="jdbc.hub.url" value="jdbc:oracle:thin:@${jdbc.hub.url.host}:${jdbc.hub.url.port}/${jdbc.hub.url.sid}"/> 
 
\t \t \t \t \t </contrib:then> 
 
\t \t \t </contrib:elseif> \t \t \t 
 
\t \t </contrib:if>  
 
\t \t <!--<input message="Enter password for ${jdbc.hub.user}${line.separator}" addproperty="jdbc.hub.password"> 
 
\t \t \t <handler classname="org.apache.tools.ant.input.SecureInputHandler"/> 
 
\t \t </input> --> 
 
\t \t 
 
\t \t <property name="jdbc.hub.url" value="jdbc:oracle:thin:@${jdbc.hub.url.host}:${jdbc.hub.url.port}/${jdbc.hub.url.sid}"/> 
 
\t \t <input message="Enter License Key" addproperty="WebApp.license"/> 
 

 
\t \t 
 
\t \t <antcall target="tomcat-server-xml"/> 
 
\t \t 
 
\t </target> 
 
\t 
 

 
\t \t <target name="tomcat-server-xml"> 
 
\t 
 
\t \t <echo message ="tomcat-server-xml is called"/> 
 
\t \t <xmltask source="${context_xml}/context.xml" dest="${context_xml}/context.xml"> 
 
\t \t \t <replace path="//*[local-name()='url']/text()" withText="${jdbc.WebApp.url}"/> 
 
\t \t \t <replace path="//*[local-name()='username']/text()" withText="${jdbc.WebApp.user}"/> 
 
\t \t \t <replace path="//*[local-name()='password']/text()" withText="${jdbc.WebApp.password}"/> 
 
\t \t </xmltask> 
 
\t </target> 
 
\t 
 
\t 
 
\t 
 
\t 
 
</project>

+0

あなたは、プロパティの形式で値を得たのですか?そして 'context.xml'ファイルを更新したいのですか? – Rao

+0

@Rao:いいえ、私はプロパティファイルから値を取得しません。私はbuild.xmlファイルを持っていると私はユーザーからの値を読み取り、私はそれらのすべての値をXMLプロパティタグに設定します。あなたがbuild.xmlファイルをアップロードすることを私に尋ねるならば。 – Varun

+0

できれば助けになるでしょう。 – Rao

答えて

1

あなたのcontext.xmlのテンプレートを作成します。

<?xml version='1.0' encoding='utf-8'?> 
<Context> 
    <WatchedResource>WEB-INF/web.xml</WatchedResource> 
    <WatchedResource>${catalina.base}/conf/web.xml</WatchedResource> 

    <Resource name="jdbc/monitords" 
       auth="Container" 
       type="javax.sql.DataSource" 
        factory="org.apache.tomcat.jdbc.pool.DataSourceFactory" 
       driverClassName="${jdbc.myDatabase.driver}" 
       url="${jdbc.myDatabase.url}" 
       username="${jdbc.myDatabase.user}" 
       password="${jdbc.myDatabase.password}" 
       jdbcInterceptors="org.apache.tomcat.jdbc.pool.interceptor.ConnectionSta te;org.apache.tomcat.jdbc.pool.interceptor.StatementFinalizer;org.apach e.tomcat.jdbc.pool.interceptor.SlowQueryReport(threshold=1500)" 
      /> 
</Context> 

をし、その後に次のターゲットを使用しますそれに基づいて実際のcontext.xmlを生成します:

<target name="generate.context"> 

    <!-- Properties (might be defined elsewhere) --> 
    <property name="jdbc.myDatabase.driver" value="oracle.jdbc.OracleDriver"/> 
    <property name="jdbc.myDatabase.url" value="jdbc:oracle:thin:@192.168.15.194:1521:orcl"/> 
    <property name="jdbc.myDatabase.user" value="tomcat_dbrds"/> 
    <property name="jdbc.myDatabase.password" value="cmxinfa"/> 

    <!-- Copy context.xml.template to context.xml, expanding the properties in the process --> 
    <copy file="context.xml.template" tofile="context.xml"> 
     <filterchain> 
      <filterreader classname="org.apache.tools.ant.filters.ExpandProperties"/> 
     </filterchain> 
    </copy> 

</target> 
関連する問題