Maven在尝试构建时报错 “Cannot find symbol”。

huangapple go评论78阅读模式
英文:

Maven says "Cannot find symbol" when trying to build it

问题

I'm trying to build a webapp in Jenkins using Maven, but it keeps saying that a couple of symbols couldn't be found.

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
英文:

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

答案1

得分: 1

没有在您的pom.xml中找到java.persistence。也许您在Eclipse项目的构建路径中添加了一些额外的库。请通过pom.xml来管理所有的依赖,否则您的系统将经常出现问题。还可以尝试在Eclipse工作空间目录和Jenkins工作空间中运行mvn help:effective-pom

英文:

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.

答案2

得分: 0

根据您的评论,如果在Eclipse中可以正常工作,但在Jenkins中无法工作,那么您需要检查以下事项:

  • 确保您没有本地版本的内部依赖项,这些依赖项会引入所需的依赖项(如果我们看javax.persistence,那可能是Hibernate/EclipseLink或任何其他JPA实现)。
  • 确保您在Eclipse中使用"Maven for Eclipse"(m2e)来导入项目,并且没有明确添加JAR文件。
  • 由于您使用的是Java 11,请确保在您的module-info中提供了所需的模块。

要比较本地和Jenkins之间的差异,您可以使用mvn dependency:tree生成依赖树:这应该会打印出Jenkins使用的依赖项和您本地工作空间使用的依赖项。使用差异可能会给您一些提示,以便采取相应的行动(例如,将更改推送到内部模块,以便在尝试构建项目之前Jenkins构建它)。

在Eclipse中,您还可以打开一个引发错误的文件,例如src/main/java/br/ufes/informatica/marvin/research/domain/BibGenConfiguration.java,转到导入部分,然后按住Ctrl键,单击类(例如javax.persistence.Entity):如果启用了“包资源管理器”的“与编辑器链接”功能,那么您应该会跳转到包含该类的JAR文件。

如果该类不在您的本地Maven存储库(~/.m2/repository%USERPROFILE%\.m2\repository)中,那么它很可能是在Eclipse中添加的JAR文件,但未在pom.xml中包含。

[编辑](并回答评论)我的回答是一般性的,不仅与javax.persistence有关:

当您在Jenkins(或任何不工作的地方)看到此类错误时,您需要深入挖掘并查找问题所在:

[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

这个错误意味着Java无法在src/main/java/br/ufes/informatica/marvin/core/persistence/AcademicJPADAO.java中找到br.ufes.informatica.marvin.core.domain.Academic_类。

在Eclipse中打开AcademicJPADAO.java文件,如果可以编译通过,找出它来自哪里,但对于这些情况,我认为您缺少一个内部依赖项或者您本地拥有一个较新版本的此依赖项(可能是因为您编译了它,或者因为您更新了它的源代码等等)。

英文:

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

huangapple
  • 本文由 发表于 2020年8月11日 04:10:59
  • 转载请务必保留本文链接:https://go.coder-hub.com/63347337.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定