not able to load properties file with runnable jar

I have maven project in Java in which I have a property file (quartz.properties) under this directory:

/src/main/resources

Now I can use this property file in two ways from this class as shown below:

/**
 * Create a StdSchedulerFactory that has been initialized via
 * <code>{@link #initialize(Properties)}</code>.
 *
 * @see #initialize(Properties)
 */
public StdSchedulerFactory(Properties props) throws SchedulerException {
    initialize(props);
}

/**
 * Create a StdSchedulerFactory that has been initialized via
 * <code>{@link #initialize(String)}</code>.
 *
 * @see #initialize(String)
 */
public StdSchedulerFactory(String fileName) throws SchedulerException {
    initialize(fileName);
}

So I started using like this:

public static void main(String[] args) {
    StdSchedulerFactory factory = new StdSchedulerFactory();
    try {
        factory.initialize(TestClassName.class.getClassLoader().getResourceAsStream("quartz.properties"));
        Scheduler scheduler = factory.getScheduler();
        scheduler.start();
    } catch (SchedulerException ex) {
        System.out.println("error= " + ExceptionUtils.getStackTrace(ex));
    }
}

This works fine without any issues in my windows laptop but when I make a runnable jar (export --> runnable jar --> Package required libraries into generated JAR) and then if I run like this on my other ubuntu machine:

java -jar abc.jar

I am getting this exception:

error= org.quartz.SchedulerException: Error loading property data from InputStream - InputStream is null.
        at org.quartz.impl.StdSchedulerFactory.initialize(StdSchedulerFactory.java:576)
        at com.example.quartz.TestClassName.main(TestClassName.java:17)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:601)
        at org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoader.java:58)

What is wrong I am doing?

Update:- Output from jar tvf abc.jar . I am just showing relevant things not all.

    13 Thu Sep 10 18:16:30 GMT-07:00 2015 resources/build.properties
   594 Thu Sep 10 18:16:30 GMT-07:00 2015 resources/quartz.properties
  1254 Thu Sep 10 18:16:30 GMT-07:00 2015 resources/quartz_config.xml
Jon Skeet
people
quotationmark

Your file is in the jar file as resources/quartz.properties, not just quartz.properties - so that's how you need to load it:

factory.initialize(
  TestClassName.class.getClassLoader().getResourceAsStream("resources/quartz.properties"));

Alternatively, create the jar file differently so that quartz.properties is in the "root" directory of the jar file. (That's where I'd expected it to be, given the file system structure you've described.)

people

See more on this question at Stackoverflow