【问题标题】:Package name does not correspond to the file path包名与文件路径不对应
【发布时间】:2014-02-07 19:06:23
【问题描述】:

我是 maven 新手,正在尝试运行简单的 spring 演示。我使用 Intellij IDEA 作为我的 IDE。我正在关注here提供的教程。

所以我跑了

mvn archetype:generate -DgroupId=SpringDemo -DartifactId=SpringExamples 
    -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false

然后做了

mvn idea:idea

它生成了所有 .ipr,.iws 等文件。然后我只是从 IDEA 打开并选择了 .ipr 文件。它检测到它是 IDEA 项目并打开它,但它给了我以下错误

Package name 'cospring' does not correspond to the file path 'cospring-demo'

应用类是

package cospring-demo;

/**
 * Hello world!
 *
 */
public class App
{
    public static void main( String[] args )
    {
        System.out.println( "Hello World!" );
    }
}

有什么问题?有什么解决办法吗?

【问题讨论】:

  • 我认为cospring-demo 不是一个有效的包名(包含连字符)尝试在你的类中使用cospring App
  • 你真的不应该使用mvn idea:idea。它已过时:stackoverflow.com/a/11903127/1350762.

标签: java maven intellij-idea


【解决方案1】:

这个解释很好

Maven groupIds 更喜欢破折号(“-”),但 Java 编译器禁止在包名称中使用破折号。然而,原型插件只是简单地将用户提供的内容作为 groupId 吐出。 ARCHETYPE-216

只需避免在从原型生成的groupId 中使用-

如果域名包含连字符或标识符中不允许的任何其他特殊字符(第 3.8 节),请将其转换为下划线。 JLS

【讨论】:

    猜你喜欢
    • 2014-12-13
    • 1970-01-01
    • 2016-09-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-05-07
    • 1970-01-01
    相关资源
    最近更新 更多