• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Running a JAR file on Unix

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi ,
i have a mq queue depth monitoring program , i have prepared an executable jar for the same and it is working from the windows but when i run from from unix by using

java -jar mqjar.jar command through a script i get this error

[root@-i ] ./mqrun.sh
toaaaday is Tue Apr 30 23:12:59 UTC 2013
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:rsrc:logback-classic-0.9.19.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:rsrc:logback-classic-0.9.6.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:rsrc:logback-classic-0.9.19_2.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
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)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoader.java:58)


Exception in thread "main" java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoader.java:58)
Caused by: java.lang.NumberFormatException: For input string: ""

can you please help me with this

it appear to me that it has something to do with relative path or something how to resolve this

my code is like this

MessageAgeMonitor

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;
}
}

WriteStringToFile


public class WriteStringToFile {
/** * @param args the command line arguments */
public static void main(String[] args) {
FileWriter fileWriter = null;
try {
String content = "Hello! Java-Buddy ";
//File newTextFile = new File("../../../Final_Age_Monitor/test.txt");
File newTextFile = new File("C:/test/test.txt");

fileWriter = new FileWriter(newTextFile);
fileWriter.write(content);
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);
}
}
}
}


PropertiesMQ.properties

qmgrName=blah blah blah
host=196.178.185.139
port=19xx
channel=SYSTEM.DEF.SVRCONN
queueName=xyz.ACCOUNT.Q.OUT.xx

 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
gauravtyagi tyagi
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
gauravtyagi tyagi
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi i found a way around this problem

1 i placed all my required files in the same director from where i am running the shell scrits to execute the jar
2 i generated the jar once again after changing the path of java files to the directory of unix box from where i m executing the scrpt to run jar

hope this helps other users.
 
Rancher
Posts: 1044
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


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.



A sidenote: it is not likely but also not unconceivable to have this file on Linux:

oracle@izsak:/tmp> uname -a
Linux izsak.khb.hu 2.6.9-101.ELsmp #1 SMP Fri May 27 18:57:30 EDT 2011 i686 athlon i386 GNU/Linux

oracle@izsak:/tmp> ls -l D:/Property/PropertiesMQ.properties
-rw-r----- 1 oracle oinstall 412 May 28 15:52 D:/Property/PropertiesMQ.properties


 
reply
    Bookmark Topic Watch Topic
  • New Topic