锘??xml version="1.0" encoding="utf-8" standalone="yes"?>MyISAM
鏄粯璁ゅ瓨鍌ㄦ柟寮忥紝浣嗘槸涓嶆敮鎸佷簨鍔★紝鎵浠ュ鑷翠簡鎴戠殑闂錛屽彧瑕佹妸榛樿璁劇疆鎴?code class="literal">default-storage-engine=innodb灝卞彲浠ヤ簡錛屽綋鐒朵篃鍙互鍦ㄦ瘡涓猼able鍒涘緩鐨勬椂鍊欐寚瀹氥?br />甯屾湜瀵圭鍒版綾婚棶棰樼殑鏈嬪弸鏈夋墍甯姪銆?br />
]]>
聽聽聽
榪欐牱灝卞紩鍏ヤ簡涓涓寖鍥寸殑姒傚康,"鏌愪釜鍔ㄤ綔"鏄綔鐢ㄥ湪涓瀹氳寖鍥村唴鐨?榪欎釜鑼冨洿灝變笉浠呬粎鏄摢浜涘璞′簡,涔熷彲鑳芥槸鏃墮棿鑼冨洿,姣斿鍒犻櫎鍑犲ぉ鍓嶇殑鏃ュ織淇℃伅.鍒拌繖閲屽
浠誨姟鐨勫畾涔夋湁鎵鏀瑰彉浜?涓涓換鍔″寘鎷竴浜涜寖鍥翠篃鍙互璇存槸鏉′歡,榪欎釜鏉′歡涓嶅寘鎷Е鍙戠偣榪欎釜鏉′歡),涓涓姩浣?鎵浠ョ郴緇熶腑瀹氫箟浜嗕竴涓狪Range鎺ュ彛,鑼冨洿鐨?
琛ㄧず閮戒繚瀛樺湪涓涓猉ML瀛楃涓?XML瀛楃涓茬殑緇撴瀯鍜屾庝箞瑙f瀽閮戒氦緇欏叿浣撶殑瀛愬璞?榪欐牱灝辯粰浜嗗瓙綾葷殑鐏墊椿鎬?
public interface IRange {
聽聽聽 public Map saveToMap(String strMap);//淇濆瓨鑼冨洿鍙傛暟
聽聽聽 public List getResult(Map map);//瑙f瀽鑼冨洿鍙傛暟,騫惰繑鍥炴搷浣滃璞$嚎紼嬪垪琛?br />
聽聽聽 public List getViewInfo();鍙栧緱欏甸潰琛ㄧず鏂瑰紡,緇撳悎浜唚ebwork
}
涓涓換鍔″搴斾竴涓狪Range鐨勫瓙綾?IRange鐨勫瓙綾誨浠誨姟鐨勫悇縐嶅弬鏁拌寖鍥?鍔ㄤ綔榪涜浜嗗疄鐜?鎺ョ潃榪樺姞鍏ヤ竴涓狪RangeManager鎺ュ彛,
public interface IRangeManager {
聽聽聽 public void saveDataMap(Long jobId, String strMap)throws SchedulerException;//淇濆瓨鑼冨洿鍙傛暟
聽聽聽 public List getObjects(Map map);//鍙栧緱瀵硅薄鍒楄〃,鍏朵腑鍖呮嫭浜嗗鍙傛暟鐨勮В鏋?br />
聽聽聽 public List getViews(Map map);
}
聽聽聽 瀹炵幇鐨勫姛鑳芥槸瀵硅寖鍥磋繘琛岀鐞?鍖呮嫭瀵筈uartz鐨勬搷浣?涓昏涓浜涗繚瀛樻暟鎹簱絳夌殑鎿嶄綔,榪欐牱瀵逛簬澧炲姞涓涓柊鐨凴ange瀛愮被灝卞彲浠ヤ笉鐢ㄧ煡閬換uartz浜?
聽聽聽 榪欐牱鍥犱負寰堝涓滆タ閮芥槸鍙厤緗殑,澧炲姞浜嗙伒媧繪?瀵逛互鍚庝換鍔$殑娣誨姞瀹氫箟浜嗕竴浜涙帴鍙?鑰冭檻鍒頒簡鎵╁睍鎬?鍦ㄨ璁¤繖涓ā鍧楃殑鏃跺?鎬葷殑鎬濊礬鏄妸閭d簺涓嶅彉鐨勪笢瑗塊兘灝佽璧鋒潵,鎶婅兘鍙樺緱涓滆タ閮戒氦緇欏叿浣撶殑浠誨姟浜?
涓婇潰鎴戝彧鏄ぇ鑷磋浜嗕竴涓?鐢變簬姘村鉤鏈夐檺,鍙兘璁茬殑涓嶆槸娓呮,姣旇緝涔?鎴戞病鏈夋彁渚涘叿浣撶殑渚嬪瓙,鍙槸鎻愪緵浜嗕竴涓濊礬,甯屾湜瀵瑰ぇ瀹舵湁鎵甯姪,鎴栬呬綘榪樻湁鏇村ソ鐨勮璁?璇蜂笌鎴戣仈緋?
]]>
鎺ヤ笅鏉ョ殑闂鏄棦鐒惰緇撳悎,閭d箞璁㏎uartz鏉ユ彁渚涜繛鎺ユ睜閰嶇疆鍛㈣繕鏄湁Hibernate鎻愪緵.鐮旂┒浜嗕袱鑰呯殑榪炴帴姹犳柟闈㈢殑婧愪唬鐮?鍙戠幇
Hibernate鐨勮繛鎺ユ睜璁捐榪滆繙濂戒簬Quartz,Quartz鐩墠鍙彁渚涗竴涓繛鎺ユ睜鎻愪緵綾籔oolingConnectionProvider,鑰?
涓斾嬌鐢ㄧ殑榪炴帴姹犳槸dbcp,榪欎釜榪炴帴姹犲惉璇撮棶棰樺澶?鐩稿弽hibernate鎻愪緵浜嗘洿鍔犵伒媧葷殑閰嶇疆,鎵浠ヨ繛鎺ユ睜鐢盚ibernate鎻愪緵.
聽聽聽 棣栧厛瀹炵幇涓涓猀uartz涓瑿onnectionProvider瀛愮被HibernateConnectionProvider
public class HibernateConnectionProvider implements ConnectionProvider {
聽聽聽 private Connection con = null;
聽聽聽 protected static ThreadLocal hibernateHolder = new ThreadLocal();
聽聽聽 public Connection getConnection() throws SQLException {
聽聽聽 聽聽聽 con = null;
聽聽聽 聽聽聽 SessionFactoryImpl sessionFactory = null;
聽聽聽 聽聽聽 sessionFactory = (SessionFactoryImpl) Global.getSessionFacotry();
聽聽聽 聽聽聽 con = sessionFactory.getConnectionProvider().getConnection();
聽聽聽 return con;
}
public void shutdown() throws SQLException {
聽聽聽 // FIXME Auto-generated method stub
}
}
,鐒跺悗淇敼StdSchedulerFactory,鍦ㄤ笉鐮村潖鍏舵湰鏉ョ殑閫昏緫鍜屽彲閰嶇疆鎬т笅榪涜浜嗙浉搴旂殑淇敼.淇敼鐨勬槸private Scheduler
instantiate() throws SchedulerException鏂規硶,鎵懼埌//Set up any
DataSources孌佃繘琛屼慨鏀?浠g爜濡備笅:
String[] dsNames = cfg.getPropertyGroups(PROP_DATASOURCE_PREFIX);
聽聽聽 聽聽聽 for (int i = 0; i < dsNames.length; i++) {
聽聽聽 聽聽聽 聽聽聽 PropertiesParser pp = new PropertiesParser(cfg.getPropertyGroup(
聽聽聽 聽聽聽 聽聽聽
聽聽聽 聽聽聽 PROP_DATASOURCE_PREFIX + "." +
dsNames[i], true));
聽聽聽 聽聽聽 聽聽聽 String dsDriver = pp
聽聽聽 聽聽聽 聽聽聽
聽聽聽 聽聽聽
.getStringProperty(PROP_DATASOURCE_DRIVER, null);
聽聽聽 聽聽聽 聽聽聽 String dsURL = pp.getStringProperty(PROP_DATASOURCE_URL, null);
聽聽聽 聽聽聽 聽聽聽 boolean dsAlwaysLookup = pp.getBooleanProperty(
聽聽聽 聽聽聽 聽聽聽
聽聽聽 聽聽聽
PROP_DATASOURCE_JNDI_ALWAYS_LOOKUP, false);
聽聽聽 聽聽聽 聽聽聽 String dsUser = pp.getStringProperty(PROP_DATASOURCE_USER, "");
聽聽聽 聽聽聽 聽聽聽 String dsPass = pp.getStringProperty(PROP_DATASOURCE_PASSWORD, "");
聽聽聽 聽聽聽 聽聽聽 int dsCnt = pp.getIntProperty(PROP_DATASOURCE_MAX_CONNECTIONS, 3);
聽聽聽 聽聽聽 聽聽聽 String providerClass = pp.getStringProperty(
聽聽聽 聽聽聽 聽聽聽
聽聽聽 聽聽聽 PROP_DATASOURCE_PROVIDER_CLASS,
null);
聽聽聽 聽聽聽 聽聽聽 String dsJndi = pp
聽聽聽 聽聽聽 聽聽聽
聽聽聽 聽聽聽
.getStringProperty(PROP_DATASOURCE_JNDI_URL, null);
聽聽聽 聽聽聽 聽聽聽 String dsJndiInitial = pp.getStringProperty(
聽聽聽 聽聽聽 聽聽聽
聽聽聽 聽聽聽 PROP_DATASOURCE_JNDI_INITIAL,
null);
聽聽聽 聽聽聽 聽聽聽 String dsJndiProvider = pp.getStringProperty(
聽聽聽 聽聽聽 聽聽聽
聽聽聽 聽聽聽 PROP_DATASOURCE_JNDI_PROVDER,
null);
聽聽聽 聽聽聽 聽聽聽 String dsJndiPrincipal = pp.getStringProperty(
聽聽聽 聽聽聽 聽聽聽
聽聽聽 聽聽聽 PROP_DATASOURCE_JNDI_PRINCIPAL,
null);
聽聽聽 聽聽聽 聽聽聽 String dsJndiCredentials = pp.getStringProperty(
聽聽聽 聽聽聽 聽聽聽
聽聽聽 聽聽聽 PROP_DATASOURCE_JNDI_CREDENTIALS,
null);
聽聽聽 聽聽聽 聽聽聽 String dsValidation = pp.getStringProperty(
聽聽聽 聽聽聽 聽聽聽
聽聽聽 聽聽聽 PROP_DATASOURCE_VALIDATION_QUERY,
null);
聽聽聽 聽聽聽 聽聽聽 if (providerClass == null
聽聽聽 聽聽聽 聽聽聽 聽聽聽 聽聽聽 || providerClass.equals("")
聽聽聽 聽聽聽 聽聽聽 聽聽聽 聽聽聽 || providerClass
聽聽聽 聽聽聽 聽聽聽
聽聽聽 聽聽聽 聽聽聽
聽聽聽
.equals("org.quartz.utils.PoolingConnectionProvider")) {
聽聽聽 聽聽聽 聽聽聽 聽聽聽 if (dsDriver == null) {
聽聽聽 聽聽聽 聽聽聽
聽聽聽 聽聽聽 initException = new
SchedulerException(
聽聽聽 聽聽聽 聽聽聽
聽聽聽 聽聽聽 聽聽聽
聽聽聽 "Driver not specified for DataSource: "
聽聽聽 聽聽聽 聽聽聽
聽聽聽 聽聽聽 聽聽聽
聽聽聽 聽聽聽 聽聽聽 + dsNames[i]);
聽聽聽 聽聽聽 聽聽聽 聽聽聽 聽聽聽 throw initException;
聽聽聽 聽聽聽 聽聽聽 聽聽聽 }
聽聽聽 聽聽聽 聽聽聽 聽聽聽 if (dsURL == null) {
聽聽聽 聽聽聽 聽聽聽
聽聽聽 聽聽聽 initException = new
SchedulerException(
聽聽聽 聽聽聽 聽聽聽
聽聽聽 聽聽聽 聽聽聽
聽聽聽 "DB URL not specified for DataSource: "
聽聽聽 聽聽聽 聽聽聽
聽聽聽 聽聽聽 聽聽聽
聽聽聽 聽聽聽 聽聽聽 + dsNames[i]);
聽聽聽 聽聽聽 聽聽聽 聽聽聽 聽聽聽 throw initException;
聽聽聽 聽聽聽 聽聽聽 聽聽聽 }
聽聽聽 聽聽聽 聽聽聽 聽聽聽 try {
聽聽聽 聽聽聽 聽聽聽
聽聽聽 聽聽聽 PoolingConnectionProvider cp =
new PoolingConnectionProvider(
聽聽聽 聽聽聽 聽聽聽
聽聽聽 聽聽聽 聽聽聽
聽聽聽 dsDriver, dsURL, dsUser, dsPass, dsCnt,
聽聽聽 聽聽聽 聽聽聽
聽聽聽 聽聽聽 聽聽聽
聽聽聽 dsValidation);
聽聽聽 聽聽聽 聽聽聽
聽聽聽 聽聽聽 dbMgr =
DBConnectionManager.getInstance();
聽聽聽 聽聽聽 聽聽聽
聽聽聽 聽聽聽
dbMgr.addConnectionProvider(dsNames[i], cp);
聽聽聽 聽聽聽 聽聽聽 聽聽聽 } catch (SQLException sqle) {
聽聽聽 聽聽聽 聽聽聽
聽聽聽 聽聽聽 initException = new
SchedulerException(
聽聽聽 聽聽聽 聽聽聽
聽聽聽 聽聽聽 聽聽聽
聽聽聽 "Could not initialize DataSource: " + dsNames[i],
聽聽聽 聽聽聽 聽聽聽
聽聽聽 聽聽聽 聽聽聽
聽聽聽 sqle);
聽聽聽 聽聽聽 聽聽聽 聽聽聽 聽聽聽 throw initException;
聽聽聽 聽聽聽 聽聽聽 聽聽聽 }
聽聽聽 聽聽聽 聽聽聽 } else if (providerClass
聽聽聽 聽聽聽 聽聽聽
聽聽聽 聽聽聽
.equals("org.quartz.utils.JNDIConnectionProvider")) {
聽聽聽 聽聽聽 聽聽聽 聽聽聽 Properties props = null;
聽聽聽 聽聽聽 聽聽聽 聽聽聽 if (null != dsJndiInitial || null != dsJndiProvider
聽聽聽 聽聽聽 聽聽聽
聽聽聽 聽聽聽 聽聽聽 || null !=
dsJndiPrincipal || null != dsJndiCredentials) {
聽聽聽 聽聽聽 聽聽聽 聽聽聽 聽聽聽 props = new Properties();
聽聽聽 聽聽聽 聽聽聽 聽聽聽 聽聽聽 if (dsJndiInitial != null)
聽聽聽 聽聽聽 聽聽聽
聽聽聽 聽聽聽 聽聽聽
props.put(PROP_DATASOURCE_JNDI_INITIAL, dsJndiInitial);
聽聽聽 聽聽聽 聽聽聽 聽聽聽 聽聽聽 if (dsJndiProvider != null)
聽聽聽 聽聽聽 聽聽聽
聽聽聽 聽聽聽 聽聽聽
props.put(PROP_DATASOURCE_JNDI_PROVDER, dsJndiProvider);
聽聽聽 聽聽聽 聽聽聽 聽聽聽 聽聽聽 if (dsJndiPrincipal != null)
聽聽聽 聽聽聽 聽聽聽
聽聽聽 聽聽聽 聽聽聽
props.put(PROP_DATASOURCE_JNDI_PRINCIPAL,
聽聽聽 聽聽聽 聽聽聽
聽聽聽 聽聽聽 聽聽聽
聽聽聽 聽聽聽 dsJndiPrincipal);
聽聽聽 聽聽聽 聽聽聽 聽聽聽 聽聽聽 if (dsJndiCredentials != null)
聽聽聽 聽聽聽 聽聽聽
聽聽聽 聽聽聽 聽聽聽
props.put(PROP_DATASOURCE_JNDI_CREDENTIALS,
聽聽聽 聽聽聽 聽聽聽
聽聽聽 聽聽聽 聽聽聽
聽聽聽 聽聽聽 dsJndiCredentials);
聽聽聽 聽聽聽 聽聽聽 聽聽聽 }
聽聽聽 聽聽聽 聽聽聽
聽聽聽 JNDIConnectionProvider cp = new
JNDIConnectionProvider(dsJndi,
聽聽聽 聽聽聽 聽聽聽
聽聽聽 聽聽聽 聽聽聽 props,
dsAlwaysLookup);
聽聽聽 聽聽聽 聽聽聽 聽聽聽 dbMgr = DBConnectionManager.getInstance();
聽聽聽 聽聽聽 聽聽聽 聽聽聽 dbMgr.addConnectionProvider(dsNames[i], cp);
聽聽聽 聽聽聽 聽聽聽 } else if (providerClass
聽聽聽 聽聽聽 聽聽聽
聽聽聽 聽聽聽
.equals("org.quartz.utils.HibernateConnectionProvider")) {
聽聽聽 聽聽聽 聽聽聽
聽聽聽 HibernateConnectionProvider cp = new
HibernateConnectionProvider();
聽聽聽 聽聽聽 聽聽聽 聽聽聽 dbMgr = DBConnectionManager.getInstance();
聽聽聽 聽聽聽 聽聽聽 聽聽聽 dbMgr.addConnectionProvider(dsNames[i], cp);
聽聽聽 聽聽聽 聽聽聽 } else {
聽聽聽 聽聽聽 聽聽聽 聽聽聽 initException = new SchedulerException(
聽聽聽 聽聽聽 聽聽聽
聽聽聽 聽聽聽 聽聽聽
"Provider_Class not Supported: " + providerClass);
聽聽聽 聽聽聽 聽聽聽 聽聽聽 throw initException;
聽聽聽 聽聽聽 聽聽聽 }
聽聽聽 聽聽聽 }
聽聽聽 鏈鍚庡氨鏄慨鏀歸厤緗枃浠秖uartz.properties,鍔犲叆
#org.quartz.dataSource.myDS.provider_class = org.quartz.utils.JNDIConnectionProvider
#org.quartz.dataSource.myDS.provider_class = org.quartz.utils.PoolingConnectionProvider
org.quartz.dataSource.myDS.provider_class = org.quartz.utils.HibernateConnectionProvider鍔?鐨勪緵鍙傝?
聽聽聽 緇忚繃嫻嬭瘯,闇瑕佸hibernate榪炴帴姹犵殑涓浜涘弬鏁拌繘琛屽井璋?榪欐牱灝卞畬鎴愪簡Quartz涓嶩ibernate鍦ㄦ暟鎹簱鐨勮繛鎺ユ柟闈㈢殑緇撳悎,濡傛灉鏈夋洿濂界殑瑙e喅鏂規,璇瘋仈緋繪垜.
]]>
聽聽聽聽聽聽 榪欎篃鏄竴涓範鎯殑闂,濂界殑紼嬪簭鍛樹箣鎵浠ユ槸涓ソ鐨勭▼搴忓憳鏄洜涓轟粬鏈夊ソ鐨勪範鎯?榪欎簺濂界殑涔犳儻甯︽潵鐨勫ソ澶勪篃鏄緢澶氱殑.鍐欐棩蹇楀彧鏄叾涓竴涓ソ涔犳儻,鎴戜篃瑕佹參鎱㈢暀鎰忎竴浜涘ソ鐨勪範鎯?鎱㈡參鎬葷粨.
]]>
聽聽聽 聽聽 涓涓啓鐨勪笉閿欑殑浠嬬粛Quartz鐨勪腑鏂囨枃绔狅細璇︾粏璁茶ВQuartz濡備綍浠庡叆闂ㄥ埌綺鵑?/b>錛岃嫳鏂囦笉濂界殑鍙互鍙傝冭繖涓傝繖綃囨枃绔犲ぇ鑷寸殑璁蹭簡Quartz鐨勬鏋訛紝寰堝緇嗚妭騫舵病鏈夋秹鍙婏紝榪欎篃闅炬紝涓綃囨枃绔犱笉鍙兘閮藉啓涓婂幓鐨勩?br />
聽聽聽 聽聽
濡傛灉浣犳兂緇х畫浜嗚ВQuartz錛屽畼鏂圭綉绔欐湁闈㈠悜寮鍙戜漢鍛樼殑鏂囨。錛屼絾鏄斁鍦ㄤ笉璧風溂鐨勮钀斤紝鎴戜互鍓嶉棽閫涙椂鎵懼埌錛岀幇鍦ㄤ竴鏃舵壘涓嶅埌錛屼粈涔堟椂鍊欎粈涔堟壘鍒頒簡鍦ㄥ姞涓婂幓錛屾垜鍦?
鍙﹀鍦版柟鎵懼埌鍏朵腑鐨勫嚑绔狅紝榪欎袱绔犳槸鍏朵腑鏈閲嶈鐨勪袱绔狅紝鍙互浣滀負鍙傝冿紝http://javaforge.com/proj/doc.do?doc_id=
1740
聽聽聽 聽聽 濡傛灉浣犺繕瑕佺戶緇繁鍏ョ爺絀訛紝灝辮鑷繁鍒癱vs鍘諱笅杞芥渶鏂版簮鐮侊紝鑷繁鐮旇浜嗭紝紲濆ぇ瀹舵垚鍔燂紝鎴戜細鎺ヤ笅鍘誨啓涓浜涜嚜宸變粠涓鍒扮殑涓滆タ銆?img src ="http://m.tkk7.com/aspirin/aggbug/37902.html" width = "1" height = "1" />
]]>
聽java.net.SocketException: Invalid argument or cannot assign requested address
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:305)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:171)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:158)
at java.net.Socket.connect(Socket.java:452)
at java.net.Socket.connect(Socket.java:402)
at java.net.Socket.<init>(Socket.java:309)
at java.net.Socket.<init>(Socket.java:124)聽
聽聽聽聽聽聽 榪欐槸IP鍦板潃鐨勯棶棰?鍦‵C4涓粯璁ょ殑鏄疘Pv6 socket,JDK1.4鏀寔鐨勫簲璇ユ槸IPv4,鍏蜂綋鍘熷洜鍙互鏌ョ湅SUN鍏徃緇欏嚭鐨勮В閲?
瑙e喅鍔炴硶鏄湪榪愯JAVA紼嬪簭鏃跺姞涓?-Djava.net.preferIPv4Stack=true 濡?
java -Djava.net.preferIPv4Stack=true application.
浣嗘槸榪欎釜鍦ㄦ瘡嬈¢兘瑕佸姞涓婅繖鍙ヨ瘽錛屽彟鏈夎В鍐蟲柟娉曟槸 淇敼 /etc/modprobe.conf 鏂囦歡,澧炲姞
alias net-pf-10 off
alias ipv6 off
榪欐牱灝變笉鐢ㄥ鍔犲弬鏁?"-Djava.net.preferIPv4Stack=true ",閲嶈搗鍗沖彲.
浣嗘槸鏃㈣ipv6鍙堣兘瑙e喅榪欎釜闂鐨勬柟娉曡繕娌℃壘鍒般傚笇鏈涢珮浜烘寚鐐?/p>
This task runs tests from the JUnit testing framework. The latest version of the framework can be found at http://www.junit.org. This task has been tested with JUnit 3.0 up to JUnit 3.8.1; it won't work with versions prior to JUnit 3.0.
Note: This task depends on external libraries not included in the Ant distribution. See Library Dependencies for more information.
Note: You must have junit.jar
and the class
files for the <junit>
task in the same classpath. You can do
one of:
junit.jar
and the optional tasks jar file in
ANT_HOME/lib
.
ANT_HOME/lib
, and instead include their
locations in your CLASSPATH
environment variable.
<classpath>
element in the build file. See the FAQ for
details. Tests are defined by nested test
or batchtest
tags
(see nested elements).
Attribute | Description | Required |
printsummary | Print one-line statistics for each testcase. Can take the values
on , off , and withOutAndErr .
withOutAndErr is the same as on but also includes the
output of the test as written to System.out and
System.err . |
No; default is off . |
fork | Run the tests in a separate VM. | No; default is off . |
forkmode | Controls how many Java Virtual Machines get created if you want
to fork some tests. Possible values are "perTest" (the default), "perBatch" and
"once". "once" creates only a single Java VM for all tests while "perTest"
creates a new VM for each TestCase class. "perBatch" creates a VM for each
nested <batchtest> and one collecting all nested
<test> s. Note that only tests with the same settings of
filtertrace , haltonerror , haltonfailure ,
errorproperty and failureproperty can share a VM, so
even if you set forkmode to "once", Ant may have to create more
than a single Java VM. This attribute is ignored for tests that don't get forked
into a new Java VM. since Ant 1.6.2 |
No; default is perTest . |
haltonerror | Stop the build process if an error occurs during the test run. | No; default is off . |
errorproperty | The name of a property to set in the event of an error. | No |
haltonfailure | Stop the build process if a test fails (errors are considered failures as well). | No; default is off . |
failureproperty | The name of a property to set in the event of a failure (errors are considered failures as well). | No. |
filtertrace | Filter out Junit and Ant stack frames from error and failure stack traces. | No; default is on . |
timeout | Cancel the individual tests if they don't finish in the given
time (measured in milliseconds). Ignored if fork is disabled. |
No |
maxmemory | Maximum amount of memory to allocate to the forked VM. Ignored if
fork is disabled. |
No |
jvm | The command used to invoke the Java Virtual Machine, default is
'java'. The command is resolved by java.lang.Runtime.exec() .
Ignored if fork is disabled. |
No; default is java . |
dir | The directory in which to invoke the VM. Ignored if
fork is disabled. |
No |
newenvironment | Do not propagate the old environment when new environment
variables are specified. Ignored if fork is disabled. |
No; default is false . |
includeantruntime | Implicitly add the Ant classes required to run the tests and
JUnit to the classpath in forked mode. Note: Please read the Ant FAQ if you want to set this
to false and use the XML formatter at the same time. |
No; default is true . |
showoutput | Send any output generated by tests to Ant's logging system as well as to the formatters. By default only the formatters receive the output. | No |
tempdir | Where Ant should place temporary files. Since Ant 1.6. | No; default is the project's base directory. |
reloading | Whether or not a new classloader should be instantiated for each
test case. Ignore if fork is set to true. Since Ant
1.6. |
No; default is
true . |
By using the errorproperty
and failureproperty
attributes, it is possible to perform setup work (such as starting an external
server), execute the test, clean up, and still fail the build in the event of a
failure.
The filtertrace
attribute condenses error and failure stack
traces before reporting them. It works with both the plain and XML formatters.
It filters out any lines that begin with the following string patterns:
"junit.framework.TestCase"
"junit.framework.TestResult"
"junit.framework.TestSuite"
"junit.framework.Assert."
"junit.swingui.TestRunner"
"junit.awtui.TestRunner"
"junit.textui.TestRunner"
"java.lang.reflect.Method.invoke("
"sun.reflect."
"org.apache.tools.ant."
The <junit>
task supports a nested
<classpath>
element that represents a PATH like structure.
If fork
is enabled, additional parameters may be passed to the
new VM via nested <jvmarg>
elements. For example:
<junit fork="yes">
<jvmarg value="/-Djava.compiler=NONE"/>
...
</junit>
would run the test in a VM without JIT.
<jvmarg>
allows all attributes described in Command-line Arguments.
Use nested <sysproperty>
elements to specify system
properties required by the class. These properties will be made available to the
VM during the execution of the test (either ANT's VM or the forked VM, if
fork
is enabled). The attributes for this element are the same as
for environment variables.
<junit fork="no">
<sysproperty key="basedir" value="${basedir}"/>
...
</junit>
would run the test in ANT's VM and make the basedir
property
available to the test.
You can specify a set of properties to be used as system properties with syspropertysets.
since Ant 1.6.
It is possible to specify environment variables to pass to the forked VM via
nested <env>
elements. For a description of the
<env>
element's attributes, see the description in the exec task.
Settings will be ignored if fork
is disabled.
The location of bootstrap class files can be specified using this PATH like structure - will be ignored if
fork is not true
or the target VM doesn't support it (i.e.
Java 1.1).
since Ant 1.6.
Security permissions can be revoked and granted during the execution of the class via a nested permissions element. For more information please see permissions
Settings will be ignored if fork is enabled.
since Ant 1.6.
You can control enablement of Java 1.4 assertions with an <assertions> subelement.
Assertion statements are currently ignored in non-forked mode.
since Ant 1.6.
The results of the tests can be printed in different formats. Output will
always be sent to a file, unless you set the usefile
attribute to
false
. The name of the file is determined by the name of the test
and can be set by the outfile
attribute of
<test>
.
There are three predefined formatters - one prints the test results in XML
format, the other emits plain text. The formatter named brief
will
only print detailed information for testcases that failed, while
plain
gives a little statistics line for all test cases. Custom
formatters that need to implement
org.apache.tools.ant.taskdefs.optional.junit.JUnitResultFormatter
can be specified.
If you use the XML formatter, it may not include the same output that your tests have written as some characters are illegal in XML documents and will be dropped.
Note: Please read the Ant FAQ if you want to set the
fork attribute to true
, the includeAntRuntime attribute to
false
and use the XML formatter at the same time.
Attribute | Description | Required |
type | Use a predefined formatter (either xml ,
plain , or brief ). |
Exactly one of these. |
classname | Name of a custom formatter class. | |
extension | Extension to append to the output filename. | Yes, if classname has been used. |
usefile | Boolean that determines whether output should be sent to a file. | No; default is true . |
if | Only use formatter if the named property is set. | No; default is true . |
unless | Only use formatter if the named property is not set. | No; default is true . |
Defines a single test class.
Attribute | Description | Required |
name | Name of the test class. | Yes |
fork | Run the tests in a separate VM. Overrides value set in
<junit> . |
No |
haltonerror | Stop the build process if an error occurs during the test run.
Overrides value set in <junit> . |
No |
errorproperty | The name of a property to set in the event of an error. Overrides
value set in <junit> . |
No |
haltonfailure | Stop the build process if a test fails (errors are considered
failures as well). Overrides value set in <junit> . |
No |
failureproperty | The name of a property to set in the event of a failure (errors
are considered failures as well). Overrides value set in
<junit> . |
No |
filtertrace | Filter out Junit and Ant stack frames from error and failure
stack traces. Overrides value set in <junit> . |
No; default is on . |
todir | Directory to write the reports to. | No; default is the current directory. |
outfile | Base name of the test result. The full filename is determined by
this attribute and the extension of formatter . |
No; default is TEST- name,
where name is the name of the test specified in the name
attribute. |
if | Only run test if the named property is set. | No |
unless | Only run test if the named property is not set. | No |
Tests can define their own formatters via nested
<formatter>
elements.
Define a number of tests based on pattern matching.
batchtest
collects the included files from any number of nested
<fileset>
s. It then
generates a test class name for each file that ends in .java
or
.class
.
Attribute | Description | Required |
fork | Run the tests in a separate VM. Overrides value set in
<junit> . |
No |
haltonerror | Stop the build process if an error occurs during the test run.
Overrides value set in <junit> . |
No |
errorproperty | The name of a property to set in the event of an error. Overrides
value set in <junit> . |
No |
haltonfailure | Stop the build process if a test fails (errors are considered
failures as well). Overrides value set in <junit> . |
No |
failureproperty | The name of a property to set in the event of a failure (errors
are considered failures as well). Overrides value set in
<junit> |
No |
filtertrace | Filter out Junit and Ant stack frames from error and failure
stack traces. Overrides value set in <junit> . |
No; default is on . |
todir | Directory to write the reports to. | No; default is the current directory. |
if | Only run tests if the named property is set. | No |
unless | Only run tests if the named property is not set. | No |
Batchtests can define their own formatters via nested
<formatter>
elements.
<junit>
<test name="my.test.TestCase"/>
</junit>
Runs the test defined in my.test.TestCase
in the same VM. No
output will be generated unless the test fails.
<junit printsummary="yes" fork="yes" haltonfailure="yes">
<formatter type="plain"/>
<test name="my.test.TestCase"/>
</junit>
Runs the test defined in my.test.TestCase
in a separate VM. At
the end of the test, a one-line summary will be printed. A detailed report of
the test can be found in TEST-my.test.TestCase.txt
. The build
process will be stopped if the test fails.
<junit printsummary="yes" haltonfailure="yes">
<classpath>
<pathelement location="${build.tests}"/>
<pathelement path="${java.class.path}"/>
</classpath>
<formatter type="plain"/>
<test name="my.test.TestCase" haltonfailure="no" outfile="result">
<formatter type="xml"/>
</test>
<batchtest fork="yes" todir="${reports.tests}">
<fileset dir="${src.tests}">
<include name="**/*Test*.java"/>
<exclude name="**/AllTests.java"/>
</fileset>
</batchtest>
</junit>
Runs my.test.TestCase
in the same VM, ignoring the given
CLASSPATH; only a warning is printed if this test fails. In addition to the
plain text test results, for this test a XML result will be output to
result.xml
. Then, for each matching file in the directory defined
for ${src.tests}
a test is run in a separate VM. If a test fails,
the build process is aborted. Results are collected in files named
TEST-
name.txt
and written to
${reports.tests}
.