use getResource to get the URL of the resource and then parsethe URL to find the file path
On 07/05/2009, Pete Siemsen <[email protected]> wrote: > That seems reasonable, but I still don't understand how to make it work. > > The program I'm trying to test is like a compiler. It reads source > files that can contain "include" statements. When it parses such a > statement, the program needs to open the include file and start > parsing statements in the include file. > > If I use getResourceAsStream, what can I do when I encounter the > "include" statement? How can I open the include file if I can't > specify the path that leads to the include file, relative to the > initial input stream? > > As I wrote, the program is working just fine. It reads a file name > from the command line. My question is how to test it within the maven > framework, without specifying absolute test file names. > > Cheers, > -- Pete > > > On May 5, 2009, at 3:55 PM, Jeff MAURY wrote: > >> You should store your files under src/test/resources and load your >> files using getResourceAsStream >> >> Regards >> Jeff MAURY >> >> On Tue, May 5, 2009 at 11:37 PM, Pete Siemsen <[email protected]> >> wrote: >> >>> This is a basic question about how to run Java unit tests that >>> require file names. >>> >>> I use maven to develop a program that reads input file names from >>> the command line. It's working fine, but now I want to share the >>> code with someone else. The test programs live in ../src/test/ >>> java, and the test data lives in ../src/test/data. Until now, I've >>> used fully-qualified paths hard-coded into my test programs, like / >>> Users/siemsen/TranslateCIM/src/test/data/cim/ >>> testArrayTypeOnNonArray/testATONA.mof. >>> >>> If I tar up my development directory and give it to someone else, >>> the fully-qualified paths obviously don't work. I want to make the >>> paths relative somehow. The program reads an input file that may >>> contain "include" statements that cause the program to open other >>> files relative to the first input file. It seems to my newbie eyes >>> that using resources and getResourceAsStream won't allow me to open >>> subfiles. >>> >>> What I think I want is a runtime environment variable or something >>> that tells me the path to the maven development directory. >>> >>> Any suggestion would be appreciated. >>> >>> -- Pete > > --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
