18

Like below, I had an error when running mvn package

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-jar-plugin:2.3.1:jar (default-jar) on project hello-world: Execution default-jar of goal org.apache.maven.plugins:maven-jar-plugin:2.3.1:jar failed: Unable to load the mojo 'jar' in the plugin 'org.apache.maven.plugins:maven-jar-plugin:2.3.1'. A required class is missing: org/codehaus/plexus/components/io/resources/PlexusIoResourceCollection
[ERROR] -----------------------------------------------------
[ERROR] realm =    plugin>org.apache.maven.plugins:maven-jar-plugin:2.3.1
[ERROR] strategy = org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy
[ERROR] urls[0] = file:/C:/maven/repository/org/apache/maven/plugins/maven-jar-plugin/2.3.1/maven-jar-plugin-2.3.1.jar
[ERROR] urls[1] = file:/C:/maven/repository/junit/junit/3.8.1/junit-3.8.1.jar
[ERROR] urls[2] = file:/C:/maven/repository/org/apache/maven/maven-archiver/2.4.1/maven-archiver-2.4.1.jar
[ERROR] urls[3] = file:/C:/maven/repository/org/codehaus/plexus/plexus-archiver/1.0/plexus-archiver-1.0.jar
[ERROR] urls[4] = file:/C:/maven/repository/commons-lang/commons-lang/2.1/commons-lang-2.1.jar
[ERROR] urls[5] = file:/C:/maven/repository/org/codehaus/plexus/plexus-utils/2.0.5/plexus-utils-2.0.5.jar
[ERROR] Number of foreign imports: 1
[ERROR] import: Entry[import  from realm ClassRealm[maven.api, parent: null]]
[ERROR] 
[ERROR] -----------------------------------------------------: org.codehaus.plexus.components.io.resources.PlexusIoResourceCollection
[ERROR] -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginContainerException

This is my pom.xml. I got rid of unnecessary things, but still it didn't work..

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

<modelVersion>4.0.0</modelVersion>
<groupId>sds.jetty.simple</groupId>
<artifactId>hello-world</artifactId>
<version>1.0</version>
<packaging>jar</packaging>
<name>Jetty HelloWorld</name>

<properties>
    <jettyVersion>8.1.2.v20120308</jettyVersion>
</properties>

<dependencies>
    <dependency>
        <groupId>org.eclipse.jetty</groupId>
        <artifactId>jetty-server</artifactId>
        <version>${jettyVersion}</version>
    </dependency>
</dependencies>

<build>
</build>
</project>
ROMANIA_engineer
  • 54,432
  • 29
  • 203
  • 199
verystrongjoe
  • 3,831
  • 9
  • 35
  • 66

11 Answers11

6

Try to remove to folder

.m2\repository\org\apache\maven\plugins\maven-jar-plugin

on your file system. Your plugin jar might be corrupted.

If this does not work, try to remove the jetty-server folder (same reason)

toniedzwiedz
  • 17,895
  • 9
  • 86
  • 131
Samuel EUSTACHI
  • 3,116
  • 19
  • 24
  • doesn't maven automatically check/update corrupted files? revmoving files manually is time consuming if use a lot of packages. – Lei Yang Jul 07 '20 at 02:14
2

I met similar issue once. It turned out to be a maven 3 issue. After switching to maven 2.2.1 my build ran fine.

2

Even faced this issue. It will be resolved by just deleting the .m2/repository folder and build the Project again.

nisarga
  • 21
  • 2
  • this worked for me, its crazy solution, takes time to re-build the entire repo. I kept backup repo by renaming the existing `.m2` directory – Akhil Jain Jun 04 '18 at 12:38
1

Compiling with Java 8 instead of Java 6 has solved the problem in my case.

0

It is working for me for your example POM file, the problem should be somewhere else.

Are you sure there is no connection problems there? Your antivirii software doesn't prevents you downloading artifacts? Isn't an entry in your local repository corrupted?

rlegendi
  • 10,466
  • 3
  • 38
  • 50
0

For us this was caused when Eclipse / Maven automatically changed our JDK to 1.5 (from 1.8). Manually changing back to 1.8 fixed the issue.

Ryan S
  • 195
  • 2
  • 11
0

Thats an unresolved issue in Maven 3.3.1 and 3.3.3; https://issues.apache.org/jira/browse/MNG-5787 I upgraded to 3.3.9 and things started working.

0

i recently encountered the issue and i just need to remove the folders from .m2/repository and rerun the pom. it worked.

arn-arn
  • 1,328
  • 1
  • 21
  • 31
0

1.I will suggest you to delete the .m2 folder completely

2.Then do maven -> Update Project.

3.Maven Install

0

I have had the same error using the maven version 3.6.3. In my case, it is not an issue with maven. But I have a very large size folder (5 GB) copied inside the src/resource folder unusually. After removing the junk folder, everything worked normally.

-1

There should be some issue within the dependencies which maven can't resolve on the fly. try running this command on your project root.

mvn dependency:tree

this should resolve all the dependency issues and help you run with the appliction