Issue
I have 2 Java projects, one is a Web Project in NetBeans and the other is a Java Project in Eclipse.
Just to know, the Java Project from Eclipse is used by the Web Project in NetBeans as a library (.jar)
Situation:
1. Java Project from Eclipse has the following structure:
And inside the src
, there is a class
that uses the file1, file2, etc in some method using global variables like this:
public static final String PATH_ONE = "./files/file1.xml";
public static final String PATH_TWO = "./files/file2.xml";
...
Finally, when I test the method in some main()
class everything works good.
2. Web Project from NetBeans has a jar
reference to the above library
and If everything works good, then the web project will be able to execute the method
that uses the global variables without problems from the library
project.
Problem:
When I run the web project and I want to invoke the method
from my library
that uses the above xml
files from it, for some reason, NetBeans or the project (I don't certainly know) looks for the path and fails in Exception
because the path can not be found (It seems that tries to find the path in the web project and not in the library
one).
How can I solve this issue? It sounds simple but I don't want to change my structure, load them as a resource or transfer files from one project to another and use external paths to make this work because I just make a recreation of the situation but I am working with lots of files with different folders and paths too.
Solution
If you unzip your jar you can't find your folder file because not is included in your classpath.
You can See .classpath file and the folder isn't. For these reason is FileNotFoudnException.
You can to add how source folder in Eclipse ID:
1. Right click in your project/Build Path/ New source folder
Create the source folder . Then you can add a new package with the name Folder.
Your project:
src
resources
folder
resource1.xml
resource2.xml
2. Modify your java project.
public static final String PATH ="/folder/resource1.xml";
Now, if you try to unzip the jar, you can see that the folder was added in the .classpath.
It works for me. I tried to paste image but i'm new user.
Answered By - Makoton