【问题标题】:maven exec plugin : org.apache.maven.plugin.MojoExecutionException and ClassNotFoundExceptionmaven exec 插件:org.apache.maven.plugin.MojoExecutionException 和 ClassNotFoundException
【发布时间】:2012-09-13 11:57:08
【问题描述】:

执行 maven 程序时出现异常。 我正在使用 Maven 2.2 使用 maven 执行类时出现此异常。 这是我的 pom.xml

<modelVersion>4.0.0</modelVersion>
<groupId>com.infrasoft.ibs.retail</groupId>
<artifactId>ibs-project</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>ibs-project</name>

<properties>

    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

    <dependencies>
    <dependency>
        <groupId>org.apache.shiro</groupId>
        <artifactId>shiro-core</artifactId>
        <version>1.2.1</version>
    </dependency>

    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-simple</artifactId>
        <version>1.6.4</version>
        <scope>test</scope>
    </dependency>
</dependencies>
<build>
    <plugins>
         <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>2.0.2</version>
            <configuration>
                <source>1.5</source>
                <target>1.5</target>
                <encoding>${project.build.sourceEncoding}</encoding>
            </configuration>
        </plugin>

        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>exec-maven-plugin</artifactId>
            <version>1.1</version>
            <executions>
                <execution>
                    <goals>
                        <goal>java</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <classpathScope>test</classpathScope>
                <mainClass>ShiroDemo</mainClass>
            </configuration>
        </plugin>

    </plugins>
</build>

   StackTrace is 
  org.apache.maven.lifecycle.LifecycleExecutionException: An exception occured whi
 le executing the Java class. ShiroDemo
    at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(Defa
 ultLifecycleExecutor.java:719)
    at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeStandalone
 Goal(DefaultLifecycleExecutor.java:569)
    at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoal(Defau
 ltLifecycleExecutor.java:539)
    at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalAndHan
 dleFailures(DefaultLifecycleExecutor.java:387)
    at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegmen
  ts(DefaultLifecycleExecutor.java:348)
    at org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLi
 fecycleExecutor.java:180)
    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:328)
    at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:138)
    at org.apache.maven.cli.MavenCli.main(MavenCli.java:362)
    at org.apache.maven.cli.compat.CompatibleMain.main(CompatibleMain.java:6
  0)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
      java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
   sorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.codehaus.classworlds.Launcher.launchEnhanced(Launcher.java:315)
    at org.codehaus.classworlds.Launcher.launch(Launcher.java:255)
    at org.codehaus.classworlds.Launcher.mainWithExitCode(Launcher.java:430)

    at org.codehaus.classworlds.Launcher.main(Launcher.java:375)
      Caused by: org.apache.maven.plugin.MojoExecutionException: An exception occured
    while executing the Java class. ShiroDemo
    at org.codehaus.mojo.exec.ExecJavaMojo.execute(ExecJavaMojo.java:345)
    at org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPlugi
      nManager.java:490)
    at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(Defa
      ultLifecycleExecutor.java:694)
    ... 17 more
      Caused by: java.lang.ClassNotFoundException: ShiroDemo
    at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:188)

请帮忙,可能是什么原因? 提前致谢

编辑

好的,当我删除时

   <configuration>
            <classpathScope>test</classpathScope>
            <mainClass>ShiroDemo</mainClass>
        </configuration>

来自 pom.xml 并使用以下命令执行它可以正常工作。 mvn compile exec:java -Dexec.mainClass="org.sample.test.ShiroDemo" -e

【问题讨论】:

  • 请在此处粘贴异常。如果您不首先向我们展示问题是什么,我们应该如何帮助您?你用 Maven 做什么?你的异常的堆栈跟踪是什么?这些是最基本的信息,没有这些信息是不可能回答你的问题的。你不这么认为吗?
  • 我将粘贴堆栈跟踪。请不要问诸如“您使用 maven 做什么?”之类的幼稚问题。如果您能在这里贡献您的知识,我将不胜感激。
  • 适合自己。我只是想帮忙
  • 我猜这是因为您已将classpathScope 设置为测试。删除该行,看看它是否有效。
  • 您好,感谢您的回复,但即使删除该行,它也会出现同样的错误。

标签: maven-2


【解决方案1】:

您不需要指定 -Dexec.mainClass。你得到了正确的配置,只是不在 pom.xml 中。将其更改为以下内容:

<mainClass>org.sample.test.ShiroDemo</mainClass>

【讨论】:

    猜你喜欢
    • 2017-05-11
    • 2018-07-10
    • 2015-07-29
    • 2015-02-04
    • 1970-01-01
    • 2018-04-12
    • 2018-12-25
    • 2016-12-08
    • 2016-03-08
    相关资源
    最近更新 更多