Paul Clapham wrote:Well, have a look at this part of your stack trace:
java.io.FileNotFoundException: D:/Property/PropertiesMQ.properties (No such file or directory)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(FileInputStream.java:106)
at java.io.FileInputStream.<init>(FileInputStream.java:66)
at mqAge.MessageAgeMonitor.main(MessageAgeMonitor.java:232)
First of all the exception is thrown from the main() method of the MessageAgeMonitor class. But the code you posted, which was a class named MessageAgeMonitor, doesn't have a main() method. So you're looking at the wrong version of the class. First step, then, is to find the code corresponding to what you are running.
And second, you'll notice that the file which wasn't found was D:/Property/PropertiesMQ.properties. This is a Windows file path which must have been hard-coded in the main() method; running that on a Unix system is naturally not going to be able to find a file with that name.
thank you for taking out time
my profuse appologies for giving the incomplete class here is the complete code and it has main method i also tried creating similar folder strcture in the unix and accordingle changed the path
public class MessageAgeMonitor implements Runnable {
protected static Logger logger = Logger.getLogger(MessageAgeMonitor.class);
protected static boolean isDebugEnabled = logger.isDebugEnabled();
final private String qmgrName;
final private String host;
final private int port;
final private String queueName;
final private int alertAge; // in seconds
final private String channel;
// file change for flat file
final static int Polling_Freq = 30 * 1000; // 30 seconds
MessageAgeMonitor(String qmgrName, String host, int port, String queueName,
String channel, int alertAge) {
this.qmgrName = qmgrName;
System.out.println(qmgrName);
this.host = host;
this.port = port;
this.channel = channel;
this.queueName = queueName;
this.alertAge = alertAge;
}
public void run() {
if (isDebugEnabled)
logger.debug("Starting Message Age monitor for " + queueName
+ "...");
while (true) {
checkAge();
try {
Thread.sleep(Polling_Freq); // sleep for 30 seconds
} catch (InterruptedException e) {
logger.info("The monitor has been interrupted, exit...");
break;
}
}
}
private void checkAge() {
MQQueueManager qm = null;
MQQueue queue = null;
if (isDebugEnabled) {
logger.debug("Connecting to " + qmgrName + " at " + host + ":"
+ port + " over " + channel);
}
try {
MQEnvironment.disableTracing();
MQException.log = null;
MQEnvironment.hostname = host;
MQEnvironment.port = port;
MQEnvironment.channel = channel;
qm = new MQQueueManager("");
queue = qm.accessQueue(queueName, MQC.MQOO_BROWSE
| MQC.MQOO_FAIL_IF_QUIESCING);
MQMessage message = new MQMessage();
MQGetMessageOptions gmo = new MQGetMessageOptions();
gmo.options = MQC.MQGMO_BROWSE_FIRST | MQC.MQGMO_NO_WAIT
| MQC.MQGMO_CONVERT;
message.messageId = null;
message.correlationId = null;
queue.get(message, gmo);
// get message put date time
GregorianCalendar cal = message.putDateTime;
// System.out.println("cal means "+cal);
// System.out.println("DATE: " + GregorianCalendar.DAY_OF_MONTH);
// System.out.println("DATE: " + GregorianCalendar.DAY_OF_WEEK);
// System.out.println("DATE: " + GregorianCalendar.DATE);
// System.out.println("DATE: " + GregorianCalendar.HOUR);
// String s= message.
// System.out.println("printing the message"+s);
long ageInMillis = new java.util.Date().getMinutes();
// long ageInMillis = cal.getTime().getTime() - new
// java.util.Date().getTime();
// System.out.println( "cal3 ----"+ cal.getTime().getSeconds());
// System.out.println( "ageInMillis ----"+ new
// java.util.Date().getMinutes()+"-"+new
// java.util.Date().getSeconds() );
// System.out.println( "cal2 ----"+ new java.util.Date().getTime());
// System.out.println( "cal3 ----"+ cal.getTime().getTime());
// int ageInSeconds = (int) ageInMillis/1000;
int ageInSeconds = cal.getTime().getSeconds();
System.out.println("age in second when message put" + ageInSeconds);
long ageInMillis1 = cal.getTime().getTime();
System.out
.println("age in seconds at wat time message was put from now"
+ ageInMillis1);
long ageInMillis2 = new java.util.Date().getTime();
System.out.println("prsesnt age in seconds" + ageInMillis2);
long diff = ageInMillis2 - ageInMillis1;
System.out.println("diff" + diff);
long diff2 = diff / 1000;
System.out
.println("this is difference in seconds between time when MSG came and todays date"
+ diff2);
String content = String.valueOf(diff2);
FileWriter fileWriter = null;
try {
String content2 = content;
String Client = "Instinet";
String Sep = ",";
File newTextFile = new File("/C/test/test.txt");
fileWriter = new FileWriter(newTextFile);
fileWriter.write(Client);
fileWriter.write(Sep);
fileWriter.write(queueName);
fileWriter.write(Sep);
fileWriter.write(content2);
fileWriter.close();
} catch (IOException ex) {
Logger.getLogger(WriteStringToFile.class.getName()).log(
Level.ALL, null, ex);
} finally {
try {
fileWriter.close();
} catch (IOException ex) {
Logger.getLogger(WriteStringToFile.class.getName()).log(
Level.ALL, null, ex);
}
}
if (isDebugEnabled)
// logger.debug("Put Date: " + cal.getTime() +
// " age in seconds: " + ageInSeconds);
if (ageInSeconds > alertAge) {
logger.info(qmgrName + "/" + queueName + " age = "
+ ageInSeconds + ", exceeded alert threshold: "
+ alertAge);
}
} catch (MQException mqe) {
if (mqe.reasonCode == MQException.MQRC_NO_MSG_AVAILABLE) {
if (isDebugEnabled) {
logger.debug("Queue " + qmgrName + "/" + queueName
+ " is empty.");
}
} else {
logger.error("MQException caught", mqe);
}
} finally {
if (queue != null && queue.isOpen()) {
try {
queue.close();
} catch (Exception e) {
logger.error("Exception caught during queue.close()", e);
}
}
if (qm != null) {
if (qm.isOpen()) {
try {
qm.close();
} catch (Exception e) {
logger.error("Exception caught during qm.close()", e);
}
}
if (qm.isConnected()) {
try {
qm.disconnect();
} catch (Exception e) {
logger.error("Exception caught during qm.disconnect()",
e);
}
}
}
}
}
public static void main(String[] args) {
Properties prop = new Properties();
String qmgrName = "";
String host = "";
String port = "";
String channel = "";
String queueName = "";
try {
//prop.load(new FileInputStream("src/PropertiesMQ.properties"));
prop.load(new FileInputStream("/D/Property/PropertiesMQ.properties")); // above one is working fine in windows
//chnage below
/*String path = "/Property/PropertiesMQ.properties";
//D:/Property/PropertiesMQ.properties
String base = "/Property";
String relative = new File(base).toURI().relativize(new File(path).toURI()).getPath();
//chnage below
*/
//System.out.println("this is realtive"+relative);
// relative == "stuff/xyz.dat"
/* String basePath = "D:/Property/";
String absolutePath = "D:/Property/PropertiesMQ.properties";
if (absolutePath.startsWith(basePath)) {
String relativePath = absolutePath.substring(basePath.length());
System.out.println(relativePath);
prop.load(new FileInputStream(relativePath));
}*/
//prop.load(new FileInputStream("relativePath"));
//above wrking fine
//chnage below
//prop.load(new FileInputStream(relative));
qmgrName = prop.getProperty("qmgrName");
host = prop.getProperty("host");
port = prop.getProperty("port");
channel = prop.getProperty("channel");
queueName = prop.getProperty("queueName");
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
System.out.println(qmgrName);
System.out.println(host);
System.out.println(Integer.valueOf(port));
System.out.println(channel);
System.out.println(queueName);
MessageAgeMonitor monitor = new MessageAgeMonitor(qmgrName, host, Integer.valueOf(port),
queueName, channel, 10);
new Thread(monitor).start();
}
}
addtional iformation
while creating executable jar from eclipse i get following warning
JAR export finished with warnings. See details for additional information.
Could not read JAR file 'FactoryEnabled.java'. Reason: error in opening zip file
error in opening zip file
error in opening zip file
Exported with compile warnings: Final_Age_Monitor/src/mqAge/WriteStringToFile.java
Exported with compile warnings: Final_Age_Monitor/src/mqAge/MessageAgeMonitor.java
Could not read JAR file 'libraries.properties'. Reason: error in opening zip file
error in opening zip file
error in opening zip file
please advice