怎么在ant中调用javascript

2024-12-28 09:16:35
推荐回答(1个)
回答1:

有两种方法, 一个是用java写自定义的ant task来解密传给ant script的密码. 然后用明文密码来连接数据库. 写java的缺点在于每次都要事先编译好这个ant task. 还有一种方法是在ant script写一个javascript task. 当然javascript可以调用java的解密函数, 这样不用每次运行ant script前都编译task. 具体脚本如下:

  

输出

05/25/12 18:46:55.406 INFO: [ProcessWrapper] Executing: D:\build\fabric\DSEngine\resources\win32\wrappid.exe,D:\build\fabric\DSEngine\work\yangxiaoming-lt-1\antcall.pid,D:/build/fabric/DSEngine/work/yangxiaoming-lt-1/tibcoamx/tibcojre/1.6.0/bin/java,-cp,D:/build/fabric/DSEngine/work/yangxiaoming-lt-1/tibcoamx/tools/lib/antpackage.jar,org.apache.tools.ant.launch.Launcher,-f,D:\build\fabric\DSEngine\work\yangxiaoming-lt-1\scripts\cleanupDDL\cleanupDB.xml,-Dadmin.db.password=#!Panbl6s1FhkBUM70G9T+okR+fv5Nwoq+fYUx+SLzZi8=,-Dadmin.db.url=jdbc:sqlserver://192.168.71.99:1433;databasename=amxdb,-Dadmin.db.username=sa,-Ddb.ddl.path=mssql300,-Ddb.driver.path=D:\build\fabric\DSEngine\work\yangxiaoming-lt-1/fabric/mssql2008_driver,-Dtibco.home=D:/build/fabric/DSEngine/work/yangxiaoming-lt-1/tibcoamx,-Dadmin.db.driver=com.microsoft.sqlserver.jdbc.SQLServerDriver,cleanup.db.logging,
05/25/12 18:46:55.609 INFO: [ProcessWrapper] [STDOUT] Buildfile: D:\build\fabric\DSEngine\work\yangxiaoming-lt-1\scripts\cleanupDDL\cleanupDB.xml
05/25/12 18:46:55.875 INFO: [ProcessWrapper] [STDOUT]
05/25/12 18:46:55.875 INFO: [ProcessWrapper] [STDOUT] replace.db.password:
05/25/12 18:46:55.984 INFO: [ProcessWrapper] [STDOUT] [script] log4j:WARN No appenders could be found for logger (com.tibco.security.TIBCOSecurity).
05/25/12 18:46:55.984 INFO: [ProcessWrapper] [STDOUT] [script] log4j:WARN Please initialize the log4j system properly.
05/25/12 18:46:56.500 INFO: [ProcessWrapper] [STDOUT] [echo] Tibc02008
05/25/12 18:46:56.500 INFO: [ProcessWrapper] [STDOUT]
05/25/12 18:46:56.500 INFO: [ProcessWrapper] [STDOUT] cleanup.db.logging:
05/25/12 18:46:56.687 INFO: [ProcessWrapper] [STDOUT] [sql] Executing resource: D:\build\fabric\DSEngine\work\yangxiaoming-lt-1\scripts\cleanupDDL\mssql300\drop_commonlogging.ddl
05/25/12 18:46:56.687 INFO: [ProcessWrapper] [STDOUT] [sql] 0 rows affected
05/25/12 18:46:56.687 INFO: [ProcessWrapper] [STDOUT] [sql] 1 of 1 SQL statements executed successfully
05/25/12 18:46:56.703 INFO: [ProcessWrapper] [STDOUT]
05/25/12 18:46:56.703 INFO: [ProcessWrapper] [STDOUT] BUILD SUCCESSFUL
05/25/12 18:46:56.703 INFO: [ProcessWrapper] [STDOUT] Total time: 1 second

在ant中使用javascript, 在javascript又调用了java, 所以一定要注意数据的boxing和unboxing. 比如用java的方法返回decryptedPassword 时, 它其实已经被unboxing了, 失去了java的char[]类型, 但内在传递的值是不变的, 所以需要对它重新boxing, 让它成为java的String类型, 在boxing他的char[]值同时解码, 获得实际字符串, 也就是明文. 再将它传递给javascript的变量.