Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Newcomers » Newcomers » Eclipse always searches file in workspace - how to change?
Eclipse always searches file in workspace - how to change? [message #1198256] Wed, 20 November 2013 08:18 Go to next message
Heiko Schmittwer is currently offline Heiko SchmittwerFriend
Messages: 2
Registered: November 2013
Junior Member
Hello!

I am including a file in my project like this:

File xsl = new File("stylesheet.xsl");

The problem is that Eclipse always looks for that file in the workspace. But I want it to look for that file relative to where the class-files are. I am trying to make a runnable jar of my programme but the programme will always look for that file in the workspace. If I put the stylesheet in the same folder as the .class-files (i. e. the package) I want the programme to look for the file in that folder.

How can I get that to work?
Re: Eclipse always searches file in workspace - how to change? [message #1198280 is a reply to message #1198256] Wed, 20 November 2013 08:32 Go to previous messageGo to next message
Russell Bateman is currently offline Russell BatemanFriend
Messages: 3798
Registered: July 2009
Location: Provo, Utah, USA
Senior Member

On 11/20/2013 01:18 AM, Heiko Schmittwer wrote:
> Hello!
>
> I am including a file in my project like this:
>
> File xsl = new File("stylesheet.xsl");
>
> The problem is that Eclipse always looks for that file in the workspace.
> But I want it to look for that file relative to where the class-files
> are. I am trying to make a runnable jar of my programme but the
> programme will always look for that file in the workspace. If I put the
> stylesheet in the same folder as the .class-files (i. e. the package) I
> want the programme to look for the file in that folder.
>
> How can I get that to work?

What you say isn't completely accurate. It's not Eclipse's fault per se.

In fact, this has little to do with Eclipse. It's the nature of Java
file I/O. Eclipse creates a microcosm in the project of what your
program will find when running out there in the big, bad world outside
of Eclipse.

But, Eclipse can help as recounted in a very recent post you missed when
you searched this forum:

"[Eclipse's] Java Application launcher allows you to set the working
directory on the Arguments tab."

Alternatively, you can play around creating files with different path
arguments in Java until you get a feel for how best to do this.
Re: Eclipse always searches file in workspace - how to change? [message #1199134 is a reply to message #1198280] Wed, 20 November 2013 17:52 Go to previous message
David Wegener is currently offline David WegenerFriend
Messages: 1445
Registered: July 2009
Senior Member
If you want to locate files relative to your classpath, you need to use the getResource or getResourceAsStream methods of the Class object.
Previous Topic:gdk_screen_get_resolution
Next Topic:eclipse marketplace issue
Goto Forum:
  


Current Time: Fri Apr 26 17:36:59 GMT 2024

Powered by FUDForum. Page generated in 0.08415 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top