maven工程里编译运行main函数出错:“ You must specify a valid lifecycle phase or a goal in the format”

来源:互联网 发布:淘宝详情页主图尺寸 编辑:程序博客网 时间:2024/06/08 15:44

命令行编译Maven工程时碰到如下错误,先记录下解决方案:

***************************************************************************************************************************************************************************************

。。。

[ERROR] Unknown lifecycle phase "/home/tucson/Projects/kafkaGuideTest/target/Getting-Started-0.0.1-SNAPSHOT.jar". You must specify a valid lifecycle phase or a goal in the format <plugin-prefix>:<goal> or <plugin-group-id>:<plugin-artifact-id>[:<plugin-version>]:<goal>. Available lifecycle phases are: validate, initialize, generate-sources, process-sources, generate-resources, process-resources, compile, process-classes, generate-test-sources, process-test-sources, generate-test-resources, p rocess-test-resources, test-compile, process-test-classes, test, prepare-package, package, pre-integration-test, integration-test, post-integration-test, verify, install, deploy, pre-site, site, post-site, site-deploy, pre-clean, clean, post-clean. -> [Help 1]

[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/LifecyclePhaseNotFoundException
...
[INFO] ------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------
[INFO] Total time: 2.436s
[INFO] Finished at: Tue Jan 20 10:09:13 CST 2015
[INFO] Final Memory: 10M/101M
[INFO] ------------------------------------------------------------
[WARNING] The requested profile "dev" could not be activated becaus
[ERROR] Failed to execute goal org.codehaus.mojo:exec-maven-plugin:  exception occured while executing the Java class. backtype/storm/spo
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven wit
[ERROR] Re-run Maven using the -X switch to enable full debug loggi
[ERROR]
[ERROR] For more information about the errors and possible solution
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/M

***************************************************************************************************************************************************************************************

解决方案:

在maven工程里运行Java main方法是通过Maven的exec插件以命令行方式运行。

在运行前,你需要先编译代码,记住exec:java不会自动为你编译代码,你需要先编译。

 mvn compile   

编译完之后如下命令运行你的class

 mvn exec:java -Dexec.mainClass="com.vineetmanohar.module.Main"    

如果需要添加参数

 mvn exec:java -Dexec.mainClass="com.vineetmanohar.module.Main" -Dexec.args="arg0 arg1 arg2"  


附注:


1. maven的编译依赖范围:
   compile:默认使用该依赖,对编译,测试,运行三种classpath 都有效
   test: 只对测试时有效,如junit (在dependency中,当<scope>为test时,说明该依赖包只会加入到测试代码中去)
   provided:在运行时无效,对编译和测试有效,如servlet-api
   runtime:如JDBC,对测试和运行有效,在编译时无效

2.一个对传递性依赖的排除

示例2.1:表示虽然依赖project-a,但是不想依赖a所依赖的b

    <dependency>  
      <groupId>org.sonatype.mavenbook</groupId>  
      <artifactId>project-a</artifactId>  
      <version>1.0</version>  
      <exclusions>  
        <exclusion>  
          <groupId>org.sonatype.mavenbook</groupId>  
          <artifactId>project-b</artifactId>  
        </exclusion>  
      </exclusions>  
    </dependency> 

示例2.2:排除一个依赖, 添加另外一个依赖:

    <dependency>  
        <groupId>org.hibernate</groupId>  
        <artifactId>hibernate</artifactId>  
        <version>3.2.5.ga</version>  
        <exclusions>  
          <exclusion>  
            <groupId>javax.transaction</groupId>  
            <artifactId>jta</artifactId>  
          </exclusion>  
        </exclusions>  

      </dependency>  
      <dependency>  
        <groupId>org.apache.geronimo.specs</groupId>  
        <artifactId>geronimo-jta_1.1_spec</artifactId>  
        <version>1.1</version>  
      </dependency>  

      使用排除依赖, 一般是一个传递依赖在编译的时候需要, 但是在实际运行环境不需要的时候



0 0
原创粉丝点击