0
public class RunTests {
public static void main(String[] args) {
    TestNG testNG = new TestNG();
    List<String> suites = Lists.newArrayList();         

    File xml = new File("xml.xml");
    suites.add(xml.getAbsolutePath());

    testNG.setTestSuites(suites);
    testNG.run();   
}
}  

My Java project has the default src folder, and a separate folder I created called "config". config holds a package called "pkg" with the java class "RunClass" as well as xml files that run tries to refer to.

ProjectName
src

config
     pkg
       RunClass
       file.xml

enter image description here I added config to the list of sources in the build path, yet RunClass still complains about not being able to find the file.

It gives:

java.io.FileNotFoundException: C:\Users\asdf\eclipse-workspace\NG\xml.xml (The system cannot find the file specified)

displayName
  • 195
  • 2
  • 15
  • Why do you think the build path has anything to do with the error you get? What is the code causing this error? – JB Nizet Nov 15 '19 at 20:08
  • @JBNizet I was referring to this similar post https://stackoverflow.com/questions/47100605/how-to-include-resource-folder-in-executable-jar-file-in-eclipse – displayName Nov 15 '19 at 20:32
  • @ArvindKumarAvinash the xml file is definitely in the project, just not in the default src folder. It goes config -> pkg -> [RunClass, xml.xml] – displayName Nov 15 '19 at 20:33
  • The question you linked to, just as yours, doesn't contain any code. To be able to explain why your code behaves the way it does, we need to see that code. Post the code. – JB Nizet Nov 15 '19 at 20:33
  • @JBNizet added to my original post – displayName Nov 15 '19 at 20:48
  • OK. Read the javadoc of File. It says: *A relative pathname, in contrast, must be interpreted in terms of information taken from some other pathname. By default the classes in the java.io package always resolve relative pathnames against the current user directory. This directory is named by the system property user.dir, and is typically the directory in which the Java virtual machine was invoked.*. So the classpath is completely irrelevant. The relative path `xml.xml` will be resolved based on the current directory, i.e. the directory from which you execute the java command. – JB Nizet Nov 15 '19 at 20:52
  • Just like when you execute `notepad foo.txt`, you open the foo.txt file located in the current directory. – JB Nizet Nov 15 '19 at 20:53

0 Answers0