0

I have the following in eclipse

EclipseJavaProject
    src/
        some.package
            Program (+main method)
            some.xml
            some.other.resource

Note: When running the app, the current dir is set to EclipseJavaProject/ by eclipse

I want to get the path to some.xml and the other resources (relative or absolute). either:

src/some/package/

or

/path-to-workspace/workspace/EclipseJavaProject/src/some/package/

Note: I want the src/ folder in eclipse, because I output files there. I don't want the bin/ folder. Is there a quick way?

So far I have (I don't know how to get the src folder name):

public class C {
    public static String C;

    public static void main(String[] args) {
        System.err.println(C);
    }

    static {
        String command = System.getProperty("sun.java.command");
        String dir = System.getProperty("user.dir")+"/src/"+command.substring(0, command.lastIndexOf(".")+1).replaceAll("\\.", File.separator);
        C = dir;
    }
}
mist
  • 1,853
  • 2
  • 19
  • 33
  • 1
    Search on tutorials: http://docs.oracle.com/javase/tutorial/deployment/webstart/retrievingResources.html – Luiggi Mendoza Jun 21 '14 at 15:34
  • Most of the times I'm in a static method and I don't have 'this'. Also I'm not in a jar file. – mist Jun 21 '14 at 15:35
  • `ClassName.class` is `static` as well. – Luiggi Mendoza Jun 21 '14 at 15:35
  • This would work well in a jar, but would not give me src/package/some.xml – mist Jun 21 '14 at 15:36
  • 1
    I test this on real world applications and **works**. In order for me to reopen the question, edit it and post your exact problem. Retrieving resources from the current package is not a problem because it can be searched on the net and is easy to test. – Luiggi Mendoza Jun 21 '14 at 15:37
  • I just tried it - it gives me the /bin folder in eclipse. I don't want the bin folder. I want the src/ folder – mist Jun 21 '14 at 15:40
  • 1
    You have yo start distinguishing between your project (and its source folders) and the actual application (and how it is distributed). – Sotirios Delimanolis Jun 21 '14 at 15:50
  • Thank you for the condescending comment. I have a reason to want to get the src/ folder. – mist Jun 21 '14 at 19:00
  • Can we reopen this, since I have no answer? – mist Jun 21 '14 at 19:01

0 Answers0