使用Maven管理Java项目中的依赖
2017-02-03 01:43
585 查看
之前的博客里说以后学习在项目中使用Maven,说干就干。
创建Maven项目
填写项目相关信息
填写项目名称、包名、打包类型
项目创建成功的目录列表
保存后,MyEclipse会自动build项目
等到bulid过程结束,依赖项就可以用了
applicationContext.xml
运行结果:
完美。
MyEclipse集成Maven
可以参见http://huihai.iteye.com/blog/1993972,这里不再赘述。创建Maven项目
过程如下:创建Maven项目
填写项目相关信息
填写项目名称、包名、打包类型
项目创建成功的目录列表
使用添加Spring框架的依赖项
修改pom.xml文件,添加Spring依赖保存后,MyEclipse会自动build项目
等到bulid过程结束,依赖项就可以用了
测试代码
TestSpring.javapackage com.mrbcy.maven.firstmavenspring; import org.springframework.context.support.ClassPathXmlApplicationContext; import org.springframework.stereotype.Component; @Component public class TestSpring { public TestSpring(){ System.out.println("test spring 运行了"); } public static void main(String[] args) { new ClassPathXmlApplicationContext("applicationContext.xml"); } }
applicationContext.xml
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"> <context:component-scan base-package="com.mrbcy.maven.firstmavenspring"/> </beans>
运行结果:
二月 03, 2017 1:27:42 上午 org.springframework.context.support.ClassPathXmlApplicationContext prepareRefresh 信息: Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@3a6bf80b: startup date [Fri Feb 03 01:27:42 CST 2017]; root of context hierarchy 二月 03, 2017 1:27:42 上午 org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions 信息: Loading XML bean definitions from class path resource [applicationContext.xml] test spring 运行了
完美。
相关文章推荐
- 使用maven+eclipse+svn结合的方式管理多项目依赖
- 使用Maven管理Eclipse Java项目
- 使用Maven开发编译Java项目时如何将所有依赖jar包都打入war包
- 使用maven管理依赖,spring版本冲突解决 java.lang.NoSuchMethodError: org.springframework.core.GenericTypeResolver.r
- 使用IDEA+MAVEN管理项目依赖
- 使用 Maven管理Eclipse Java项目(转)
- 使用 Maven管理Eclipse Java项目(转)
- 使用Maven管理Eclipse Java项目
- Java - Maven项目打包成jar给第三方使用(带依赖打包)
- 在eclipse项目中使用maven管理依赖(转)
- 使用Maven管理Eclipse Java项目
- 使用Maven管理Eclipse Java项目
- 使用Maven管理Eclipse Java项目
- 使用Maven管理依赖JAR文件,自定义项目布局,利用ANT生成不同的发布包
- 使用Maven管理Eclipse Java项目
- 使用Maven管理 Eclipse Java项目
- 在eclipse项目中使用maven管理依赖
- MyEclipse&Maven项目管理教程:创建Java Maven依赖项目
- 使用Maven管理Java项目
- 使用maven来管理java项目