Start the Oracle database with two operations:
1. Start the listener:
<Exec executable = "LSNRCTL">
<Arg line = "start"/>
</Exec>
2. open a database instance:
the first operation is no different here, it is the standard usage of ant to call system commands. Let's take a look at the second command, Net start oracleservice $ {ora_sid}. If you put it directly into the executable attribute, the execution result will certainly be:
build failed: e: \ Java \ testant \ build. XML: 44: Execute failed: Java. io. ioexception: CreateProcess: "Net start oracleservicemy_oracle" error = 2
pain point: Use the following method for a command with spaces:
You can use tstamp target to easily define date attributes:
<Tstamp>
<Format property = "db_backup_time" pattern = "yyyy-mm-dd"/>
</Tstamp>
Appendix: Reference script
<! -- 2005 by guipei. -->
<Project name = "testantoracle" default = "Demo" basedir = "./">
<! -- Set global properties for this build -->
<Property name = "db_backup_dir" value = "."/>
<Property name = "ora_sid" value = "my_oracle"/>
<Property name = "ora_user" value = "Scott"/>
<Property name = "ora_pwd" value = "tiger"/>
<Property name = "ora_restore_file" value = "db_back.dmp"/>
<Target name = "Demo">
<Echo> ant db_backup to backup dB </echo>
<Echo> ant db_restore to restore dB </echo>
<Echo> ant db_start to start dB </echo>
<Echo> ant db_stop to stop dB </echo>
</Target>
<Target name = "db_backup">
<Tstamp>
<Format property = "db_backup_time" pattern = "yyyy-mm-dd"/>
</Tstamp>
<Property name = "db_backup_file" value = "mydb _ $ {db_backup_time}. dmp"/>
<Echo> will backup dB at $ {db_backup_file} </echo>
<Exec dir = "$ {db_backup_dir}" executable = "exp">
<Arg line = "$ {ora_user}/$ {ora_pwd }@$ {ora_sid} file = mydb _ $ {db_backup_time}. dmp"/>
</Exec>
</Target>
<Target name = "db_restore">
<Exec dir = "$ {db_backup_dir}" executable = "Imp">
<Arg line = "$ {ora_user}/$ {ora_pwd }@$ {ora_sid} file =$ {ora_restore_file} full = y"/>
</Exec>
</Target>
<Target name = "db_start">
<Exec executable = "LSNRCTL">
<Arg line = "start"/>
</Exec>
<Exec executable = 'cmd'>
<Arg line = "/C Net start oracleservice $ {ora_sid}"/>
</Exec>
</Target>
<Target name = "db_stop">
<Exec executable = "LSNRCTL">
<Arg line = "stop"/>
</Exec>
<Exec executable = 'cmd'>
<Arg line = "/C net stop oracleservice $ {ora_sid}"/>
</Exec>
</Target>
</Project>