'how to delete target folder of maven project in eclipse

I cannot clean the maven project. who know the best way,thanks.

the maven project in eclipse.

when i run mvn clean package,first it will run successful

two times after, i cannot do it will get error.

Deleting C:\Codes...\target

BUILD ERROR

Failed to clean project: Failed to delete C:\Codes...\target

I already tried to shut dowm eclipse is still error.

i trid to login off and login in and it will be ok;

but it not a good way to solve it .

who know other way,thanks!



Solution 1:[1]

Some file of the target folder is locked by another program or you may not have permission to delete folder

so go and delete folder manually by using Windows Explorer if not open a windows explorer with administrative right and then go to that folder and delete.

now you can run mvn clean install it will works fine.

Solution 2:[2]

It is not able to delete because you must be accessing some file from it. So simple solution would be to close any files which you might have opened from target folder [inside or outside eclipse]. Once you dont access the folder or any of its contents then folder shld get deleted.

Solution 3:[3]

If you continue to have this problem, you have something of a bother.

As Lokesh explains, something is holding a file handling, preventing maven from deleting the directory. It could be eclipse, or something from the build, it can be hard to spot.

If there are any files in the non-removable directory, they may provide you with a clue.

Solution 4:[4]

I've faced the same issue, there is a process that holds a lock in the file on some subfolder that Maven is trying to clean.

Check that your Tomcat instance is really stopped or look for java processes in Task Manager that shouldn't be there. If there then End Task. (My Case)

Check and close that file from notepad or any other application

If these steps failed, try restarting your machine. (This will definitely resolve)

Solution 5:[5]

I use MobaXterm to upload the war file to our test/prod servers. Somehow the tool keeps the file/folder locked and the delete is not allowed.

Solution:

  • Close MobaXterm and build. this can be inconvenient as the session is lost

  • Configure Maven to write the war file to a different directory than target. In MobaXterm use this dir to upload the file. As the maven clean doesn't need to delete this directory, everything works fine now.

        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <configuration>
                    <warName>NAME OF THE WAR FILE</warName>
                    <outputDirectory>SEPEREATE LOCATION (I use .../workspace/bin</outputDirectory>
                </configuration>
            </plugin>
        </plugins>
    
    </build>
    

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Sasikumar Murugesan
Solution 2 Lokesh
Solution 3 Niels Bech Nielsen
Solution 4 Arun
Solution 5 Sachin Jain