gpt4 book ai didi

java - eclipse中读取maven项目失败: For Input String "US"

转载 作者:行者123 更新时间:2023-11-30 06:55:50 24 4
gpt4 key购买 nike

我在 Eclipse (Neon 2) 中有一个 Maven 项目。

该特定项目的 pom.xml 出现错误。每当我在 eclipse 中打开 pom 文件时,“错误日志”选项卡中都会抛出一条错误消息。消息是这样的 --> 无法读取 Maven 项目:对于输入字符串:“US”。

双击错误会显示完整的错误消息:

java.lang.NumberFormatException: For input string: "US"
at java.lang.NumberFormatException.forInputString(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at org.apache.maven.artifact.repository.MavenArtifactRepository.decode(MavenArtifactRepository.java:314)
at org.apache.maven.artifact.repository.MavenArtifactRepository.basedir(MavenArtifactRepository.java:246)
at org.apache.maven.artifact.repository.MavenArtifactRepository.<init>(MavenArtifactRepository.java:80)
at org.apache.maven.bridge.MavenRepositorySystem.createArtifactRepository(MavenRepositorySystem.java:467)
at org.apache.maven.bridge.MavenRepositorySystem.buildArtifactRepository(MavenRepositorySystem.java:387)
at org.apache.maven.project.DefaultProjectBuilder.initProject(DefaultProjectBuilder.java:863)
at org.apache.maven.project.DefaultProjectBuilder.build(DefaultProjectBuilder.java:176)
at org.apache.maven.project.DefaultProjectBuilder.build(DefaultProjectBuilder.java:119)
at org.apache.maven.project.DefaultProjectBuilder.initProject(DefaultProjectBuilder.java:679)
at org.apache.maven.project.DefaultProjectBuilder.build(DefaultProjectBuilder.java:176)
at org.apache.maven.project.DefaultProjectBuilder.build(DefaultProjectBuilder.java:119)
at org.eclipse.m2e.core.internal.embedder.MavenImpl.readMavenProject(MavenImpl.java:636)
at org.eclipse.m2e.core.internal.project.registry.ProjectRegistryManager$5.call(ProjectRegistryManager.java:816)
at org.eclipse.m2e.core.internal.project.registry.ProjectRegistryManager$5.call(ProjectRegistryManager.java:1)
at org.eclipse.m2e.core.internal.embedder.MavenExecutionContext.executeBare(MavenExecutionContext.java:176)
at org.eclipse.m2e.core.internal.embedder.MavenExecutionContext.execute(MavenExecutionContext.java:151)
at org.eclipse.m2e.core.internal.embedder.MavenExecutionContext.execute(MavenExecutionContext.java:99)
at org.eclipse.m2e.core.internal.project.registry.ProjectRegistryManager.execute(ProjectRegistryManager.java:967)
at org.eclipse.m2e.core.internal.project.registry.ProjectRegistryManager.readProjectWithDependencies(ProjectRegistryManager.java:811)
at org.eclipse.m2e.core.internal.project.registry.ProjectRegistryManager.create(ProjectRegistryManager.java:192)
at org.eclipse.m2e.core.internal.project.registry.MavenProjectManager.create(MavenProjectManager.java:80)
at org.eclipse.m2e.core.ui.internal.actions.SelectionUtil.getMavenProject(SelectionUtil.java:259)
at org.eclipse.m2e.editor.pom.MavenPomEditor.readMavenProject(MavenPomEditor.java:732)
at org.eclipse.m2e.editor.pom.MavenPomEditor$5.run(MavenPomEditor.java:1053)
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:55)

我仍然能够执行 mvn clean/install 等...但是在项目中不断看到 pom 错误很烦人。我不想简单地改变 Maven 或 Eclipse 中的某些内容来隐藏错误,我想了解为什么会发生这种情况以及修复它的最佳方法是什么。

最佳答案

这里抛出错误:

at org.apache.maven.artifact.repository.MavenArtifactRepository.decode(MavenArtifactRepository.java:314)

查看 MavenArtifactRepository 的 source code ,我认为您在 pom.xmlsettings.xml 中定义了一个存储库,其 URL 无效(使用 String 美国)。

  • 查看您的 pom.xml 或父 pom;
  • 查看 settings.xml(通常位于 ~/.m2 中,尽管您可能已覆盖其在 Eclipse 中的位置);
  • 也许它是在 Eclipse 中配置的某个存储库,您可以通过 Eclipse 配置文件对 Eclipse 工作区进行完整搜索。

MavenArtifactRepository的相关源代码(阅读javadoc注释):

/**
* Create a remote download repository.
* @param url the URL of the repository
*/
public MavenArtifactRepository(..., String url, ...) {
...
this.basedir = basedir( url );
}


/**
* Derive the path portion of the given URL.
* @param url the repository URL
*/
private String basedir( String url ) {
if ( protocol.equalsIgnoreCase( "file" ) ) {
retValue = url.substring( protocol.length() + 1 );
retValue = decode( retValue );
...
}

/**
* Decodes the specified (portion of a) URL. <strong>Note:</strong> This decoder assumes that ISO-8859-1 is used to
* convert URL-encoded bytes to characters.
*
* @param url The URL to decode, may be <code>null</code>.
* @return The decoded URL or <code>null</code> if the input was <code>null</code>.
*/
private static String decode( String url )
{
String decoded = url;
if ( url != null )
{
int pos = -1;
while ( ( pos = decoded.indexOf( '%', pos + 1 ) ) >= 0 )
{
if ( pos + 2 < decoded.length() )
{
String hexStr = decoded.substring( pos + 1, pos + 3 );
char ch = (char) Integer.parseInt( hexStr, 16 );
decoded = decoded.substring( 0, pos ) + ch + decoded.substring( pos + 3 );
}
}
}
return decoded;
}
<小时/>

如果我正确地阅读了代码,您的存储库可能如下所示:

file:anything%USanything

显然(根据代码),只有有效的 2 位十六进制 应该跟在网址中的“%”符号之后...

关于java - eclipse中读取maven项目失败: For Input String "US",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41838360/

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