作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在 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.xml
或 settings.xml
中定义了一个存储库,其 URL 无效(使用 String 美国)。
pom.xml
或父 pom;settings.xml
(通常位于 ~/.m2
中,尽管您可能已覆盖其在 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/
我是一名优秀的程序员,十分优秀!