maven命令

用maven创建jar工程:

 mvn archetype:create -DgroupId=com.mycompany.app \
                   -DartifactId=my-app

 创建war工程:

mvn archetype:create -DgroupId=com.mycompany.app -DartifactId=my-webapp 
-DarchetypeArtifactId=maven-archetype-webapp

 

运行之后maven会给你创建helloworld。

 

创建eclipse工程:

mvn eclipse:eclipse 

 

find dependency:

use http://mvnrepository.com/   to find correct groupId and artifactId.

 

dependency scope:

Dependency scope is used to limit the transitivity of a depedency, and also to affect the classpath used for various build tasks.

There are 6 scopes available:

  • compile
    This is the default scope, used if none is specified. Compile dependencies are available in all classpaths of a project. Furthermore, those dependencies are propagated to dependent projects.
  • provided
    This is much like compile , but indicates you expect the JDK or a container to provide the dependency at runtime. For example, when building a web application for the Java Enterprise Edition, you would set the dependency on the Servlet API and related Java EE APIs to scope provided because the web container provides those classes. This scope is only available on the compilation and test classpath, and is not transitive.
  • runtime
    This scope indicates that the dependency is not required for compilation, but is for execution. It is in the runtime and test classpaths, but not the compile classpath.
  • test
    This scope indicates that the dependency is not required for normal use of the application, and is only available for the test compilation and execution phases.
  • system
    This scope is similar to provided except that you have to provide the JAR which contains it explicitly. The artifact is always available and is not looked up in a repository.
  • import (only available in Maven 2.0.9 or later)
    This scope is only used on a dependency of type pom in the <dependencyManagement> section. It indicates that the specified POM should be replaced with the dependencies in that POM's <dependencyManagement> section. Since they are replaced, dependencies with a scope of import do not actually participate in limiting the transitivity of a dependency.

 

 

在 IntelliJ IDEA 中使用 Maven 命令窗口进行项目构建或依赖管理,可以通过以下方式操作: ### 使用 Maven 命令窗口 IntelliJ IDEA 提供了内置的 **Maven 工具窗口** 和 **终端(Terminal)**,可以用于执行 Maven 命令。以下是具体的操作方法: #### 1. 打开 Maven 工具窗口 - 在界面右侧找到并点击 **Maven** 标签,打开 Maven 工具窗口。 - 该窗口会列出当前项目的生命周期阶段(如 `clean`, `compile`, `package`, `install` 等),以及插件目标。 你可以通过双击某个生命周期阶段来直接运行对应的 Maven 命令。例如: - 双击 `clean` 来清理项目生成的编译文件。 - 双击 `compile` 来编译源代码。 - 双击 `package` 来打包项目为 JAR/WAR 文件。 - 双击 `install` 将项目安装到本地 Maven 仓库,以便其他项目依赖[^2]。 #### 2. 使用终端执行 Maven 命令 - 打开 **Terminal** 窗口(通常位于底部工具栏),它默认会在当前项目的根目录下运行命令。 - 输入标准的 Maven 命令,例如: ```bash mvn clean compile ``` 这将清理项目并重新编译源码。 常见构建与依赖管理命令包括: - 构建项目:`mvn clean package` - 安装到本地仓库:`mvn clean install` - 更新依赖:`mvn dependency:resolve` - 查看依赖树:`mvn dependency:tree` #### 3. 自定义 Maven 命令 - 在 Maven 工具窗口中,可以右键点击项目或模块,选择 **Run Maven > Generate Sources and Update Folders** 或 **Reimport** 来更新依赖和项目结构。 - 如果需要运行自定义命令,可以在 Terminal 中输入任意合法的 `mvn` 指令。 #### 4. 配置 Maven 环境 确保你的项目已经正确配置了 `pom.xml` 文件,并且 IntelliJ IDEA 的 Maven 设置指向了正确的全局设置文件(如 `settings.xml`)。你可以在 **Settings (Preferences)** > **Build, Execution, Deployment** > **Build Tools** > **Maven** 中查看和修改相关配置。 ---
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值