线程主 - 异常依赖中的异常

时间:2015-05-20 20:02:47

标签: java spring maven pom.xml

public class BatchLauncherSpring {

    public static void main(String[] args) {

        ApplicationContext context = new ClassPathXmlApplicationContext(
                "application-context.xml");

        //////
    }
}

运行main方法时,我收到了ClassNotFoundException。 Spring依赖项是通过Maven添加的,这些依赖项在编译时解析。有很多类似的问题,但是当代码打包为jar并在eclipse之外执行时,每个人似乎都遇到了问题。当我在eclipse中运行它时,我实际上遇到了这个问题。

这是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/xsd/maven-4.0.0.xsd">

    <parent>
        <groupId>com.mycompany</groupId>
        <artifactId>mybatch</artifactId>
        <version>1.0.0-SNAPSHOT</version>
    </parent>

    <modelVersion>4.0.0</modelVersion>
    <groupId>com.mycompany</groupId>
    <artifactId>mybatchCore</artifactId>
    <version>1.0.0-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>mybatchCore</name>
    <url></url>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <spring.version>3.2.2.RELEASE</spring.version>
        <spring.batch.version>2.2.5.RELEASE</spring.batch.version>
    </properties>

    <dependencies>
        <dependency>
                <groupId>com.my.repo</groupId>
                <artifactId>spring-core</artifactId>
                <version>${spring.version}</version>
            </dependency>
            <dependency>
                <groupId>com.my.repo</groupId>
                <artifactId>spring-jdbc</artifactId>
                <version>${spring.version}</version>
            </dependency>
            <dependency>
                <groupId>com.my.repo</groupId>
                <artifactId>spring-oxm</artifactId>
                <version>${spring.version}</version>
            </dependency>
            <dependency>
                <groupId>com.my.repo</groupId>
                <artifactId>spring-batch-core</artifactId>
                <version>${spring.batch.version}</version>
            </dependency>
            <dependency>
                <groupId>com.my.repo</groupId>
                <artifactId>spring-batch-infrastructure</artifactId>
                <version>${spring.batch.version}</version>
            </dependency>


    </dependencies>

</project>

栈跟踪

  

java.lang.NoClassDefFoundError:   org / springframework / context / ApplicationContext引起:   抛出java.lang.ClassNotFoundException:   org.springframework.context.ApplicationContext at   java.net.URLClassLoader $ 1.run(URLClassLoader.java:200)at   java.security.AccessController.doPrivileged(Native Method)at   java.net.URLClassLoader.findClass(URLClassLoader.java:188)at   java.lang.ClassLoader.loadClass(ClassLoader.java:307)at   sun.misc.Launcher $ AppClassLoader.loadClass(Launcher.java:301)at at   java.lang.ClassLoader.loadClass(ClassLoader.java:252)at   java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)   线程“main”中的异常

这是什么问题?谢谢!

2 个答案:

答案 0 :(得分:1)

你需要spring-context依赖 快乐的编码

答案 1 :(得分:0)

如果没有堆栈跟踪,我们只能猜测,但是弹出给我的第一件事就是你将它用于springId的groupId:com.my.repo。那应该是org.springframework

我不确定这是怎么编译的。