I am using the Maven exec plugin to launch a Java application from the command line using the mvn exec: java command. I pointed out the main class in pom.xml and related dependencies.
<groupId>com.example.MyApp</groupId> <artifactId>MyApp</artifactId> <version>1.0.0</version> <build> <plugins> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>exec-maven-plugin</artifactId> <version>1.2.1</version> <executions> <execution> <goals> <goal>java</goal> </goals> </execution> </executions> <configuration> <mainClass>com.example.myclass</mainClass> <arguments> <argument>configFile</argument> <argument>properties</argument> </arguments> </configuration> </plugin>
I also indicate the number of dependencies ...
<dependencies> <dependency> <groupId>log4j</groupId> <artifactId>log4j</artifactId> <version>1.2.17</version> <type>jar</type> </dependency> <dependency> <groupId>com.example.MyLibrary</groupId> <artifactId>MyLibrary</artifactId> <version>1.0.0</version> </dependency>
MyApp reads the configuration file, which is passed as a command line argument. The configuration file contains the name of the class located in MyLibrary . So the class could be com.mypackage.driver.MyClass , which is in MyLibrary , which is a dependency of the MyApp jar listed above. However, when I try to run this, I get a ClassNotFoundException ...
Update ---- I use the system class loader to load classes that are passed on the command line for MyApp
ClassLoader loader = ClassLoader.getSystemClassLoader();
I think this is causing the problem as it is looking for default classes that do not contain dependencies.
Any hints that I'm doing wrong here?
Barry source share