Eclipse, multiple classpaths?

I have Eclipse project A which loads resources found in its project root.

I have Eclipse project B which uses project A. Whenever I execute project B, the resources A tries to load is not found, obviously because it’s looking for the resources in project B root rather than A.

How do I address this issue?

Do not load files via file system paths, use classpath resources instead and load those via ClassLoader.getResourceAsStream (for example).
So, first thing: Put all resources you want to load under some classpath root, such as /res or somewhere.
Second: Use the ClassLoader to load those resources as URL or as InputStream.

For Project A:
“Java Build Path” -> “Order and Export” tab -> check the classpath elements that you wish dependent projects to have access to.

Thanks, that helped me clean up some code. But it did not solve this problem because the only folder showed up in “Order and Export” tab was A’s src folder. The resource folder was not even there.

To complete this I have to refactor a lot of code, but thanks for the tip! ^^

Classpath root folders are automatically exported. Only libs are not.
You do not load your resources via a classpath root. So, your folder is not there.

That’s just the way it is. :slight_smile:

Have same issues long time ago)
Only Conclusion I find – not load res in project A from other place then project A :wink:
For all others res use external folder “…/…/res” links good same in eclipse and after project was built.

p.s personaly i now using abs Path - easy to debug


String workingDir = System.getProperty("user.dir");
String IO_Path_ABS = workingDir + "\\";

File file = new File(IO_Path_ABS + str);

but long time ago i use this)


	protected File get_File_In_Jar_In(String path){
		URL ur = SomeClass.class.getClassLoader().getResource(path);	
		File file = null;
		try{
			file = new File(ur.toURI());
		}catch (URISyntaxException e){e.printStackTrace();}	
		return file;
	}

	protected File get_File_In_Folder_In(String path){
		File file = new File(path);	
		return file;
	}

Note that this is a problem that only exist in development environment. Will work fine during production. So I will move the resource folder to project B.