M2eclipse compilation error

When I run "mvn site" from the command line (using far manageR), everything works just fine, it loads all the necessary banks into the repository and performs the tasks.

But when I try to do the same (mvn site) from eclipse using the m2eclipse plugin, it will show me:

[INFO] Scanning for projects... [INFO] [INFO] ------------------------------------------------------------------------ [INFO] Building jdbc_maven 0.0.1-SNAPSHOT [INFO] ------------------------------------------------------------------------ [INFO] [INFO] --- maven-resources-plugin:2.5:resources (default-resources) @ jdbc_maven --- [debug] execute contextualize [INFO] Using 'UTF-8' encoding to copy filtered resources. [INFO] Copying 1 resource [INFO] [INFO] --- maven-compiler-plugin:3.0:compile (default-compile) @ jdbc_maven --- [INFO] Changes detected - recompiling the module! [INFO] Compiling 7 source files to G:\workspace\jdbc_maven\target\classes [INFO] ------------------------------------------------------------- [ERROR] COMPILATION ERROR : [INFO] ------------------------------------------------------------- [ERROR] G:\workspace\jdbc_maven\src\main\java\com\nixsolutions\JdbcRoleDao.java:[8,23] error: package org.apache.log4j does not exist [ERROR] G:\workspace\jdbc_maven\src\main\java\com\nixsolutions\JdbcRoleDao.java:[13,16] error: cannot find symbol [ERROR] symbol: class Logger location: class JdbcRoleDao G:\workspace\jdbc_maven\src\main\java\com\nixsolutions\User.java:[5,23] error: package org.apache.log4j does not exist [ERROR] G:\workspace\jdbc_maven\src\main\java\com\nixsolutions\User.java:[28,16] error: cannot find symbol [ERROR] symbol: class Logger location: class User G:\workspace\jdbc_maven\src\main\java\com\nixsolutions\JdbcUserDao.java:[13,23] error: package org.apache.log4j does not exist [ERROR] G:\workspace\jdbc_maven\src\main\java\com\nixsolutions\JdbcUserDao.java:[19,16] error: cannot find symbol [ERROR] symbol: class Logger location: class JdbcUserDao G:\workspace\jdbc_maven\src\main\java\com\nixsolutions\JdbcRoleDao.java:[13,29] error: cannot find symbol [ERROR] symbol: variable Logger location: class JdbcRoleDao G:\workspace\jdbc_maven\src\main\java\com\nixsolutions\User.java:[28,29] error: cannot find symbol [ERROR] symbol: variable Logger location: class User G:\workspace\jdbc_maven\src\main\java\com\nixsolutions\JdbcUserDao.java:[19,29] error: cannot find symbol [INFO] 9 errors [INFO] ------------------------------------------------------------- [INFO] ------------------------------------------------------------------------ [INFO] BUILD FAILURE [INFO] ------------------------------------------------------------------------ [INFO] Total time: 1.387s [INFO] Finished at: Sat Feb 16 11:05:13 EET 2013 [INFO] Final Memory: 7M/154M [INFO] ------------------------------------------------------------------------ [ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.0:compile (default-compile) on project jdbc_maven: Compilation failure: Compilation failure: [ERROR] G:\workspace\jdbc_maven\src\main\java\com\nixsolutions\JdbcRoleDao.java:[8,23] error: package org.apache.log4j does not exist [ERROR] G:\workspace\jdbc_maven\src\main\java\com\nixsolutions\JdbcRoleDao.java:[13,16] error: cannot find symbol [ERROR] symbol: class Logger [ERROR] location: class JdbcRoleDao [ERROR] G:\workspace\jdbc_maven\src\main\java\com\nixsolutions\User.java:[5,23] error: package org.apache.log4j does not exist [ERROR] G:\workspace\jdbc_maven\src\main\java\com\nixsolutions\User.java:[28,16] error: cannot find symbol [ERROR] symbol: class Logger [ERROR] location: class User [ERROR] G:\workspace\jdbc_maven\src\main\java\com\nixsolutions\JdbcUserDao.java:[13,23] error: package org.apache.log4j does not exist [ERROR] G:\workspace\jdbc_maven\src\main\java\com\nixsolutions\JdbcUserDao.java:[19,16] error: cannot find symbol [ERROR] symbol: class Logger [ERROR] location: class JdbcUserDao [ERROR] G:\workspace\jdbc_maven\src\main\java\com\nixsolutions\JdbcRoleDao.java:[13,29] error: cannot find symbol [ERROR] symbol: variable Logger [ERROR] location: class JdbcRoleDao [ERROR] G:\workspace\jdbc_maven\src\main\java\com\nixsolutions\User.java:[28,29] error: cannot find symbol [ERROR] symbol: variable Logger [ERROR] location: class User [ERROR] G:\workspace\jdbc_maven\src\main\java\com\nixsolutions\JdbcUserDao.java:[19,29] error: cannot find symbol 

Here is my 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>jdbc_maven</groupId> <artifactId>jdbc_maven</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>jar</packaging> <name>jdbc_maven</name> <url>http://maven.apache.org</url> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> </properties> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.8.1</version> <scope>test</scope> </dependency> <dependency> <groupId>org.dbunit</groupId> <artifactId>dbunit</artifactId> <version>2.4.8</version> </dependency> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-simple</artifactId> <version>1.6.4</version> </dependency> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-api</artifactId> <version>1.6.4</version> </dependency> <dependency> <groupId>com.h2database</groupId> <artifactId>h2</artifactId> <version>1.3.169</version> </dependency> <dependency> <groupId>log4j</groupId> <artifactId>log4j</artifactId> <version>1.2.17</version> <exclusions> <exclusion> <groupId>javax.jms</groupId> <artifactId>jms</artifactId> </exclusion> <exclusion> <groupId>com.sun.jmx</groupId> <artifactId>jmxri</artifactId> </exclusion> <exclusion> <groupId>com.sun.jdmk</groupId> <artifactId>jmxtools</artifactId> </exclusion> </exclusions> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-site-plugin</artifactId> <version>3.0</version> <configuration> <reportPlugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-report-plugin</artifactId> <version>2.8</version> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-checkstyle-plugin</artifactId> <version>2.6</version> <configuration> <configLocation>sun_checks.xml</configLocation> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-javadoc-plugin</artifactId> <version>2.6.1</version> </plugin> </reportPlugins> </configuration> </plugin> <!-- JDK 1.7 COMPILER - DON'T TOUCH --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.0</version> <configuration> <source>1.7</source> <target>1.7</target> <showDeprecation>true</showDeprecation> <showWarnings>true</showWarnings> <executable>${env.JAVA_HOME}/bin/javac</executable> <fork>true</fork> </configuration> </plugin> <!-- JDK 1.7 COMPILER - DON'T TOUCH --> </plugins> </build> </project> 
+4
source share
6 answers

This sometimes happens with m2eclipse, because since you add new dependencies to pom.xml, m2e automatically adds it to the classpath, and this classpath generation has some problems.

and a quick and dirty way to fix it will be

  • Remove the project from the eclipse
  • Now navigate to the project folder and delete .settings directory and .classpath file
  • Import the project into the eclipse as "Maven Project"
+2
source

Do project-> clean (also try updating the project) in eclipse. When you compile your code from the command line, it sometimes causes some problem in eclipse and the code needs to be recompiled in eclipse

+1
source

Everyone who uses the m2eclipse plugin and struggles with some problems, here are my tips:

1) user of your own maven, and not built in m2eclipse, you can switch to it in m2eclipse settings

2) change the repository location from stupid C: \ Users \ current_user-m2 \ repository to D: \ repository or any other normal path without ~ or any other special liters

3) check everything in the console with your own maven before a panic. For example, my commands like mvn site mvn install mvn tomcat: redeploy

works EXCELLENT from the console, but a failure from inside the eclipse. This means that m2eclipse parameters are incorrect and you must set your own parameters.

4) do not rely on contextual commands (right-click - run as-maven test / site / build) create your own command in the run as-maven menu in the menu to select the correct JRE version (1.7 in my case) and add any additional parameters , do not forget to give this command your name: "maven tomcat: redeploy JDK 7" - this will give you a good opportunity to run everything you want and you will not encounter 90% of problems and errors in m2eclipse.

PS I fought maven 2 and m2eclipse for over 20 hours. Hope my tips will be helpful to someone.

0
source

I had the same problem and I think I found a solution. The problem is that in the startup configurations, the maven configuration for your project did not update the new settings made in the general configuration.

Here is my solution:

  • in the start button (the one with the green triangle), select the launch options
  • Go to the maven build category and find one of your projects.
  • check that maven runtime, jre etc. configured correctly: these values ​​are not updated when changed in eclipse
  • apply changes and run

This solution worked for me (I played with the maven runtime, changing between internal and external, and this seemed like a problem.

0
source

same problem when creating documents using m2eclipse, javadoc: javadoc or javadoc: jar target, meanwhile Project -> Generate Javadoc is working fine. This seems like a problem in the wrong class path in the first case.
Workaround:

1.run Project β†’ Create Javadoc with the option to check "Save Javadoc export settings as an script"
2. javadoc.xml will be created
3. Run m2eclipse, after javadoc.sh fails, the parameters, packages will be in / site / apidocs /
4. take the contents of the classpath from javadoc.xml and put in the classpath in the parameter file
5. run./javadoc.sh

0
source

in pom.xml make sure you have a log4j scope when compiling

 <dependency> <groupId>org.apache.logging.log4j</groupId> <artifactId>log4j-api</artifactId> <version>2.5</version> <scope>compile</scope> </dependency> <dependency> <groupId>org.apache.logging.log4j</groupId> <artifactId>log4j-web</artifactId> <version>2.5</version> <scope>compile</scope> </dependency> 

It still puts log4j.jars in .war.

0
source

All Articles