java - Maven编译失败(但Eclipse下编译成功)

标签 java eclipse maven-2

Eclipse 构建我的 Web 项目时,一切都很好:没有错误,没有警告

但是,在使用 Maven 构建项目时,它失败。下面是输出形式mvncompile:

c:\Users\jwa\Desktop\tets\traffic_web>mvn compile -e + Error stacktraces are turned on. [INFO] Scanning for projects... [INFO] ------------------------------------------------------------------------ [INFO] Building traffic_web [INFO]
task-segment: [compile] [INFO] ------------------------------------------------------------------------ [INFO] [resources:resources {execution: default-resources}] [WARNING] Using platform encoding (Cp1250 actually) to copy filtered resources, i.e. build is platform dependent! [INFO] skip non existing resourceDirectory c:\Users\jwa\Desktop\tets\traffic_web\src\main\resources [INFO] [compiler:compile {execution: default-compile}] [INFO] Compiling 22 source files to c:\Users\jwa\Desktop\tets\traffic_web\target\classes [INFO] ------------------------------------------------------------------------ [ERROR] BUILD FAILURE [INFO] ------------------------------------------------------------------------ [INFO] Compilation failure

c:\Users\jwa\Desktop\tets\traffic_web\src\traffic_web\tools\Encryptor.java:[7,15] sun.misc.BASE64Encoder is Sun propriet ary API and may be removed in a future release

c:\Users\jwa\Desktop\tets\traffic_web\src\traffic_web\tools\Session.java:[3,25] package javax.servlet.http does not exis t

c:\Users\jwa\Desktop\tets\traffic_web\src\traffic_web\tools\Session.java:[15,21] cannot find symbol symbol : class HttpSession location: class traffic_web.tools.Session

c:\Users\jwa\Desktop\tets\traffic_web\src\traffic_web\tools\ServletContextListenerInitializer.java:[6,20] package javax. servlet does not exist

c:\Users\jwa\Desktop\tets\traffic_web\src\traffic_web\tools\ServletContextListenerInitializer.java:[7,20] package javax. servlet does not exist

c:\Users\jwa\Desktop\tets\traffic_web\src\traffic_web\tools\ServletContextListenerInitializer.java:[8,20] package javax. servlet does not exist

c:\Users\jwa\Desktop\tets\traffic_web\src\traffic_web\tools\ServletContextListenerInitializer.java:[10,58] cannot find s ymbol symbol: class ServletContextListener public class ServletContextListenerInitializer implements ServletContextListener {

c:\Users\jwa\Desktop\tets\traffic_web\src\traffic_web\tools\ServletContextListenerInitializer.java:[12,33] cannot find s ymbol symbol : class ServletContextEvent location: class traffic_web.tools.ServletContextListenerInitializer

c:\Users\jwa\Desktop\tets\traffic_web\src\traffic_web\tools\ServletContextListenerInitializer.java:[15,35] cannot find s ymbol symbol : class ServletContextEvent location: class traffic_web.tools.ServletContextListenerInitializer

c:\Users\jwa\Desktop\tets\traffic_web\src\traffic_web\controller\BoardController.java:[9,25] package javax.servlet.http does not exist

c:\Users\jwa\Desktop\tets\traffic_web\src\traffic_web\controller\BoardController.java:[87,29] cannot find symbol symbol : class HttpServletResponse location: class traffic_web.controller.BoardController

c:\Users\jwa\Desktop\tets\traffic_web\src\traffic_web\controller\BoardController.java:[116,37] cannot find symbol symbol : class HttpServletResponse location: class traffic_web.controller.BoardController

c:\Users\jwa\Desktop\tets\traffic_web\src\traffic_web\tools\Encryptor.java:[27,15] sun.misc.BASE64Encoder is Sun proprie tary API and may be removed in a future release

c:\Users\jwa\Desktop\tets\traffic_web\src\traffic_web\tools\Session.java:[17,27] cannot access javax.servlet.http.HttpSe rvletRequest class file for javax.servlet.http.HttpServletRequest not found return attr.getRequest().getSession(true); // true == allow create

c:\Users\jwa\Desktop\tets\traffic_web\src\traffic_web\tools\ServletContextListenerInitializer.java:[17,8] cannot find sy mbol symbol : class ServletContext location: class traffic_web.tools.ServletContextListenerInitializer

[INFO] ------------------------------------------------------------------------ [INFO] Trace org.apache.maven.BuildFailureException: Compilation failure at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:715) at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalWithLifecycle(DefaultLifecycleExecutor.java:55 6) at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoal(DefaultLifecycleExecutor.java:535) at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalAndHandleFailures(DefaultLifecycleExecutor.jav a:387) at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegments(DefaultLifecycleExecutor.java:348) at org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLifecycleExecutor.java:180) at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:328) at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:138) at org.apache.maven.cli.MavenCli.main(MavenCli.java:362) at org.apache.maven.cli.compat.CompatibleMain.main(CompatibleMain.java:60) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.codehaus.classworlds.Launcher.launchEnhanced(Launcher.java:315) at org.codehaus.classworlds.Launcher.launch(Launcher.java:255) at org.codehaus.classworlds.Launcher.mainWithExitCode(Launcher.java:430) at org.codehaus.classworlds.Launcher.main(Launcher.java:375) Caused by: org.apache.maven.plugin.CompilationFailureException: Compilation failure at org.apache.maven.plugin.AbstractCompilerMojo.execute(AbstractCompilerMojo.java:516) at org.apache.maven.plugin.CompilerMojo.execute(CompilerMojo.java:114) at org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPluginManager.java:490) at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:694) ... 17 more [INFO] ------------------------------------------------------------------------ [INFO] Total time: 1 second [INFO] Finished at: Mon Jun 28 21:56:25 CEST 2010 [INFO] Final Memory: 13M/254M

[INFO]

我的 POM 文件如下所示:

<project>
  <modelVersion>4.0.0</modelVersion>
  <groupId>masters.traffic</groupId>
  <artifactId>traffic_web</artifactId>
  <packaging>war</packaging>
  <name>traffic_web</name>
  <version>0.1.0</version>
  <build>
        <sourceDirectory>src</sourceDirectory>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>                    
                </configuration>
            </plugin>
        </plugins>
  </build>

    ...

</project>

有人可以帮我解决这个问题吗?

问候

最佳答案

您尚未将 Servlet 类添加为依赖项。显然 Eclipse 中默认存在这些,这就是为什么它可以从那里进行编译。将以下内容添加到您的 pom 中(在 <build>... 之前,取自 here ):

<dependencies>
  [...]
  <dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>servlet-api</artifactId>
    <version>2.4</version>
    <scope>provided</scope>
  </dependency>
</dependencies>

关于java - Maven编译失败(但Eclipse下编译成功),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3135871/

相关文章:

java - TextView 未定位在 `CoordinatorLayout` 中的 ImagevVew 下

eclipse - Maven/Eclipse : The default build path for resources excluded everything

hibernate - 配置 hibernate.reveng.xml 以使用 hibernate3-maven-plugin 和 Postgre 检测序列 PK 生成器

maven-2 - 处理 Maven 快照 - 最佳实践

java - Eclipse 的 Eclipse 插件开发

java - 具有一对多关系的jooq单个查询

java - 我不断收到致命异常 : main

java - 使用 Dagger 进行嵌套/递归注入(inject)

java - Android Studio Pre-Lollipop 模拟器找不到类

java - Android:启动应用程序并截屏