Java Maven 与 Eclipse 错误“路径必须包含项目和资源名称”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25206689/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-10 23:53:03  来源:igfitidea点击:

maven with eclipse error "Path must include project and resource name"

javaeclipsemaven

提问by mdarwin

I've recently started using maven with eclipse.

我最近开始在 Eclipse 中使用 Maven。

I've set up several projects and I've noticed that if I try and specify a build directory (to over-ride target) which is outside the project directory, I get an error when doing "update project":

我已经设置了几个项目,我注意到如果我尝试指定项目目录之外的构建目录(以覆盖目标),则在执行“更新项目”时会出现错误:

'Updating Maven Project' has encountered a problem.

“更新 Maven 项目”遇到问题。

An internal error occurred during: "Updating MAven Project". Path must include project and resource name: /[my project name]

在“更新 MAven 项目”期间发生内部错误。路径必须包含项目和资源名称:/[我的项目名称]

I need to build outside the project. How can I get around this? Can I perhaps have maven automatically create a softlink?

我需要在项目之外构建。我怎样才能解决这个问题?我可以让 maven 自动创建一个软链接吗?

回答by user3487063

For example, if you'd like to have build contents in some folder outside workspace, you can have something like :

例如,如果您想在工作区外的某个文件夹中构建内容,您可以使用以下内容:

<build>
<plugins>
  <plugin>
    <executions>
        <execution>

        <phase>move-build</phase>
        ////do your build
  </plugin>

  <plugin>
    <executions>
        <execution>
        <id>copy-resources</id>
        <phase>move-build</phase>
        // do your copying to external
  </plugin>

  <plugin>
    <executions>
            <execution>

        <phase>move-build</phase>
        // do your deletions from target
  </plugin>

</plugins>
</build>

then you can call mvn move-buildto have your build, copy, delete done.

然后你可以打电话mvn move-build来完成你的构建、复制、删除。

here is an example of copy to external folderand delete, you can combine both into your move-build phase as described above

这是复制到外部文件夹删除的示例,您可以如上所述将两者结合到移动构建阶段

回答by SparkOn

why can't I build somewhere like ../build

why can't I build somewhere like ../build

Yes you can build in some folder called build provided it contains the pom.xml.

是的,您可以在名为 build 的文件夹中构建,前提是它包含pom.xml.

The pom.xmlfile is the core of a project's configuration in Maven. It is a single configuration file that contains the majority of information required to build a project.

pom.xml文件是 Maven 中项目配置的核心。它是一个包含构建项目所需的大部分信息的单个配置文件。

In short the pom.xmlwill have all information to build your project. pom.xmlis a file which contains the project configuration details used by Maven. It provides all the configuration required for a project.

简而言之,pom.xml它将拥有构建项目的所有信息。 pom.xml是一个包含 Maven 使用的项目配置详细信息的文件。它提供了项目所需的所有配置。

回答by paxmemento

Although this is a fairly old thread, I recently encountered this problem and was able to solve it. The reason why maven threw this error is I had, somewhere in my pom.xmlfile, an absolute path that was not consistent with the directory from which the project was imported into eclipse. So I had two absolute paths (one incorrect, or points to a previous location) that point to resources, i.e. project.build.outputDirectory, in the pom.xmlfile.

虽然这是一个相当老的线程,但我最近遇到了这个问题并且能够解决它。maven 抛出这个错误的原因是我在我的pom.xml文件中某处有一个绝对路径,该路径与项目导入到 eclipse 的目录不一致。所以我有两个指向资源的绝对路径(一个不正确,或者指向以前的位置),即project.build.outputDirectorypom.xml文件中。

The Solution: Locate the faulty absolute path, /home/userA/ProjectB/bin, and replace with a relative, ./bin, path. Update the project in eclipse and you should be fine.

解决方案:找到有问题的绝对路径/home/userA/ProjectB/bin,并替换为相对./bin路径 。在 eclipse 中更新项目,你应该没问题。

回答by G. Demecki

This is a bit old thread, but since nobody gave a correct answer...

这是一个有点旧的线程,但由于没有人给出正确的答案......

The following Eclipse error:

以下 Eclipse 错误:

An internal error occurred during: "Updating Maven Project".
java.lang.IllegalArgumentException: Path must include project and resource name:
    at org.eclipse.core.runtime.Assert.isLegal(Assert.java:63)
    at org.eclipse.core.internal.resources.Workspace.newResource(Workspace.java:2069)
    at ...

can occur in many different scenarios - in the Eclipse Bugzilla you can find a lot of similar bug reports.

可以发生在许多不同的场景中——在 Eclipse Bugzilla 中,您可以找到很多类似的错误报告。

In situation you described, it is a known limitation. But it's not a m2efault - simply Eclipse JDTdoes not allow setting output dir outside of the project.
IMHO it's a pity, because if maven supports a such layout, so I would expect that m2eshould as well.

在您描述的情况下,这是一个已知限制。但这不是m2e错误 - 只是Eclipse JDT不允许在项目之外设置输出目录。
恕我直言,很遗憾,因为如果 maven 支持这样的布局,那么我希望也m2e应该如此。

I've reported it as a bug 493229. But it has been closed with status WONTFIX.

我已将其报告为错误 493229。但它已以WONTFIX状态关闭

回答by twm

To answer the last paragraph in your question, you can get around the problem with a softlink. I did it a little differently than what you guessed at. It's not Maven that creates the symlink because this is a problem with Eclipse JDT (as others have pointed out) which runs without invoking Maven at times (it seems). Here's what I did, with all paths relative to my Maven project directory:

要回答问题的最后一段,您可以使用软链接解决问题。我做的和你猜的有点不同。创建符号链接的不是 Maven,因为这是 Eclipse JDT 的一个问题(正如其他人指出的那样),它有时在不调用 Maven 的情况下运行(似乎)。这是我所做的,所有路径都相对于我的 Maven 项目目录:

1) I wanted my actual build directory to be "../../local/java/scratch/target"

1)我希望我的实际构建目录是“../../local/java/scratch/target”

2) I created a softlink: ln -s ../../local ./

2)我创建了一个软链接: ln -s ../../local ./

3) I added this entry to my "pom.xml":

3)我将此条目添加到我的“pom.xml”中:

<build>
  <directory>${project.basedir}/local/java/scratch/target</directory>
</build>

Now Eclipse JDT happily thinks it's building within the project directory but in reality the path "../../" takes it outside of the project directory. My guess is that an absolute path would have worked too.

现在 Eclipse JDT 很高兴地认为它是在项目目录中构建的,但实际上路径“../../”将它带到了项目目录之外。我的猜测是绝对路径也会起作用。