ClassNotFound异常:Eclipse中的Maven无法正常工作

时间:2017-04-25 07:21:07

标签: java eclipse maven m2eclipse m2e

我有以下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>my.org</groupId>
    <artifactId>project</artifactId>
    <packaging>${packaging.type}</packaging>
    <version>1.0-SNAPSHOT</version>
    <name>My Project Name</name>
    <profiles>
        <profile>
            <id>dev</id>
            <properties>
                <packaging.type>war</packaging.type>
                <outputFileNameMapping>@{artifactId}@.@{extension}@</outputFileNameMapping>
            </properties>
        </profile>
        <profile>
            <id>uat</id>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
            <properties>
                <packaging.type>jar</packaging.type>
                <outputFileNameMapping>@{artifactId}@.@{extension}@.@{version}@</outputFileNameMapping>
            </properties>
        </profile>
    </profiles>
    <build>
        <finalName>My Project Name</finalName>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <version>3.0.0</version>
                <configuration>
                    <outputFileNameMapping>${outputFileNameMapping}</outputFileNameMapping>
                    <archive>
                        <manifestFile>src/main/webapp/META-INF/MANIFEST.MF</manifestFile>
                    </archive>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

我收到的错误如java.lang.ClassNotFoundException

我猜我在Eclipse中的项目根本没有加载任何Maven依赖项。

如果我从命令行运行相同的项目,那么它的工作。

但如果我删除了以下行,那么它在Eclipse中完美运行。

<outputFileNameMapping>${outputFileNameMapping}</outputFileNameMapping>

有人可以帮忙吗?

我的Eclipse版

面向Web开发人员的Eclipse Java EE IDE。 版本:Luna Service Release 2(4.4.2) 构建ID:20150219-0600

编辑:添加堆栈跟踪

Apr 25, 2017 12:38:35 PM org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:edte' did not find a matching property.
Apr 25, 2017 12:38:35 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Server version:        Apache Tomcat/7.0.64
Apr 25, 2017 12:38:35 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Server built:          Aug 19 2015 17:18:06 UTC
Apr 25, 2017 12:38:35 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Server number:         7.0.64.0
Apr 25, 2017 12:38:35 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: OS Name:               Linux
Apr 25, 2017 12:38:35 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: OS Version:            4.8.10-040810-generic
Apr 25, 2017 12:38:35 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Architecture:          amd64
Apr 25, 2017 12:38:35 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Java Home:             /usr/lib/jvm/java-8-openjdk-amd64/jre
Apr 25, 2017 12:38:35 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: JVM Version:           1.8.0_121-8u121-b13-0ubuntu1.16.04.2-b13
Apr 25, 2017 12:38:35 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: JVM Vendor:            Oracle Corporation
Apr 25, 2017 12:38:35 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: CATALINA_BASE:         /var/tmp/projects/edte/.metadata/.plugins/org.eclipse.wst.server.core/tmp0
Apr 25, 2017 12:38:35 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: CATALINA_HOME:         /home/bhushanp/workspace/apache-tomcat-7.0.64
Apr 25, 2017 12:38:35 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -agentlib:jdwp=transport=dt_socket,suspend=y,address=localhost:35365
Apr 25, 2017 12:38:35 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dcatalina.base=/var/tmp/projects/edte/.metadata/.plugins/org.eclipse.wst.server.core/tmp0
Apr 25, 2017 12:38:35 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dcatalina.home=/home/bhushanp/workspace/apache-tomcat-7.0.64
Apr 25, 2017 12:38:35 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dwtp.deploy=/var/tmp/projects/edte/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps
Apr 25, 2017 12:38:35 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Djava.endorsed.dirs=/home/bhushanp/workspace/apache-tomcat-7.0.64/endorsed
Apr 25, 2017 12:38:35 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dfile.encoding=UTF-8
Apr 25, 2017 12:38:35 PM org.apache.catalina.core.AprLifecycleListener lifecycleEvent
INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: /usr/java/packages/lib/amd64:/usr/lib/x86_64-linux-gnu/jni:/lib/x86_64-linux-gnu:/usr/lib/x86_64-linux-gnu:/usr/lib/jni:/lib:/usr/lib
Apr 25, 2017 12:38:35 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-bio-8330"]
Apr 25, 2017 12:38:35 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["ajp-bio-8339"]
Apr 25, 2017 12:38:35 PM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 968 ms
Apr 25, 2017 12:38:35 PM org.apache.catalina.core.StandardService startInternal
INFO: Starting service Catalina
Apr 25, 2017 12:38:35 PM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/7.0.64
Apr 25, 2017 12:38:36 PM org.apache.catalina.startup.TldConfig execute
INFO: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
Apr 25, 2017 12:38:37 PM org.apache.catalina.startup.TldConfig execute
INFO: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
Apr 25, 2017 12:38:37 PM org.apache.catalina.core.StandardContext listenerStart
SEVERE: Error configuring application listener of class org.zkoss.zk.ui.http.HttpSessionListener
java.lang.ClassNotFoundException: org.zkoss.zk.ui.http.HttpSessionListener
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1858)
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1709)
    at org.apache.catalina.core.DefaultInstanceManager.loadClass(DefaultInstanceManager.java:506)
    at org.apache.catalina.core.DefaultInstanceManager.loadClassMaybePrivileged(DefaultInstanceManager.java:488)
    at org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:115)
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4919)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5517)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1574)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1564)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)

Apr 25, 2017 12:38:37 PM org.apache.catalina.core.StandardContext listenerStart
SEVERE: Skipped installing application listeners due to previous error(s)
Apr 25, 2017 12:38:37 PM org.apache.catalina.core.StandardContext startInternal
SEVERE: One or more listeners failed to start. Full details will be found in the appropriate container log file
Apr 25, 2017 12:38:37 PM org.apache.catalina.core.StandardContext startInternal
SEVERE: Context [/edte] startup failed due to previous errors
Apr 25, 2017 12:38:37 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-bio-8330"]
Apr 25, 2017 12:38:37 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["ajp-bio-8339"]
Apr 25, 2017 12:38:37 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 1814 ms

另外,我已经为类'org.zkoss.zk.ui.http.HttpSessionListener'添加了依赖项,但它仍然给了我这个错误。

我的pom.xml

1 个答案:

答案 0 :(得分:0)

尝试从命令提示符编译代码,如果您得到相同的错误,则表示缺少依赖项。如果它工作正常,你需要执行mvn eclipse:eclipse,并刷新你的项目