9

I've recently started using maven with eclipse.

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.

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

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

mdarwin
  • 1,684
  • 7
  • 28
  • 72
  • `outside the project`? you can build only from the place the pom.xml exists that is the context root – SparkOn Aug 08 '14 at 15:17
  • build, copy to wherever you want using antrun plugin and delete the content from build folder – user3487063 Aug 08 '14 at 15:21
  • 1
    why can't I build somewhere like ../build ? Is that a hard rule of maven? Where is that written? – mdarwin Aug 08 '14 at 15:30
  • Because `Eclipse JDT` does not allow setting output dir outside of project. You can read it e.g. [here](https://bugs.eclipse.org/bugs/show_bug.cgi?id=493229#c1). Maven itself supports such project layout. – G. Demecki Jun 08 '16 at 06:45

6 Answers6

6

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.xml file, 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.xml file.

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.

paxmemento
  • 281
  • 4
  • 10
  • 3
    I'm glad you solved your problem, but it seems to me it's not the OP problem. He said *I need to build outside the project*. – G. Demecki Jun 08 '16 at 06:52
2

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

The following Eclipse error:

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.

In situation you described, it is a known limitation. But it's not a m2e fault - simply Eclipse JDT does 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 m2e should as well.

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

G. Demecki
  • 10,145
  • 3
  • 58
  • 58
2

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:

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

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

3) I added this entry to my "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.

twm
  • 1,448
  • 11
  • 19
0

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-build to have your build, copy, delete done.

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

Community
  • 1
  • 1
user3487063
  • 3,672
  • 1
  • 17
  • 24
0

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

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

The pom.xml file 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.

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

SparkOn
  • 8,806
  • 4
  • 29
  • 34
0

I was convinced that this problem was caused by either Maven or Eclipse, perhaps because I found this and other references to that combination on Stackoverflow.

After considerable investigation, and going slightly mad, it turns out that Git was involved - though I don't know if it was the cause.

My Maven project consists of several "nested" POMs, and I don't open the parent POM in Eclipse, but only the children. I had a couple of files (batch scripts) at the top level which I hadn't committed to Git, but once I committed these the

Path must include project and resource name

problem disappeared completely.

Eclipse version: 2020-12 (4.18.0)

DAB
  • 1,631
  • 19
  • 25