简体   繁体   中英

Maven says “Cannot find symbol” when trying to build it

Im trying to build a webapp in jenkins using maven, but it keeps saying that a couple of symbols couldnt be find.

I've checked both JAVA_HOME and MAVEN_HOME, and they are correctly set in Jenkins configs.

If someone knows anything that could help, i'd be grateful.

The command that i'm running on Maven:

mvn clean package

The errors presented:

[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  1.931 s
[INFO] Finished at: 2020-08-10T23:03:14-03:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.0:compile (default-compile) on project marvin: Compilation failure: Compilation failure: 
[ERROR] /home/luan/Downloads/teste/golden/src/main/java/br/ufrj/info/golden/core/persistence/StudentJPADAO.java:[18,46] cannot find symbol
[ERROR]   symbol:   class Student_
[ERROR]   location: package br.ufrj.info.golden.core.domain

No java.persistence in your pom.xml . Maybe you added some extra libs in your Eclipse project's build path. Manage ALL your dependencies via pom.xml else you'll always experience problems in your system. Also try mvn help:effective-pom in your Eclipse workspace directory and in your Jenkins workspace.

Given your comment, if that works in Eclipse but not in Jenkins, then you will have to check:

  • That you don't have a local version of an internal dependencies which brings back the required dependencies (if we look at javax.persistence , that would be Hibernate/EclipseLink or any other JPA implementation).
  • That you are using m2e ("Maven for Eclipse") in Eclipse to import your project and that you did not add a JAR explicitely.
  • Since you are in Java 11, that you provides the expected module in your module-info.

To check differences between local and Jenkins, you may wish to generate the dependency tree using mvn dependency:tree : that should print your the dependency that Jenkins uses and that your local workspace use. Using a diff should gives you some hint as to what to do (for example, pushing your change on the internal module so that Jenkins build it before you try to build your project).

In Eclipse, you can also open an offending file, one that does not compile such as src/main/java/br/ufes/informatica/marvin/research/domain/BibGenConfiguration.java , go to the import and, while pressing the Ctrl key, click on the class (for example javax.persistence.Entity ): if you enabled the Link with Editor feature of the Package Explorer , then you should go to the containing JAR of said class.

If the class is not a in your local maven repository ( ~/.m2/repository or %USERPROFILE%\.m2\repository ) then it is most certainly a JAR added to Eclipse but not in the pom.xml .


[edit] (and answer to comment) My answer was general, not related to javax.persistence only:

When you see such error in Jenkins (or anywhere but where it works), then you need to dig in and check what is wrong:

[ERROR] /home/luan/Downloads/teste/marvin/src/main/java/br/ufes/informatica/marvin/core/persistence/AcademicJPADAO.java:[18,46] cannot find symbol
[ERROR]   symbol:   class Academic_
[ERROR]   location: package br.ufes.informatica.marvin.core.domain

This error means that Java can't find the class br.ufes.informatica.marvin.core.domain.Academic_ in src/main/java/br/ufes/informatica/marvin/core/persistence/AcademicJPADAO.java .

Open the file AcademicJPADAO.java in Eclipse, and if its compile, find where it's from, but for those I think that you lack an internal dependency or you have locally a newer version of this dependency (either because you compiled it, either because you update its source code, etc...).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM