maven运行java项目

一、maven各个命令的区别:

1、maven clean 清空target下的文件
2、maven compile 编译(在target下生成.class文件)

一般使用:mvn clean package 先清缓存再打包
注意:如果使用的是Eclipse的maven插件,插件默认会加上maven前缀,如果你使用maven clean compile就会报错

错误提示:

Unknown lifecycle phase "maven". 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, process-test-resources, test-compile, process-test-classes, test, prepare-package, package, pre-integration-test, integration-test, post-integration-test, verify, install, deploy, pre-clean, clean, post-clean, pre-site, site, post-site, site-deploy. -> [Help 1]

解决方法:前面不加maven

3、maven install:将项目编译打包后放在本地仓库中供其他项目使用

1 [INFO] --- maven-install-plugin:2.4:install (default-install) @ upminterface ---
2 [INFO] Installing D:\eclipse workspace\UPMInterfaceV2\target\UPMInterfaceV2.war to D:\Program Files\Apache\maven-repository\com\ricninfo\upminterface\0.0.1-SNAPSHOT\upminterface-0.0.1-SNAPSHOT.war
3 [INFO] Installing D:\eclipse workspace\UPMInterfaceV2\pom.xml to D:\Program Files\Apache\maven-repository\com\ricninfo\upminterface\0.0.1-SNAPSHOT\upminterface-0.0.1-SNAPSHOT.pom

注意:install打包后,不仅在target下有jar,而且在本地仓库会有jar包供其他项目使用,依赖项目的jar会在本地仓库中进行读取或安装

4、maven package:把项目打包到target下

二、使用maven运行JAVA项目

1、右键pom.xml文件,选择maven build……

2、clean install

成功

3、运行jar

注意点:

1、配置文件需要打进 jar 包;
2、需要指定 main 入口类;
3、所依赖的第三方库也要打进 jar 包;

可能遇到的问题:

(1)到target目录cmd执行java -jar UPMInterfaceV2-sources.jar(这里对应你的jar包)

到你的MANIFEST.MF文件查看(位置:D:\eclipse workspace\UPMInterfaceV2\target\UPMInterfaceV2\META-INF请自行对应)

内容:

Manifest-Version: 1.0
Class-Path:

确实没有指出 main 入口类!

 

posted @ 2018-04-18 20:51  不是植物  阅读(930)  评论(0编辑  收藏  举报