• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

about com.ibatis.common.resources.getResourceAsReader

 
haifeng zhou
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
/*******************************************************************************
* $Header$
* $Revision$
* $Date$
* TestResource.java
*
*
* Copyright (c) 2001-2006 Primeton Technologies, Ltd.
* All rights reserved.
*
* Created on 2009-11-27
*******************************************************************************/


package com.eshore.itsm.agent.test;

import java.io.File;
import java.io.IOException;

import com.ibatis.common.resources.Resources;

/**
*
* @author Butcher
*/
public class TestResource {

/**
*@param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
final String resource = "com/eshore/itsm/agent/config/sql-map-ibatis.xml";
try {
System.out.println("TestResource process current path:"+ new File("").getAbsolutePath());
System.out.println("TestResource process begin to read source");
Resources.getResourceAsReader(resource);
System.out.println("TestResource process read source success");
} catch (IOException e) {
// TODO Auto-generated catch block
System.out.println("TestResource process read source fail");
System.out.println(e.getMessage());
}
}

}

=============================================================================================================

/*******************************************************************************
* $Header$
* $Revision$
* $Date$
*
*
* Copyright (c) 2001-2006 Primeton Technologies, Ltd.
* All rights reserved.
*
* Created on 2009-11-27
*******************************************************************************/


package com.eshore.itsm.agent.test;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;

/**
*
* @author 周海锋
*/
public class TestCallResource {

/**
*@param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
try {
System.out.println("TestCallResource process current path:"+ new File("").getAbsolutePath());
Process child = Runtime.getRuntime().exec("java -cp D:\\MyEclipseWork\\agent\\bin com.eshore.itsm.agent.test.TestResource");
int nRead = 0;
byte[] line = new byte[2048];
InputStream out = child.getInputStream();
System.out.println("TestCallResource begin to read child process");
while((nRead = out.read(line))>0){
String lineMsg = new String(line, 0, nRead);
System.out.println(lineMsg);
}

System.out.println("TestCallResource begin to read child process error stream");
out = child.getErrorStream();
while((nRead = out.read(line))>0){
String lineMsg = new String(line, 0, nRead);
System.out.println(lineMsg);
}
System.out.println("TestCallResource read child process end");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

}

=============================================================================================================
if I just run com.eshore.itsm.agent.test.TestResource
Resources.getResourceAsReader(resource) can read the source "com/eshore/itsm/agent/config/sql-map-ibatis.xml"
but run com.eshore.itsm.agent.test.TestCallResource
Resources.getResourceAsReader(resource) can not read the source "com/eshore/itsm/agent/config/sql-map-ibatis.xml"
this two java file in the same package
why??
how does Resources.getResourceAsReader(resource) work
thanks a lot
 
Rob Spoor
Sheriff
Pie
Posts: 20493
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please Use Code Tags.
 
Travis Hein
Ranch Hand
Posts: 161
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
when you have the runtime exec the child java process, you set classpath to be the D:/..../bin folder (where likely the .class and these .xml files exist.

I would check that the .xml files are actually deposited into this bin/ folder; my eclipse IDE doesn't always copy the .xml files if i have them in a folder that is not on the build path.

Also, when you set the classpath as you do to be the bin/ folder, would you not also need to include the ibatis.jar file, (and every other .jar file that is required to boot up the connection to the database and run the method?
 
haifeng zhou
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks, i get it
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic