You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by Baha Baniya <ba...@yahoo.com.INVALID> on 2018/07/12 12:24:04 UTC

Could not run main class in src/test/java due to ClassNotFoundException

Hi
When I run mvn exec:java : 
I get error:
java.lang.ClassNotFoundException: np.com.bahadur.ExecTest    at java.net.URLClassLoader.findClass (URLClassLoader.java:381)    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:270)    at java.lang.Thread.run (Thread.java:748)




pom.xml 
<?xml version="1.0" encoding="UTF-8"?><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>replicate</groupId> <artifactId>exec-sample</artifactId> <version>1.1.0-SNAPSHOT</version>
 <name>Baha Replicate</name> <description>replicate exec</description>

 <build> <plugins>
 <plugin> <artifactId>maven-compiler-plugin</artifactId> <version>3.7.0</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.6.0</version> <executions> <execution> <id>generate-test-json-data</id> <phase>generate-test-resources</phase> <goals> <goal>java</goal> </goals> </execution> </executions> <configuration> <mainClass>np.com.bahadur.ExecTest</mainClass> <classpathScope>test</classpathScope> </configuration> </plugin> </plugins> </build>
</project>


project structure 



Full project here baha_baniya / exec-maven-plugin-sample / source / — Bitbucket


| 
| 
|  | 
baha_baniya / exec-maven-plugin-sample / source / — Bitbucket


 |

 |

 |



How to fix this issue?

Regards,
Baha 

Re: Could not run main class in src/test/java due to ClassNotFoundException

Posted by Baha Baniya <ba...@yahoo.com.INVALID>.
Thank you for the Response, Tommy. I already had a classpathScope test as shown in baha_baniya / exec-maven-plugin-sample / source / pom.xml — Bitbucket.

| 
| 
|  | 
baha_baniya / exec-maven-plugin-sample / source / pom.xml — Bitbucket


 |

 |

 |





Just figured out - I have to run class after test-compile phase in which phase test classes are generated. Bound exec:java  to  process-test-classes (previously it was  process-test-resources) and it worked. 




Regards,
Baha 
 

    On Friday, 13 July 2018, 1:25:51 am AEST, Tommy Svensson <to...@natusoft.se> wrote:  
 
 #yiv7925638447 body{font-family:Helvetica, Arial;font-size:13px;}Hello Baha,
You need a dependency to a jar containing the `np.com.bahadur.ExecTest` class.
According to: https://www.mojohaus.org/exec-maven-plugin/java-mojo.html the dependency should have scope ’runtime’ unless you set the ’classpathScope’ parameter to something else. 
Your pom has no dependencies at all.
Regards,Tommy 
  
Från: Baha Baniya <ba...@yahoo.com.invalid>
Svara: Baha Baniya <ba...@yahoo.com>
Datum: 12 juli 2018 at 14:24:23
Till: users@maven.apache.org <us...@maven.apache.org>
Ämne:  Could not run main class in src/test/java due to ClassNotFoundException 

 
Hi
When I run mvn exec:java : 
I get error:
java.lang.ClassNotFoundException: np.com.bahadur.ExecTest    at java.net.URLClassLoader.findClass (URLClassLoader.java:381)    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:270)    at java.lang.Thread.run (Thread.java:748)




pom.xml 
<?xml version="1.0" encoding="UTF-8"?><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>replicate</groupId> <artifactId>exec-sample</artifactId> <version>1.1.0-SNAPSHOT</version>
 <name>Baha Replicate</name> <description>replicate exec</description>

 <build> <plugins>
 <plugin> <artifactId>maven-compiler-plugin</artifactId> <version>3.7.0</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.6.0</version> <executions> <execution> <id>generate-test-json-data</id> <phase>generate-test-resources</phase> <goals> <goal>java</goal> </goals> </execution> </executions> <configuration> <mainClass>np.com.bahadur.ExecTest</mainClass> <classpathScope>test</classpathScope> </configuration> </plugin> </plugins> </build>
</project>


project structure 



Full project here baha_baniya / exec-maven-plugin-sample / source / — Bitbucket


| 
| 
|  | 
baha_baniya / exec-maven-plugin-sample / source / — Bitbucket


 |

 |

 |



How to fix this issue?

Regards,
Baha 

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org
  

Re: Could not run main class in src/test/java due to ClassNotFoundException

Posted by Tommy Svensson <to...@natusoft.se>.
Hello Baha,

You need a dependency to a jar containing the `np.com.bahadur.ExecTest` class.

According to: https://www.mojohaus.org/exec-maven-plugin/java-mojo.html the dependency should have scope ’runtime’ unless you set the ’classpathScope’ parameter to something else. 

Your pom has no dependencies at all.

Regards,
Tommy


Från: Baha Baniya <ba...@yahoo.com.invalid>
Svara: Baha Baniya <ba...@yahoo.com>
Datum: 12 juli 2018 at 14:24:23
Till: users@maven.apache.org <us...@maven.apache.org>
Ämne:  Could not run main class in src/test/java due to ClassNotFoundException  

Hi

When I run mvn exec:java : 

I get error:

java.lang.ClassNotFoundException: np.com.bahadur.ExecTest
    at java.net.URLClassLoader.findClass (URLClassLoader.java:381)
    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:270)
    at java.lang.Thread.run (Thread.java:748)





pom.xml 

<?xml version="1.0" encoding="UTF-8"?>
<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>replicate</groupId>
    <artifactId>exec-sample</artifactId>
    <version>1.1.0-SNAPSHOT</version>

    <name>Baha Replicate</name>
    <description>replicate exec</description>


    <build>
        <plugins>

            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.7.0</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.6.0</version>
                <executions>
                    <execution>
                        <id>generate-test-json-data</id>
                        <phase>generate-test-resources</phase>
                        <goals>
                            <goal>java</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <mainClass>np.com.bahadur.ExecTest</mainClass>
                    <classpathScope>test</classpathScope>
                </configuration>
            </plugin>
        </plugins>
    </build>

</project>



project structure 




Full project here 
baha_baniya / exec-maven-plugin-sample / source / — Bitbucket

baha_baniya / exec-maven-plugin-sample / source /    — Bitbucket


How to fix this issue?


Regards,
Baha 


---------------------------------------------------------------------  
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org  
For additional commands, e-mail: users-help@maven.apache.org