简体   繁体   English

Spring MVC Maven-添加库

[英]Spring mvc maven - adding libraries

I am creating a spring mvc application. 我正在创建一个Spring MVC应用程序。 I am came across maven recently and planning to use it with my current project. 我最近遇到过Maven,并计划在我当前的项目中使用它。

I have downloaded maven and configured it on my machine and using the command line interface. 我已经下载了maven并在我的机器上使用命令行界面对其进行了配置。

I created a project with following command: 我使用以下命令创建了一个项目:

mvn archetype:generate -DgroupId=com.priyank -DartifactId=SpringWebApp -DarchetypeArtifactId=maven-archetype-webapp -DinteractiveMode=false

After that I updated my pom.xml file with dependencies: 之后,我用依赖项更新了pom.xml文件:

<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.priyank</groupId>
 <artifactId>SpringWebApp</artifactId>
 <packaging>war</packaging>
 <version>1.0</version>
 <name>SpringWebApp Maven Webapp</name>
 <url>http://maven.apache.org</url>
 <dependencies>
<dependency>
  <groupId>junit</groupId>
  <artifactId>junit</artifactId>
  <version>3.8.1</version>
  <scope>test</scope>
</dependency>

<!-- Spring dependencies -->

<dependency>
  <groupId>org.springframework</groupId>
  <artifactId>spring-aop</artifactId>
  <version>4.1.4.RELEASE</version>
</dependency>

<dependency>
  <groupId>org.springframework</groupId>
  <artifactId>spring-aspects</artifactId>
  <version>4.1.4.RELEASE</version>
</dependency>

<dependency>
  <groupId>org.springframework</groupId>
  <artifactId>spring-beans</artifactId>
  <version>4.1.4.RELEASE</version>
</dependency>

<dependency>
  <groupId>org.springframework</groupId>
  <artifactId>spring-context</artifactId>
  <version>4.1.4.RELEASE</version>
</dependency>

<dependency>
  <groupId>org.springframework</groupId>
  <artifactId>spring-context-support</artifactId>
  <version>4.1.4.RELEASE</version>
</dependency>


<dependency>
  <groupId>org.springframework</groupId>
  <artifactId>spring-core</artifactId>
  <version>4.1.4.RELEASE</version>
</dependency>

<dependency>
  <groupId>org.springframework</groupId>
  <artifactId>spring-expression</artifactId>
  <version>4.1.4.RELEASE</version>
</dependency>

<dependency>
  <groupId>org.springframework</groupId>
  <artifactId>spring-instrument</artifactId>
  <version>4.1.4.RELEASE</version>
</dependency>

<dependency>
  <groupId>org.springframework</groupId>
  <artifactId>spring-instrument-tomcat</artifactId>
  <version>4.1.4.RELEASE</version>
</dependency>

<dependency>
  <groupId>org.springframework</groupId>
  <artifactId>spring-jdbc</artifactId>
  <version>4.1.4.RELEASE</version>
</dependency>

<dependency>
  <groupId>org.springframework</groupId>
  <artifactId>spring-jms</artifactId>
  <version>4.1.4.RELEASE</version>
</dependency>

<dependency>
  <groupId>org.springframework</groupId>
  <artifactId>spring-messaging</artifactId>
  <version>4.1.4.RELEASE</version>
</dependency>

<dependency>
  <groupId>org.springframework</groupId>
  <artifactId>spring-orm</artifactId>
  <version>4.1.4.RELEASE</version>
</dependency>

<dependency>
  <groupId>org.springframework</groupId>
  <artifactId>spring-oxm</artifactId>
  <version>4.1.4.RELEASE</version>
</dependency>

<dependency>
  <groupId>org.springframework</groupId>
  <artifactId>spring-test</artifactId>
  <version>4.1.4.RELEASE</version>
</dependency>

<dependency>
  <groupId>org.springframework</groupId>
  <artifactId>spring-tx</artifactId>
  <version>4.1.4.RELEASE</version>
</dependency>

<dependency>
  <groupId>org.springframework</groupId>
  <artifactId>spring-web</artifactId>
  <version>4.1.4.RELEASE</version>
</dependency>

<dependency>
  <groupId>org.springframework</groupId>
  <artifactId>spring-webmvc</artifactId>
  <version>4.1.4.RELEASE</version>
</dependency>

<dependency>
  <groupId>org.springframework</groupId>
  <artifactId>spring-webmvc-portlet</artifactId>
  <version>4.1.4.RELEASE</version>
</dependency>

<dependency>
  <groupId>org.springframework</groupId>
  <artifactId>spring-websocket</artifactId>
  <version>4.1.4.RELEASE</version>
</dependency>

<!-- hibernate dependencies -->
<dependency>
  <groupId>org.hibernate</groupId>
  <artifactId>hibernate-core</artifactId>
  <version>4.3.8.Final</version>
</dependency>

<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-entitymanager</artifactId>
    <version>4.3.8.Final</version>
</dependency>
 </dependencies>
 <build>
   <finalName>SpringWebApp</finalName>
 </build>
</project>

After updating pom.xml from my command line I executed: 从命令行更新pom.xml后,我执行了:

mvn install

which downloaded all dependencies in my local repo. 在我的本地仓库中下载了所有依赖项。

After that I converted it to my eclipse project using command: 之后,我使用命令将其转换为eclipse项目:

mvn eclipse:eclipse -Dwtpversion=2.0

Now after importing this project SpringWebApp in my workspace I can see libraries included in manner like this: 现在,在我的工作区中导入该项目SpringWebApp之后,我可以看到包含库的方式如下:

Eclipse Prjoect导航器

Usually when I create Spring mvc without maven, I put my libraries under WEB-INF\\lib folder. 通常,当我创建不带maven的Spring mvc时,我会将库放在WEB-INF \\ lib文件夹下。

I am confused here. 我在这里很困惑。 Seems I have done something wrong. 看来我做错了。 What is the right way to include this libraries in project? 在项目中包含此库的正确方法是什么?

PS: This added jre 1.4 as my runtime, but I have changed it to 1.7 PS:这将jre 1.4添加为我的运行时,但是我将其更改为1.7

I prefer use m2e plugin include in eclipse to make .classpath / .project and .settings of eclipse configuration then eclipse:eclipse goal. 我更喜欢使用eclipse中包含的m2e插件来使.classpath / .project和.settings成为eclipse配置,然后使eclipse:eclipse为目标。

When you configure eclipse project with m2e plugin classpath libraries is done like this: 当使用m2e插件配置eclipse项目时,类路径库是这样完成的: 在此处输入图片说明

And all dependencies are deploy in WEB-INF/lib automatically by eclipse and into war by maven-war-plugin. Eclipse会自动将所有依赖项部署在WEB-INF / lib中,并通过maven-war-plugin部署到war中。

to force use of specific version of java you need to specify version in configuration of maven-compiler-plugin like this: 要强制使用特定版本的Java,您需要在maven-compiler-plugin的配置中指定版本,如下所示:

<plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <configuration>
            <source>1.7</source>
            <target>1.7</target>
        </configuration>
</plugin>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM