Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven compilation failes (but compilation under Eclipse is successful)

While building my web project from Eclipse, everything is fine: no errors, no warnings.

However while building project with Maven it failes. Below is the output form mvn compile:

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]

My POM file looks like that:

<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>

Can Someone help me how to fix that ?

Regards

like image 586
jwaliszko Avatar asked Jun 28 '10 20:06

jwaliszko


People also ask

Why Maven project showing error in Eclipse?

The error message indicates that Maven is unable to find the Java compiler, which comes only with a JDK and not with a JRE.


1 Answers

You haven't added the servlet classes as dependencies. There are apparently present per default in Eclipse, which is why it works to compile from there. Add the following to you pom (before <build>..., taken from here):

<dependencies>
  [...]
  <dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>servlet-api</artifactId>
    <version>2.4</version>
    <scope>provided</scope>
  </dependency>
</dependencies>
like image 92
Alexander Torstling Avatar answered Nov 16 '22 02:11

Alexander Torstling