您的位置:58编程 > 怎么把maven项目部署到tomcat Maven教程 - 如何将您的项目安装到Maven本地存储库

怎么把maven项目部署到tomcat Maven教程 - 如何将您的项目安装到Maven本地存储库

2023-05-18 15:33 Maven教程

怎么把maven项目部署到tomcat Maven教程 - 如何将您的项目安装到Maven本地存储库

怎么把maven项目部署到tomcat Maven教程 - 如何将您的项目安装到Maven本地存储库

怎么把maven项目部署到tomcat

Maven教程 - 如何将您的项目安装到Maven本地存储库


当构建软件时,我们经常需要创建一些库来收集所有的函数和类在共同的一起,把编译的库文件建立路径,使编译器可以找到库编译代码时。

在Java中,这通常意味着创建一个具有库类的jar文件。

在Maven中,我们可以使用“mvn install"打包项目并自动部署到本地存储库。

当执行“安装"阶段时,将执行其之前的所有阶段,例如“验证",“编译",“测试",“封装",“积分测试",“验证"阶段。 之后这些阶段将执行安装阶段。



mvn安装示例

以下代码显示了从maven生成的POM文件。

<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/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.java2s.ide</groupId>
  <artifactId>xmlFileEditor</artifactId>
  <packaging>jar</packaging>
  <version>1.0-SNAPSHOT</version>
  <name>xmlFileEditor</name>
  <url>http://maven.apache.org</url>
  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
  </dependencies>
</project>

基于上面的pom.xml文件,当执行“mvn install"时,它会将项目打包到jar文件中并复制到本地存储库。

它总是建议运行“干净"和“安装"在一起,以便你总是部署最新的项目到本地存储库。

mvn clean install

上述命令生成以下结果。

c:mvn_testxmlFileEditor>mvn clean install
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building xmlFileEditor 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ xmlFileEditor ---
[INFO] Deleting c:mvn_testxmlFileEditortarget
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ xmlFileEditor ---
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory c:mvn_testxmlFileEditorsrcmainresources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ xmlFileEditor ---
[INFO] Changes detected - recompiling the module!
[WARNING] File encoding has not been set, using platform encoding Cp1252, i.e. build is platform dependent!
[INFO] Compiling 1 source file to c:mvn_testxmlFileEditortargetclasses
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ xmlFileEditor ---
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory c:mvn_testxmlFileEditorsrctestresources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ xmlFileEditor ---
[INFO] Changes detected - recompiling the module!
[WARNING] File encoding has not been set, using platform encoding Cp1252, i.e. build is platform dependent!
[INFO] Compiling 3 source files to c:mvn_testxmlFileEditortargettest-classes
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ xmlFileEditor ---
[INFO] Surefire report directory: c:mvn_testxmlFileEditortargetsurefire-reports

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running com.java2s.ide.AppTest
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0 sec
Running com.java2s.ide.TestApp1
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0 sec
Running com.java2s.ide.TestApp2
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0 sec

Results :

Tests run: 3, Failures: 0, Errors: 0, Skipped: 0

[INFO]
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ xmlFileEditor ---
[INFO] Building jar: c:mvn_testxmlFileEditortargetxmlFileEditor-1.0-SNAPSHOT.jar
[INFO]
[INFO] --- maven-install-plugin:2.4:install (default-install) @ xmlFileEditor ---
[INFO] Installing c:mvn_testxmlFileEditortargetxmlFileEditor-1.0-SNAPSHOT.jar to C:Usersabc.m2repositorycomjava2sidexmlFileEditor1.0-SNAPSHOTxmlFileEditor-1.0-SNAPSHOT.jar
[INFO] Installing c:mvn_testxmlFileEditorpom.xml to C:Usersabc.m2repositorycomjava2sidexmlFileEditor1.0-SNAPSHOTxmlFileEditor-1.0-SNAPSHOT.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 6.250 s
[INFO] Finished at: 2014-11-22T10:27:10-08:00
[INFO] Final Memory: 27M/369M
[INFO] ------------------------------------------------------------------------
c:mvn_testxmlFileEditor>

我们可以在我们的本地maven存储库中查看已安装的jar文件。

null


mvn安装示例...

将jar文件安装到本地存储库之后我们通过在它们的pom.xml文件中声明以下相关性标记来访问我们部署的“jar"文件。

 

<dependency>
      <groupId>com.java2s.ide</groupId>
      <artifactId>xmlFileEditor</artifactId>
      <version>1.0-SNAPSHOT</version>
</dependency>

阅读全文
以上是58编程为你收集整理的怎么把maven项目部署到tomcat Maven教程 - 如何将您的项目安装到Maven本地存储库全部内容。
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。
相关文章
© 2024 58编程 58biancheng.com 版权所有 联系我们
桂ICP备12005667号-32 Powered by CMS