gpt4 book ai didi

java - Maven:mvn 编译失败。 "package does not exist"。依赖项包含在 maven 中,其他 SO 解决方案不起作用。我缺少什么?

转载 作者:行者123 更新时间:2023-11-30 02:48:19 25 4
gpt4 key购买 nike

我知道关于这个主题还有很多其他答案,尽管this question似乎是最有用的,但这些解决方案都没有使我完全解决我的问题。所以我需要更多帮助。

我有一个 Netbeans 项目,是由我之前在我公司工作过的人创建的,该项目从未使用 Maven 构建过,而且我还没有完全深入了解该项目的源代码。然而,由于该项目的依赖项数量对我来说似乎难以承受,因此我决定需要找出一个管理解决方案。这让我接触到 Maven,然后间接接触到 Apache Archiva。

因此,我建立了一个 Archiva 存储库并上传了项目所需的所有依赖项。所有这些 Artifact 都是 JAR 文件。然后,我在预先存在的项目目录中创建了一个 pom.xml 文件,并调整了build设置以匹配该项目。现在项目目录如下所示:

ProjectStructure and Import Error In Source Code

在上面的屏幕截图中,您还可以看到第 12 行的错误。此错误显示“package.imgscalr 不存在”,稍后 mvncompile 会回显该错误。

完整的项目 POM 如下所示:

    <?xml version="1.0" encoding="UTF-8"?>
<!--LISCENSE HEADER-->
<project>
<groupId>com.glsarchives</groupId>
<artifactId>GLSLib</artifactId>
<version>1.0</version>
<modelVersion>4.0.0</modelVersion>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.1</version>
</dependency>
<dependency>
<groupId>at.unbounded</groupId>
<artifactId>serialization.jar</artifactId>
<version>0.0</version>
</dependency>
<dependency>
<groupId>com.businessobjects.sdk</groupId>
<artifactId>cecore</artifactId>
<version>0.0</version>
</dependency>
<dependency>
<groupId>com.businessobjects.sdk</groupId>
<artifactId>celib</artifactId>
<version>0.0</version>
</dependency>
<dependency>
<groupId>com.businessobjects.sdk</groupId>
<artifactId>ceplugins</artifactId>
<version>0.0</version>
</dependency>
<dependency>
<groupId>com.businessobjects.sdk</groupId>
<artifactId>cereports</artifactId>
<version>0.0</version>
</dependency>
<dependency>
<groupId>com.businessobjects.sdk</groupId>
<artifactId>cesession</artifactId>
<version>0.0</version>
</dependency>
<dependency>
<groupId>com.businessobjects.sdk</groupId>
<artifactId>ceutils</artifactId>
<version>0.0</version>
</dependency>
<dependency>
<groupId>com.businessobjects.sdk</groupId>
<artifactId>corbaidl</artifactId>
<version>0.0</version>
</dependency>
<dependency>
<groupId>com.businessobjects.sdk</groupId>
<artifactId>ebus405</artifactId>
<version>0.0</version>
</dependency>
<dependency>
<groupId>com.businessobjects.sdk</groupId>
<artifactId>MetafileRenderer</artifactId>
<version>0.0</version>
</dependency>
<dependency>
<groupId>com.businessobjects.sdk</groupId>
<artifactId>rasapp</artifactId>
<version>0.0</version>
</dependency>
<dependency>
<groupId>com.businessobjects.sdk</groupId>
<artifactId>rascore</artifactId>
<version>0.0</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
<dependency>
<groupId>org.dspace.xmlui.concurrent</groupId>
<artifactId>Concurrent</artifactId>
<version>0.0</version>
</dependency>
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>eclipselink</artifactId>
<version>2.5.2</version>
</dependency>
<dependency>
<groupId>org.imgscalr</groupId>
<artifactId>imgscalr-lib</artifactId>
<version>4.2</version>
</dependency>
<dependency>
<groupId>org.lucee</groupId>
<artifactId>commons-logging</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>org.lucee</groupId>
<artifactId>xml-apis</artifactId>
<version>0.0</version>
</dependency>
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>javax.persistence</artifactId>
<version>0.0</version>
</dependency>
<dependency>
<groupId>org.netbeans.lib</groupId>
<artifactId>awtextra</artifactId>
<version>0.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.netbeans.external</groupId>
<artifactId>AbsoluteLayout</artifactId>
<version>0.0</version>
</dependency>
</dependencies>

<build>
<sourceDirectory>./src</sourceDirectory>
<finalName>GLSLib</finalName>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>

<repositories>
<repository>
<id>GLS-Java-Repo</id>
<name>Java Repository</name>
<url>http://archiva:8080/repository/GLS-Java-Repo/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>GLS-Java-Repo</id>
<name>Java Repository</name>
<url>http://archiva:8080/repository/GLS-Java-Repo/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
</project>

当我运行mvncompile-X时,我得到以下输出:

[INFO] Error stacktraces are turned on.
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building GLSLib 1.0
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ GLSLib ---

[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources,
i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory C:\GLS_DEVELOPER\GLS_Projects\GLS_Lib
\Repositories\GIT\GLS-Lib_PR_Repo\src\main\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ GLSLib ---
[INFO] Changes detected - recompiling the module!
[WARNING] File encoding has not been set, using platform encoding Cp1252, i.e. b
uild is platform dependent!
[INFO] Compiling 91 source files to C:\GLS_DEVELOPER\GLS_Projects\GLS_Lib\Reposi
tories\GIT\GLS-Lib_PR_Repo\target\classes
[INFO] -------------------------------------------------------------
[WARNING] COMPILATION WARNING :
[INFO] -------------------------------------------------------------
[WARNING] /C:/GLS_DEVELOPER/GLS_Projects/GLS_Lib/Repositories/GIT/GLS-Lib_PR_Rep
o/src/gls/ui/emp/EmpComboBoxPanel.java: Some input files use unchecked or unsafe
operations.
[WARNING] /C:/GLS_DEVELOPER/GLS_Projects/GLS_Lib/Repositories/GIT/GLS-Lib_PR_Rep
o/src/gls/ui/emp/EmpComboBoxPanel.java: Recompile with -Xlint:unchecked for deta
ils.
[INFO] 2 warnings
[INFO] -------------------------------------------------------------
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] /C:/GLS_DEVELOPER/GLS_Projects/GLS_Lib/Repositories/GIT/GLS-Lib_PR_Repo/
src/gls/image/ImagePanel.java:[12,20] package org.imgscalr does not exist
[ERROR] /C:/GLS_DEVELOPER/GLS_Projects/GLS_Lib/Repositories/GIT/GLS-Lib_PR_Repo/
src/gls/image/ImagePanel.java:[106,18] cannot find symbol
symbol: variable Scalr
location: class gls.image.ImagePanel
[ERROR] /C:/GLS_DEVELOPER/GLS_Projects/GLS_Lib/Repositories/GIT/GLS-Lib_PR_Repo/
src/gls/image/ImagePanel.java:[128,18] cannot find symbol
symbol: variable Scalr
location: class gls.image.ImagePanel
[INFO] 3 errors
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.154 s
[INFO] Finished at: 2016-09-14T12:31:34-04:00
[INFO] Final Memory: 17M/321M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.
1:compile (default-compile) on project GLSLib: Compilation failure: Compilation
failure:
[ERROR] /C:/GLS_DEVELOPER/GLS_Projects/GLS_Lib/Repositories/GIT/GLS-Lib_PR_Repo/
src/gls/image/ImagePanel.java:[12,20] package org.imgscalr does not exist
[ERROR] /C:/GLS_DEVELOPER/GLS_Projects/GLS_Lib/Repositories/GIT/GLS-Lib_PR_Repo/
src/gls/image/ImagePanel.java:[106,18] cannot find symbol
[ERROR] symbol: variable Scalr
[ERROR] location: class gls.image.ImagePanel
[ERROR] /C:/GLS_DEVELOPER/GLS_Projects/GLS_Lib/Repositories/GIT/GLS-Lib_PR_Repo/
src/gls/image/ImagePanel.java:[128,18] cannot find symbol
[ERROR] symbol: variable Scalr
[ERROR] location: class gls.image.ImagePanel
[ERROR] -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal o
rg.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on p
roject GLSLib: Compilation failure
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor
.java:212)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor
.java:153)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor
.java:145)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProje
ct(LifecycleModuleBuilder.java:116)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProje
ct(LifecycleModuleBuilder.java:80)
at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThre
adedBuilder.build(SingleThreadedBuilder.java:51)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(Lifecycl
eStarter.java:128)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:307)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:193)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:106)
at org.apache.maven.cli.MavenCli.execute(MavenCli.java:863)
at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:288)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:199)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
sorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Laun
cher.java:289)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.jav
a:229)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(La
uncher.java:415)
at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:
356)
Caused by: org.apache.maven.plugin.compiler.CompilationFailureException: Compila
tion failure
at org.apache.maven.plugin.compiler.AbstractCompilerMojo.execute(Abstrac
tCompilerMojo.java:858)
at org.apache.maven.plugin.compiler.CompilerMojo.execute(CompilerMojo.ja
va:129)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(Default
BuildPluginManager.java:134)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor
.java:207)
... 20 more
[ERROR]
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please rea
d the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureExc
eption

所以,明显的问题是maven似乎找不到org.imgscalr包。但是,我的依赖项都没有被覆盖或删除——基于 mvn dependency:tree -Dverbose 生成的依赖项树,包括 imgscalr-lib 依赖项(这是一个JAR,其中包含 org.imgscalr 包和 META-INF)。

由于怀疑损坏,我删除了本地存储库中的 imgscaler-lib 文件夹 - 然后删除了整个存储库 - 这些都不起作用。编译后,Maven 重新从我的 Archiva 存储库中获取了所有文件,但问题仍然存在。

我检查了mvn help: effective-pom,它似乎与我的pom.xml匹配。

我还尝试按照链接问题中的建议运行mvn dependency:copy-dependencies,并且我的所有库都已成功复制到目标目录中,包括有问题的库: org.imgscalr

我在这里缺少什么?

编辑:更新了 pom.xml 以添加存储库信息

编辑:我的 pom.xml 中的版本号非常奇怪,是因为我从前任给我的文件夹中将 Artifact 上传到了 Archiva。很多松散的 Artifact 没有任何版本号,所以我将这些未知的版本号标记为“0.0”

编辑:在 pom.xml 添加存储库信息后再次删除存储库。运行另一个干净的目标和另一个编译目标。 Maven 重新获取依赖项。我已经确认 Maven 正在从我的 Archiva 存储库中获取 Artifact 。问题仍然存在。

最佳答案

来自评论:

The package is DEFINITELY in the .jar. Not a .class file, but 3 .java source files. Including one called Scalr.java which appears to be the one that the compiler is complaining about.

这是你的问题。 Jars 应包含已编译的 .class 文件,而不是源文件,例如 *.java 文件。您已将源 jar 放入 Archiva,但它们应该是包含编译文件的 jar。

我猜您是通过某种非正统的方式获得这些 .jar,而不是使用常规工具。

关于java - Maven:mvn 编译失败。 "package does not exist"。依赖项包含在 maven 中,其他 SO 解决方案不起作用。我缺少什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39496282/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com