How can civil ATC maintain safety with military aircraft around?
Military aircraft do have transponders that can reply to civil ATC radar and TCAS interrogations. Normally military aircraft operating in civil airspace are visible to civilian ATC and also will trigger TCAS advisories and alerts if they are getting close to airliners. 

During  wartime operations, and sometimes during combat practice in dedicated airspace, the transponder is operated in a different mode and will not be replying to civil radar interrogations. 

Typically when operating in civil airspace, military aircraft will fly under the civil regulations for that airspace. Training flights are usually conducted in dedicated airspace under military traffic control. 

In some cases the military ATC assumes responsibility over military aircraft in otherwise civil ATC controlled airspace. In such a case the military ATC will be responsible for the separation between the military aircraft themselves and between military and civilian aircraft. 

In other cases military aircraft may be allowed to maintain their separation from each other on their own, without civil ATC interfering in their operations. This allows for operations where military aircraft flying close to each other like formation flying and aerial refuelling outside the dedicated military airspace. In the USA these operations are called MARSA (Military Assumes Responsibility for Separation of Aircraft). Civil ATC is responsible for keeping Instrument Flight Rules (IFR) aircraft separated from MARSA operations. Visual Flight Rules (VFR) pilots have to maintain separation visually from MARSA flights and vice-versa. If VFR pilots are in contact with ATC they will be advised of ongoing military operations.