导入java spring项目后如何构建maven [英] How to build maven after importing an java spring project
问题描述
所以我已经安装了maven并将maven依赖项添加到项目中,但我在java构建路径中出现错误,因为缺少spring框架。可以帮助我从这里..
Blockquote
告诉我如何添加maven依赖关系对于进口的java spring项目
我的程序文件
package java4s ;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
public class ClientLogic {
public static void main(String [] args)
{
资源res =新的ClassPathResource(spconfig.xml );
BeanFactory factory = new XmlBeanFactory(res);
Object o = factory.getBean(id1);
WelcomeBean wb =(WelcomeBean)o;
wb.show();
}
}
<!DOCTYPE beans PUBLIC - // SPRING // DTD BEAN 2.0 // EN
http://www.springframework.org/dtd/spring-beans-2.0.dtd\">
< beans>
< bean id =id1class =java4s.WelcomeBean>
< property name =messagevalue =欢迎来到春天/>
< / bean>
< / beans>
这是我的文件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/xsd/maven-4.0.0.xsd\">
> < modelVersion> 4.0.0< / modelVersion>
> <&的groupId GT;弹簧你好-世界< /&的groupId GT;
> < artifactId的>弹簧你好-世界< / artifactId的>
> <版本> 0.0.1-快照LT; /版本> <依赖性> <依赖性>
> <&的groupId GT; com.force.sdk< /&的groupId GT;
> < artifactId的>力springsecurity< / artifactId的>
> <版本> 22.0.9-BETA< /版本>
> <类型>罐子< /类型>
> <范围>编译< /范围> < /依赖性> < /依赖性> < /项目> <依赖性>
>
> < /依赖性>
进一步我可以在这里添加什么样的依赖关系现在我已经开始使用弹簧
我也是新的,为什么我可以说你可以使用你的pom.xml添加所需的所有依赖项。
例如,如果您需要添加弹簧上下文,您可以只写它的名称和版本。 Maven认为如何查找和导入它。
示例的语法是:
<依赖性>
< groupId> org.springframework< / groupId>
< artifactId> spring-context< / artifactId>
< version> 3-0< / version>
< / dependency>
对于您需要的每一个依赖,只需写入groupId,artifactID和版本,依赖关系
标签和maven将会考虑一切。
因此,您将在pom.xml中列出这些依赖标记。
此外,不要忘记Maven使用其结构;)
Hello i am new to java spring concepts . .so i downloaded a sample spring application and import that into eclipse ..i have read from spring tutorials either i have to install maven into eclipse to run spring projects ..
so i have installed maven and add a maven dependency pom.xml file into project but i got error in java build path as missing spring framework..can any one help me out from here ..
Blockquote
Tell me how to add maven dependency for a imported java spring project
MY program file
package java4s;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
public class ClientLogic {
public static void main(String[] args)
{
Resource res = new ClassPathResource("spconfig.xml");
BeanFactory factory = new XmlBeanFactory(res);
Object o = factory.getBean("id1");
WelcomeBean wb = (WelcomeBean)o;
wb.show();
}
}
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN"
"http://www.springframework.org/dtd/spring-beans-2.0.dtd">
<beans>
<bean id="id1" class="java4s.WelcomeBean">
<property name="message" value="Welcome to spring" />
</bean>
</beans>
This is my file 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/xsd/maven-4.0.0.xsd">
> <modelVersion>4.0.0</modelVersion>
> <groupId>Spring-Hello-World</groupId>
> <artifactId>Spring-Hello-World</artifactId>
> <version>0.0.1-SNAPSHOT</version> <dependencies> <dependency>
> <groupId>com.force.sdk</groupId>
> <artifactId>force-springsecurity</artifactId>
> <version>22.0.9-BETA</version>
> <type>jar</type>
> <scope>compile</scope> </dependency> </dependencies> </project> <dependency>
>
> </dependency>
Further what kind of dependency i can add here..just now i have started working with springs
I'm new too and for what I can say you can use your pom.xml to add all the dependencies that you need. For example, if you need to add spring context, you can just write its name and version. Maven thinks of how to find and import it.
The syntax of the example is:
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>3-0</version>
</dependency>
For every dependence that you need, just write is groupId, artifactID and version, within the dependency
tag and maven will think of everything.
Hence you will have a list of these dependency tags in the pom.xml.
Moreover, don't forget Maven use its structure ;)
这篇关于导入java spring项目后如何构建maven的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!