1

I am trying to build my maven project, however I am getting the following exception:

java.lang.ClassNotFoundException: com.example.message.Main at java.net.URLClassLoader$1.run(URLClassLoader.java:372) at java.net.URLClassLoader$1.run(URLClassLoader.java:361) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:360) at java.lang.ClassLoader.loadClass(ClassLoader.java:424) at java.lang.ClassLoader.loadClass(ClassLoader.java:357) at org.codehaus.mojo.exec.ExecJavaMojo$1.run(ExecJavaMojo.java:281) at java.lang.Thread.run(Thread.java:745) 

My POM file is below. I have ensured that the package name is included within the <mainClass> tag. But it stil cannot find the class?

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.example</groupId> <artifactId>message</artifactId> <version>0.0.1-SNAPSHOT</version> <build> <plugins> <plugin> <artifactId>maven-compiler-plugin</artifactId> <version>3.1</version> <configuration> <source>1.8</source> <target>1.8</target> </configuration> </plugin> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>exec-maven-plugin</artifactId> <version>1.3.2</version> <executions> <execution> <goals> <goal>java</goal> </goals> </execution> </executions> <configuration> <mainClass>com.example.message.Main</mainClass> <arguments> <argument>AddTrial</argument> </arguments> </configuration> </plugin> </plugins> </build> <dependencies> <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-core</artifactId> <version>4.3.8.Final</version> </dependency> <dependency> <groupId>postgresql</groupId> <artifactId>postgresql</artifactId> <version>9.1-901-1.jdbc4</version> </dependency> </dependencies> </project> 
5
  • What Maven command line are you using to build and run this project? Commented Feb 15, 2015 at 13:41
  • I am using eclipse. Right Click project -> Run as Maven build -> Goals= exec:java Commented Feb 15, 2015 at 13:42
  • Right, you need to build it (within Maven) first. Try goals of "install exec:java" Commented Feb 15, 2015 at 13:43
  • Thanks for that, it is now working! Post it as an answer and I will accept Commented Feb 15, 2015 at 13:47
  • Great! Have posted below. Commented Feb 15, 2015 at 13:57

1 Answer 1

4

You need to make sure you're building a Maven project before running any plugin goals that rely on the compiled classes being available (like exec:java).

In this case, it should be as simple as running

mvn install exec:java 

or the equivalent goals from your IDE.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.