Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Current diretory problems

 
Tim Manchester
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Howdy,

I'm using Websphere and I've put together an enterprise app that includes a java project (DataAccess) and a struts web app. I created the java project because it's for utilities that I'll want to reuse so after I got that project mostly together, I exported a jar file from it into the lib directory of my web app.

Now in the Action class of one of my jsp's it instantiates a class out of the jar file just fine. The problem is that that class reads two files, neither of which it can find. I've moved those dang files all over both of my projects! The system error message doesn't tell me where it's trying to find the files (DANG!) but it does tell me it just can't find them.

If anyone can tell me, is there a system call that reports back what the current application thinks is the current directory? Or better still, does anyone know where I ought to put the files that a class in a jar would be looking for?

Regards,

- Tim Manchester
 
Nathaniel Stoddard
Ranch Hand
Posts: 1258
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How are you trying to read those files? When inside of a JAR, or EAR, or WAR, or whateveR .. .. you need to use Classloader.getResourceAsStream(), or one of the other methods that it gives you. Once you're doing that, you're going to be just fine assuming your files are actually packaged correctly.
 
Tim Manchester
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I wasn't bundling the files with the jar. I wanted to be able to use different files (one is a config file and the other has variable data). Though I will keep your earlier idea in mind for future use.

Regards,

- Tim Manchester
 
Peter Chase
Ranch Hand
Posts: 1970
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

YMMV
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic