eclipse已经有内置maven,要使用最新maven的话下载后在Preferences->Maven->Installations里设置新的maven。

eclipse中使用 maven Srping

然后再去User Setttings里面做设置, Local Repository 的位置可以在settings.xml里设置。

<localRepository>D:/Programs/apache-maven-3.5.2/mvn</localRepository>

eclipse中使用 maven Srping

    maven设置好后,就可以通过File->New->Project->maven->Maven Project 新建maven支持的project。

 

在eclipse中安装 STS,可以去spring网站上找到最新STS插件的地址,https://spring.io/tools/sts/all/,直接安装即可。

File->New->Project->Spring->Spring Legacy Project。有 Srping MVC Project,  Simple Spring maven,

Simple Spring Web  maven

 

eclipse中使用 maven Srping

 

Simple Srping Maven如下,spring的xml配置文件要放在 src/main/resources下面。 Maven定义了一些best practice, 所以有些目录和路径默认就定死了。

命令也是定死的,比如 mvn package, mvn clean, mvn build用来简化使用maven。

 

eclipse中使用 maven Srping

 

maven的使用,

maven默认打包只把你自己的源代码和资源打进去,其余依赖的包都不会做处理,下面的博客简述了把所有依赖jar包都放到某一个目录下,

然后通过包含jar包目录运行即可。

java -Djava.ext.dirs=./dependency -cp HelloSpring-0.0.1-SNAPSHOT.jar XmlJavaConfigCtx.BluePlayerMain

 

打包命令

mvn dependency:copy-dependencies -DoutputDirectory=lib -DincludeScope=compile

elicpse中打包 run as->maven build ,  然后在goals里面填入 dependency:copy-dependencies即可。

所有依赖jar包都会在target/dependency  目录下。关于maven lifecyble,phase,goals具体解释可以

见这个文章, http://blog.csdn.net/bluishglc/article/details/6632280

http://blog.csdn.net/onlyqi/article/details/6801318

eclipse中使用 maven Srping

 

mvn compile

mvn test   (mvn -Dtest=soundsystem.CDPlayerTest test) 具体执行某个JUnit测试。

mvn package

mvn dependency:copy-dependencies

 

eclipse maven 导出项目依赖的jar包

http://blog.csdn.net/andyliulin/article/details/46544555

maven导出Jar包,包括所有依赖的jar,在pom.xml加入以下配置,

maven build ,然后maven install之后,会在target目录下生成 ,

overview01-0.0.1-SNAPSHOT.jar      //不包含依赖的jar包,

overview01-0.0.1-SNAPSHOT-jar-with-dependencies.jar  //所有的依赖jar包已经项目源代码全部包含在这个jar包,类似war包,部署非常方便。

 

 <!-- Maven Assembly Plugin -->
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <executions>
                    <execution>
                        <id>copy-dependencies</id>
                        <phase>package</phase>
                        <goals>
                            <goal>copy-dependencies</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>${project.build.directory}/lib</outputDirectory>
                            <overWriteReleases>false</overWriteReleases>
                            <overWriteSnapshots>false</overWriteSnapshots>
                            <overWriteIfNewer>true</overWriteIfNewer>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <artifactId>maven-assembly-plugin</artifactId>
                <configuration>
                    <archive>
                        <manifest>

                          <!--这个是唯一需要修改的,修改成你程序的启动入口class-->
                            <mainClass>com.starlink.test.mybatis.overview01.App</mainClass>
                        </manifest>
                        <manifestEntries>
                            <Class-Path>.</Class-Path>
                        </manifestEntries>
                    </archive>
                    <descriptorRefs>
                        <descriptorRef>jar-with-dependencies</descriptorRef>
                    </descriptorRefs>
                </configuration>
                <executions>
                    <execution>
                        <id>make-assembly</id>
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

 

 

 

相关文章:

  • 2021-06-18
  • 2021-10-19
  • 2021-04-03
  • 2021-11-03
  • 2022-12-23
  • 2021-12-23
  • 2021-09-05
猜你喜欢
  • 2021-05-20
  • 2021-03-31
  • 2022-12-23
  • 2021-12-04
  • 2021-06-06
  • 2021-05-05
相关资源
相似解决方案