aspose file tools*
The moose likes Java in General and the fly likes about com.ibatis.common.resources.getResourceAsReader Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "about com.ibatis.common.resources.getResourceAsReader" Watch "about com.ibatis.common.resources.getResourceAsReader" New topic
Author

about com.ibatis.common.resources.getResourceAsReader

haifeng zhou
Greenhorn

Joined: Oct 30, 2009
Posts: 13
/*******************************************************************************
* $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

Joined: Oct 27, 2005
Posts: 19783
    
  20

Please Use Code Tags.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Travis Hein
Ranch Hand

Joined: Jun 06, 2006
Posts: 161
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?

Error: Keyboard not attached. Press F1 to continue.
haifeng zhou
Greenhorn

Joined: Oct 30, 2009
Posts: 13
thanks, i get it
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: about com.ibatis.common.resources.getResourceAsReader