Maven is a build tool. It doesn't help you much running the final application.
You can use mvn exec:java -Dexec.mainClass="com.example.Sandbox" to run your app (see the question Maven Run Project) but this gets tedious when you have to pass arguments to it.
You can get the classpath that Maven used to compile your application with mvn dependency:build-classpath
That will print the classpath to the console. Note that it will be missing target/notification-1.0.0.jar
Another useful tool in this area is the assembly plugin; it will create one very big JAR with all the dependencies rolled into a single file when you specify the descriptor jar-with-dependencies.
To get the classpath all by itself in a file, you can:
mvn dependency:build-classpath -Dmdep.outputFile=cp.txt
Or add this to the POM.XML:
<project>
[...]
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.9</version>
<executions>
<execution>
<id>build-classpath</id>
<phase>generate-sources</phase>
<goals>
<goal>build-classpath</goal>
</goals>
<configuration>
<!-- configure the plugin here -->
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
[...]
</project>
From: http://maven.apache.org/plugins/maven-dependency-plugin/usage.html
This command outputs the classpath on Mac and Linux:
mvn -q exec:exec -Dexec.executable=echo -Dexec.args="%classpath"
Having the result printed and not saved into a file might be useful, for instance, when assigning the result to a variable in a Bash script. This solution runs on Mac and Linux only, but so do Bash shell scripts.
In Windows (e.g. in BAT files), where there is no echo executable, you will need something like this (untested):
mvn -q exec:exec -Dexec.executable=cmd -Dexec.args="/c echo %classpath"
Alternatively, you can just execute java program with the classpath:
mvn -q exec:exec -Dexec.executable=java -Dexec.args="-cp %classpath Main"
Or even like that (it will use the correct classpath automatically):
mvn -q exec:java -Dexec.mainClass="Main"
However, both these alternative approaches suffer from Maven adding its error messages when your program fails.
A cleaner alternative of putting your config file into a subfolder of src/main/resources would be to enhance your classpath locations. This is extremely easy to do with Maven.
For instance, place your property file in a new folder src/main/config, and add the following to your pom:
<build>
<resources>
<resource>
<directory>src/main/config</directory>
</resource>
</resources>
</build>
From now, every files files under src/main/config is considered as part of your classpath (note that you can exclude some of them from the final jar if needed: just add in the build section:
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<excludes>
<exclude>my-config.properties</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
so that my-config.properties can be found in your classpath when you run your app from your IDE, but will remain external from your jar in your final distribution).
If you place anything in src/main/resources directory, then by default it will end up in your final *.jar. If you are referencing it from some other project and it cannot be found on a classpath, then you did one of those two mistakes:
*.jaris not correctly loaded (maybe typo in the path?)- you are not addressing the resource correctly, for instance:
/src/main/resources/conf/settings.propertiesis seen on classpath asclasspath:conf/settings.properties
You can use bin/librec or bin/librec.cmd to run it from commandline.
If you want to build your launch command you can see those start scripts and adapt them for your purposes.
To run your app through command line, once you have the .class files in some dir (usually build) all you have to do is run your application with java -cp "path where jvm can find every .class that you project needs" MainClass.
The -cp flag only tells where to look for compiled .class files, since you are using IntellIJ you can see the command it runs when executing your program, there is a class path that it uses.
Class Path points to where your .class files are, they can be in separate folders, but you need to include every dir when giving the class path, separated by ";"
Example taken from another question in SO.
java -cp "Test.jar;lib/*" my.package.MainClass
You need to include your src/main/resources directory to the classpath in your pom.xml using its relative path:
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
</resource>
</resources>
</build>
You can read more about it here.
Can you please check inside jar if it contains the mentioned file in classes folder. Also you can try below code to load the file from classpath.
Thread.currentThread().getContextClassLoader().getResource(<file_name>)
If possible then keep that file outside the jar in some folder location and set that location as classpath when executing the jar.