Ошибка inject plugin

what the console prints, I am trying to run a java web application on netbeans and I do not understand very well why it gives me that error.

Downloaded from central: https://repo.maven.apache.org/maven2/com/thoughtworks/xstream/xstream/1.4.4/xstream-1.4.4.jar (483 kB at 33 kB/s)
Error injecting: org.apache.maven.plugin.war.WarMojo
com.google.inject.ProvisionException: Unable to provision, see the following errors:

1) Error injecting constructor, java.lang.ExceptionInInitializerError
  at org.apache.maven.plugin.war.WarMojo.<init>(Unknown Source)
  while locating org.apache.maven.plugin.war.WarMojo

1 error
    at com.google.inject.internal.InternalProvisionException.toProvisionException (InternalProvisionException.java:226)
    at com.google.inject.internal.InjectorImpl$1.get (InjectorImpl.java:1053)
    at com.google.inject.internal.InjectorImpl.getInstance (InjectorImpl.java:1086)
    at org.eclipse.sisu.space.AbstractDeferredClass.get (AbstractDeferredClass.java:48)
    at com.google.inject.internal.ProviderInternalFactory.provision (ProviderInternalFactory.java:85)

Failed to execute goal org.apache.maven.plugins:maven-war-plugin:2.3:war (default-war) on project primera_web: Execution default-war of goal org.apache.maven.plugins:maven-war-plugin:2.3:war failed: Unable to load the mojo ‘war’ in the plugin ‘org.apache.maven.plugins:maven-war-plugin:2.3’ due to an API incompatibility: org.codehaus.plexus.component.repository.exception.ComponentLookupException: null

realm =    plugin>org.apache.maven.plugins:maven-war-plugin:2.3
strategy = org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy
urls[0] = file:/C:/Users/HP/.m2/repository/org/apache/maven/plugins/maven-war-plugin/2.3/maven-war-plugin-2.3.jar
urls[1] = file:/C:/Users/HP/.m2/repository/org/apache/maven/reporting/maven-reporting-api/2.0.6/maven-reporting-api-2.0.6.jar
urls[2] = file:/C:/Users/HP/.m2/repository/org/apache/maven/doxia/doxia-sink-api/1.0-alpha-7/doxia-sink-api-1.0-alpha-7.jar
urls[3] = file:/C:/Users/HP/.m2/repository/commons-cli/commons-cli/1.0/commons-cli-1.0.jar

Number of foreign imports: 1
import: Entry[import  from realm ClassRealm[maven.api, parent: null]]

-----------------------------------------------------
: ExceptionInInitializerError: Unable to make field private final java.util.Comparator java.util.TreeMap.comparator accessible: module java.base does not "opens java.util" to unnamed module @5c82031b
-> [Help 1]

To see the full stack trace of the errors, re-run Maven with the -e switch.
Re-run Maven using the -X switch to enable full debug logging.

For more information about the errors and possible solutions, please read the following articles:
[Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginContainerException

file pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<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/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.mycompany</groupId>
    <artifactId>primera_web</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>war</packaging>

    <name>primera_web</name>

    <properties>
        <endorsed.dir>${project.build.directory}/endorsed</endorsed.dir>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>
    
    <dependencies>
        <dependency>
            <groupId>javax</groupId>
            <artifactId>javaee-web-api</artifactId>
            <version>7.0</version>
            <scope>provided</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.1</version>
                <configuration>
                    <source>1.7</source>
                    <target>1.7</target>
                    <compilerArguments>
                        <endorseddirs>${endorsed.dir}</endorseddirs>
                    </compilerArguments>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <version>2.3</version>
                <configuration>
                    <failOnMissingWebXml>false</failOnMissingWebXml>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <version>2.6</version>
                <executions>
                    <execution>
                        <phase>validate</phase>
                        <goals>
                            <goal>copy</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>${endorsed.dir}</outputDirectory>
                            <silent>true</silent>
                            <artifactItems>
                                <artifactItem>
                                    <groupId>javax</groupId>
                                    <artifactId>javaee-endorsed-api</artifactId>
                                    <version>7.0</version>
                                    <type>jar</type>
                                </artifactItem>
                            </artifactItems>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

suggestions to solve the problem ??

asked Apr 2, 2021 at 14:08

Zarcor's user avatar

2

I had the same problem. I am using Eclipse Jun 2021 release. The problem got resolved after manually configuring one of the recent war plug-ins in POM.xml.

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-war-plugin</artifactId>
    <version>3.3.1</version>
</plugin>

answered Jul 11, 2021 at 16:21

Vikram's user avatar

VikramVikram

8814 silver badges8 bronze badges

4

I experienced the same issue after upgrading from JDK 1.8 to JDK 17 and I solved it by upgrading the plugin version.

Before:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-war-plugin</artifactId>
    <version>2.3</version>
</plugin>

After:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-war-plugin</artifactId>
    <version>3.3.1</version>
</plugin>

Laurel's user avatar

Laurel

5,98514 gold badges31 silver badges58 bronze badges

answered Jun 13, 2022 at 7:44

SANGWA Emmanuel's user avatar

0

if you want to deploy the war. what worked for me is both

<plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-war-plugin</artifactId>
            <version>3.3.1</version>
            <configuration>
                <failOnMissingWebXml>false</failOnMissingWebXml>
            </configuration>
        </plugin>

and

<plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <inherited>true</inherited>
            <version>3.8.1</version>
            <configuration>
                <source>16</source>
                <target>16</target>
                <compilerArguments>
                    <endorseddirs>${endorsed.dir}</endorseddirs>
                </compilerArguments>
            </configuration>
        </plugin>

Please note the versions.

Dharman's user avatar

Dharman

31.1k25 gold badges87 silver badges137 bronze badges

answered Aug 24, 2021 at 21:25

Ramdane Oualitsen's user avatar

You can fix it by changing the JDK in your projects to JDK 14. Left-click on your project and go to properties -> build -> compile . Change the JDK to version 14. If you don’t have JDK 14, you can manage it there by clicking Manage Java Platforms. The download of the JDK is here.

answered Apr 11, 2021 at 12:22

Phillip's user avatar

PhillipPhillip

871 silver badge12 bronze badges

Your pom.xml like this will 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/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.example</groupId>
    <artifactId>vysample</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>war</packaging>
    <name>vysample-1.0-SNAPSHOT</name>
    
    <properties>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
        <endorsed.dir>${project.build.directory}/endorsed</endorsed.dir>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <failOnMissingWebXml>false</failOnMissingWebXml>
        <jakartaee>9.0.0</jakartaee>
    </properties>
    
    <dependencies>
        <dependency>
            <groupId>jakarta.platform</groupId>
            <artifactId>jakarta.jakartaee-api</artifactId>
            <version>${jakartaee}</version>
            <scope>provided</scope>
        </dependency>
        
    </dependencies>
    
    <build>
        <plugins>            
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.1</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                    <compilerArguments>
                        <endorseddirs>${endorsed.dir}</endorseddirs>
                    </compilerArguments>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <version>3.3.2</version>
                <configuration>
                    <failOnMissingWebXml>false</failOnMissingWebXml>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <version>2.6</version>
                <executions>
                    <execution>
                        <phase>validate</phase>
                        <goals>
                            <goal>copy</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>${endorsed.dir}</outputDirectory>
                            <silent>true</silent>
                            <artifactItems>
                                <artifactItem>
                                    <groupId>jakarta.platform</groupId>
                                    <artifactId>jakarta.jakartaee-api</artifactId>
                                    <version>${jakartaee}</version>
                                    <type>jar</type>
                                </artifactItem>
                            </artifactItems>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

Focus at

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-war-plugin</artifactId>
    <version>3.3.2</version>
    <configuration>
        <failOnMissingWebXml>false</failOnMissingWebXml>
    </configuration>
</plugin>

answered Jul 13, 2022 at 13:44

Vy Do's user avatar

Vy DoVy Do

46.9k60 gold badges215 silver badges318 bronze badges

I resolved this error by adding following part in pom.xml

 <build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-war-plugin</artifactId>
            <version>3.3.1</version>
            <configuration>
                <source>1.8</source>
                <target>1.8</target>
                <failOnMissingWebXml>false</failOnMissingWebXml>
            </configuration>

        </plugin>

    </plugins>
</build>

apart from that i added maven configuration properties

<properties>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
</properties>

and here is my entire file as following

<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.groupId</groupId>
<artifactId>com.artifactId</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<properties>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
</properties>
<dependencies>
    <!-- https://mvnrepository.com/artifact/io.rest-assured/rest-assured -->
    <dependency>
    
        <groupId>io.rest-assured</groupId>
        <artifactId>rest-assured</artifactId>
        <version>5.3.0</version>

    </dependency>

</dependencies>


<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-war-plugin</artifactId>
            <version>3.3.1</version>
            <configuration>
                <source>1.8</source>
                <target>1.8</target>
                <failOnMissingWebXml>false</failOnMissingWebXml>
            </configuration>

        </plugin>

    </plugins>
</build>

answered Jan 12 at 6:58

Parameshwar's user avatar

ParameshwarParameshwar

8568 silver badges16 bronze badges

My problem got resolved after manually configuring war plug-in in POM.xml and then do clean install

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-war-plugin</artifactId>
    <version>3.3.1</version>
</plugin>

Then in the terminal, do a clean install, as:

mvn clean install

This should give you the war file (javaj22ee.war) status like:

[INFO] Building war: /Users/my_proj/java/javaj2ee/target/javaj2ee.war
[INFO]
[INFO] --- install:3.1.1:install (default-install) @ javaj2ee ---
[INFO] Installing /Users/my_proj/java/javaj2ee/pom.xml to 
/Users/.m2/repository/org/example/javaj2ee/1.0-SNAPSHOT/javaj2ee-1.0- 
SNAPSHOT.pom
[INFO] Installing /Users/my_proj/java/javaj2ee/target/javaj2ee.war to 
/Users/.m2/repository/org/example/javaj2ee/1.0-SNAPSHOT/javaj2ee-1.0- 
SNAPSHOT.war
[INFO] -----------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ----------------------------------------------------------------- 
[INFO] Total time:  8.506 s
[INFO] Finished at: 2023-09-04T18:37:31+05:30
[INFO] ----------------------------------------------------------------- 

answered Sep 4 at 13:20

Vidz's user avatar

VidzVidz

5551 gold badge6 silver badges16 bronze badges

I have solved this by simply going in the Jenkins global tool configuration and changing the path of JDK to /usr/local/Cellar/openjdk@11/11.0.10.
Previously it was /usr/local/Cellar/openjdk/16.0.1 in my local machine MAC.

Click here to see

This was the error :

Downloaded from central: https://repo.maven.apache.org/maven2/com/thoughtworks/xstream/xstream/1.3.1/xstream-1.3.1.jar (431 kB at 529 kB/s)
11:52:49 [WARNING] Error injecting: org.apache.maven.plugin.war.WarMojo
11:52:49 com.google.inject.ProvisionException: Unable to provision, see the following errors:
11:52:49 
11:52:49 1) Error injecting constructor, java.lang.ExceptionInInitializerError: Cannot access defaults field of Properties
11:52:49   at org.apache.maven.plugin.war.WarMojo.<init>(Unknown Source)

Sanket Singh's user avatar

Sanket Singh

1,2661 gold badge10 silver badges26 bronze badges

answered Jul 18, 2021 at 6:40

Nirbhay Singh's user avatar

Eclipse 2021-06 release by default JDK will be set to 16. So changed to your preferred JDK version. or configure your default JDK to run
enter image description here

maven-war-plugin:3.0.0:war (default-war) @ projectname 
--- [WARNING] Error injecting: org.apache.maven.plugins.war.WarMojo 
com.google.inject.ProvisionException: Unable to provision, 
see the following errors: 1) Error injecting constructor,
java.lang.ExceptionInInitializerError 
at org.apache.maven.plugins.war.WarMojo.<init>(Unknown Source)

answered Jul 31, 2021 at 17:34

Nɪsʜᴀɴᴛʜ ॐ's user avatar

Nɪsʜᴀɴᴛʜ ॐNɪsʜᴀɴᴛʜ ॐ

2,7764 gold badges33 silver badges57 bronze badges

I had this exact same issue. After updating the POM file, I needed to delete my .m2/repository folder before running mvn install for the project.

answered May 19, 2022 at 16:54

user19155519's user avatar

I had the same problems and I resolved changed the version 2.3 to 3.3.1

<plugin>
   <groupId>org.apache.maven.plugins</groupId>
   <artifactId>maven-war-plugin</artifactId>
   <version>3.3.1</version>
   <configuration>
      <failOnMissingWebXml>false</failOnMissingWebXml>
   </configuration>
</plugin>

enter image description here
enter image description here

answered May 27, 2022 at 22:41

Eduardo Guerra Alvarez's user avatar

Problem has been resolved by stopping the Tomcat server
sudo systemctl stop tomcat
so as to allow Netbeans to run it. If the server is already running when Netbeans tries to deploy an app Netbeans will display the delopy failed message.

answered Nov 13, 2022 at 23:34

minc84's user avatar

I’m experiencing the same issue when combined with file-loader + oneOf.

Simplified repro on webpack 5, modified example/webpack.config.js to:

const InjectPlugin = require('..').default;

module.exports = {
  entry: './entry.js',
  mode: 'development',
  plugins: [
    new InjectPlugin(() => `console.log('hello world');`),
    new InjectPlugin(() => `console.log('second injected code');`)
  ],
  module: {
    rules: [
      {
        oneOf: [
          {
            exclude: [/webpack-inject/],
            loader: require.resolve('file-loader'),
          }
        ]
      }
    ]
  }
};

Seems like now its trying to use file-loader on webpack-inject-plugin.loader.js?id=webpack-inject-module-1. Tried excluding it but haven’t been able to get it to work yet.

Will try to investigate a bit more, lmk if you have any ideas @adierkens 🙏

Hello Guys, How are you all? Hope You all Are Fine. Today I am trying to run my java application but I am facing following error Error injecting: org.apache.maven.plugin.war.WarMojo com.google.inject.ProvisionException: Unable to provision in Java. So Here I am Explain to you all the possible solutions here.

Without wasting your time, Let’s start This Article to Solve This Error.

Contents

  1. How This Error Occurs ?
  2. How To Solve Error injecting: org.apache.maven.plugin.war.WarMojo com.google.inject.ProvisionException: Unable to provision Error ?
  3. Solution 1: configure war plugin
  4. Solution 2: Change JDK for your project
  5. Summary

How This Error Occurs ?

I am trying to run my java application but I am facing following error.

Error injecting: org.apache.maven.plugin.war.WarMojo com.google.inject.ProvisionException: Unable to provision, see the following errors:

Error injecting constructor, java.lang.ExceptionInInitializerError at org.apache.maven.plugin.war.WarMojo.<init>(Unknown Source) while locating org.apache.maven.plugin.war.WarMojo

  1. How To Solve Error injecting: org.apache.maven.plugin.war.WarMojo com.google.inject.ProvisionException: Unable to provision Error ?

    To Solve Error injecting: org.apache.maven.plugin.war.WarMojo com.google.inject.ProvisionException: Unable to provision Error Just configure war plugin in your POM.xml. Second one is Just Change your JDK for particular Project. Follow this step. First of all Left-click on your project.Then, Select Properties.now, Select Build.Select compile.Change the JDK to version 14.If you don’t have JDK 14 then The download of the JDK is here.Now, Your issue will be fix.

  2. Error injecting: org.apache.maven.plugin.war.WarMojo com.google.inject.ProvisionException: Unable to provision

    To Solve Error injecting: org.apache.maven.plugin.war.WarMojo com.google.inject.ProvisionException: Unable to provision Error Just configure war plugin in your POM.xml. Second one is Just Change your JDK for particular Project. Follow this step. First of all Left-click on your project.Then, Select Properties.now, Select Build.Select compile.Change the JDK to version 14.If you don’t have JDK 14 then The download of the JDK is here.Now, Your issue will be fix.

Solution 1: configure war plugin

Just configure war plugin in your POM.xml like this.

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-war-plugin</artifactId>
    <version>3.3.2</version>
</plugin>

Solution 2: Change JDK for your project

Just Change your JDK for particular Project. Follow this step.

  1. First of all Left-click on your project.
  2. Then, Select Properties.
  3. now, Select Build.
  4. Select compile.
  5. Change the JDK to version 14.
  6. If you don’t have JDK 14 then The download of the JDK is here.
  7. Now, Your issue will be fix.

Summary

It’s all About this issue. Hope all solution helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which solution worked for you?

Also, Read

  • java.lang.reflect.InaccessibleObjectException: Unable to make protected final java.lang.Class

Issue

I created a controller plugin to be used global in every component, but I can’t make it work with Vue 3 + TypeScript + Composition API I get a TypeScript error

ui/plugins/controllers.ts

import { App } from 'vue'
import { provider, IProvider } from '@/core/presentation/provider'

export default {
  install: (app: App) => {
    const controllers: IProvider = provider()
    app.provide('controllers', controllers)
  }
}

main.ts

import { createApp } from 'vue'
import { controllers } from './ui'

createApp(App)
  .use(controllers)
  .mount('#app')

@/core/presentation/provider/provider.ts

import { UserController } from '../controllers'
import { IProvider } from './provider.types'

export const provider = (): IProvider => ({
  users: new UserController()
})

ui/views/Component.vue

import { onMounted, ref, inject, defineComponent } from 'vue'

export default defineComponent({
  setup() {
    const controllers = inject('controllers')

    const user = ref()
    const getUser = async () => {
      const result = await controllers.users.getById(1)
      if (result) {
        user.value = result.toJson()
      }
    }

    onMounted(getUser)

    return {
      user,
      getUser
    }
  }
})

Here I get a typescript error when I try to use the controller at this line

const result = await controllers.users.getById(1)

Error:

const controllers: unknown
Object is of type 'unknown'.Vetur(2571)

If I set the type with my interface like this I get another typescript error

import { IProvider } from '@/core'
...
const controllers: IProvider  = inject('controllers')

Error:

type 'IProvider | undefined' is not assignable to type 'IProvider'.
Type 'undefined' is not assignable to type 'IProvider'.Vetur(2322)

I can only make it work like this but I think it’s weird:

const controllers: IProvider | undefined = inject('controllers')
...
const result = await controllers?.users.getById(1)

Solution

I managed to solve my problem with post Type-safe Vue.js Injections

One thing to note is that the inject function produces the resolved type in union with undefined. This is because there is the possibility that the injection is not resolved. It’s up to you how you want to handle it.

So to deal with undefined I followed his advice and create an injectStrict function. Here is my final code:

Component.vue

import { IProvider } from '@/core'
import { injectStrict } from '@/ui/utils'
import { onMounted, ref, defineComponent } from 'vue'

export default defineComponent({
  setup() {
    const controllers: IProvider = injectStrict('controllers')
    const user = ref()
    const getUser = async () => {
      const result = await controllers.users.getById(1)
      if (result) {
        user.value = result.toObj()
      }
    }

    onMounted(getUser)

    return {
      user,
      getUser
    }
  }
})

@/utils/injections.ts

import { inject } from 'vue'

function injectStrict<T>(key: string, fallback?: T) {
  const resolved = inject(key, fallback)
  if (!resolved) {
    throw new Error(`Could not resolve ${key}`)
  }

  return resolved
}

export { injectStrict }

Answered By – ocordova

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Hello Guys, How are you all? Hope You all Are Fine. Today I am trying to run my java application but I am facing following error Error injecting: org.apache.maven.plugin.war.WarMojo com.google.inject.ProvisionException: Unable to provision in Java. So Here I am Explain to you all the possible solutions here.

Without wasting your time, Let’s start This Article to Solve This Error.

Contents

  1. How This Error Occurs ?
  2. How To Solve Error injecting: org.apache.maven.plugin.war.WarMojo com.google.inject.ProvisionException: Unable to provision Error ?
  3. Solution 1: configure war plugin
  4. Solution 2: Change JDK for your project
  5. Summary

How This Error Occurs ?

I am trying to run my java application but I am facing following error.

Error injecting: org.apache.maven.plugin.war.WarMojo com.google.inject.ProvisionException: Unable to provision, see the following errors:

Error injecting constructor, java.lang.ExceptionInInitializerError at org.apache.maven.plugin.war.WarMojo.<init>(Unknown Source) while locating org.apache.maven.plugin.war.WarMojo

  1. How To Solve Error injecting: org.apache.maven.plugin.war.WarMojo com.google.inject.ProvisionException: Unable to provision Error ?

    To Solve Error injecting: org.apache.maven.plugin.war.WarMojo com.google.inject.ProvisionException: Unable to provision Error Just configure war plugin in your POM.xml. Second one is Just Change your JDK for particular Project. Follow this step. First of all Left-click on your project.Then, Select Properties.now, Select Build.Select compile.Change the JDK to version 14.If you don’t have JDK 14 then The download of the JDK is here.Now, Your issue will be fix.

  2. Error injecting: org.apache.maven.plugin.war.WarMojo com.google.inject.ProvisionException: Unable to provision

    To Solve Error injecting: org.apache.maven.plugin.war.WarMojo com.google.inject.ProvisionException: Unable to provision Error Just configure war plugin in your POM.xml. Second one is Just Change your JDK for particular Project. Follow this step. First of all Left-click on your project.Then, Select Properties.now, Select Build.Select compile.Change the JDK to version 14.If you don’t have JDK 14 then The download of the JDK is here.Now, Your issue will be fix.

Solution 1: configure war plugin

Just configure war plugin in your POM.xml like this.

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-war-plugin</artifactId>
    <version>3.3.2</version>
</plugin>

Solution 2: Change JDK for your project

Just Change your JDK for particular Project. Follow this step.

  1. First of all Left-click on your project.
  2. Then, Select Properties.
  3. now, Select Build.
  4. Select compile.
  5. Change the JDK to version 14.
  6. If you don’t have JDK 14 then The download of the JDK is here.
  7. Now, Your issue will be fix.

Summary

It’s all About this issue. Hope all solution helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which solution worked for you?

Also, Read

  • java.lang.reflect.InaccessibleObjectException: Unable to make protected final java.lang.Class

Introduction

This article is actually an additional article. It is very important to add the solution for solving an error in another article. Actually, there is an article How to Solve Error Message Failed to execute goal org.apache.maven.plugins:maven-war-plugin:2.2:war (default-war) on project myapp: Execution default-war of goal org.apache.maven.plugins:maven-war-plugin:2.2:war failed: Unable to load the mojo ‘war’ in the plugin ‘org.apache.maven.plugins:maven-war-plugin:2.2’ due to an API incompatibility: org.codehaus.plexus.component.repository.exception.ComponentLookupException: Cannot access defaults field of Properties when Build and Compile Java Application. Furthermore, the actual error message which is the focus for further solution is in this article. Below is the actual error message appear :

Error injecting: org.apache.maven.plugin.war.WarMojo
com.google.inject.ProvisionException: Unable to provision, see the following errors:
...
...
...

Basically, the problem exist in the ‘pom.xml’ file. The solution in the previous article mentioned to edit the ‘pom.xml’ as follows :

<?xml version="1.0"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.github.adminfaces</groupId>
    <artifactId>projectf</artifactId>
    <version>0.1-SNAPSHOT</version>
    <packaging>war</packaging>
    <name>myapp</name>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>hjojoj
    </properties>
 
    <dependencies>
         <dependency>
             <groupId>javax</groupId>
             <artifactId>javaee-api</artifactId>
             <version>7.0</version>
             <scope>provided</scope>
         </dependency>
    </dependencies>
    <build>
         <resources>
             <resource>
                 <filtering>true</filtering>
                 <directory>src/main/resources</directory>
             </resource>
             <resource>
                 <directory>src/main/docs</directory>
                 <filtering>true</filtering>
             </resource>
             <resource>
                 <directory>src/main/java</directory>
                 <includes>
                     <include>**/*.xml</include>
                     <include>**/*.properties</include>
                 </includes>
             </resource>
         </resources>
         <testResources>
             <testResource>
                  <filtering>true</filtering>
                  <directory>src/test/resources</directory>
             </testResource>
             <testResource>
                  <directory>src/test/java/</directory>
             </testResource>
         </testResources>
         <plugins>
             <plugin>
                  <artifactId>maven-compiler-plugin</artifactId>
                  <version>3.3</version>
                  <configuration>
                       <source>1.8</source>
                       <target>1.8</target>
                  </configuration>
             </plugin>
         </plugins>
         <finalName>myapp</finalName>
    </build>
    <repositories>
        <repository>
            <id>prime-repo</id>
            <name>PrimeFaces Maven Repository</name>
            <url>https://repository.primefaces.org</url>
            <layout>default</layout>
        </repository>
   </repositories>
</project>

As for the solution, just another snippet code of pom.xml file configuration. The following are those lines of configuration which is adding a plugin as follows :

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>3.3.1</version>
</plugin>

In that case, the complete modification of the ‘pom.xml’ will exist as follows :

<?xml version="1.0"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.github.adminfaces</groupId>
    <artifactId>projectf</artifactId>
    <version>0.1-SNAPSHOT</version>
    <packaging>war</packaging>
    <name>myapp</name>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>hjojoj
    </properties>
 
    <dependencies>
         <dependency>
             <groupId>javax</groupId>
             <artifactId>javaee-api</artifactId>
             <version>7.0</version>
             <scope>provided</scope>
         </dependency>
    </dependencies>
    <build>
         <resources>
             <resource>
                 <filtering>true</filtering>
                 <directory>src/main/resources</directory>
             </resource>
             <resource>
                 <directory>src/main/docs</directory>
                 <filtering>true</filtering>
             </resource>
             <resource>
                 <directory>src/main/java</directory>
                 <includes>
                     <include>**/*.xml</include>
                     <include>**/*.properties</include>
                 </includes>
             </resource>
         </resources>
         <testResources>
             <testResource>
                  <filtering>true</filtering>
                  <directory>src/test/resources</directory>
             </testResource>
             <testResource>
                  <directory>src/test/java/</directory>
             </testResource>
         </testResources>
         <plugins>
             <plugin>
                  <artifactId>maven-compiler-plugin</artifactId>
                  <version>3.3</version>
                  <configuration>
                       <source>1.8</source>
                       <target>1.8</target>
                  </configuration>
             </plugin>
             <plugin>
                  <groupId>org.apache.maven.plugins</groupId>
                  <artifactId>maven-war-plugin</artifactId>
                  <version>3.3.1</version>
                  </plugin>
         </plugins>
         <finalName>myapp</finalName>
    </build>
    <repositories>
        <repository>
            <id>prime-repo</id>
            <name>PrimeFaces Maven Repository</name>
            <url>https://repository.primefaces.org</url>
            <layout>default</layout>
        </repository>
   </repositories>
</project>

Off course in the dependency section, just add the suitable library package for the Java application. After that, just build and compile it once more. If there are no further error message, the process for building and compiling the Java application will end in a success.

Issue

I use the newest version of Java -> 16. When I run mvn clean, I am getting Could not initialize class org.apache.maven.plugin.war.util.WebappStructureSerializer error. I read that adding maven-war-plugin can be a solution, but it didn’t work for me. When I run mvn install, the following error occurs:

Error injecting constructor, java.lang.ExceptionInInitializerError:
Cannot access defaults field of Properties at
org.apache.maven.plugin.war.WarMojo.(Unknown Source) while
locating org.apache.maven.plugin.war.WarMojo

How can I solve these problems? Are they caused by the Java version?

<modelVersion>4.0.0</modelVersion>

<groupId>web-programming</groupId>
<artifactId>servlet-demo</artifactId>
<packaging>war</packaging>
<version>1.0-SNAPSHOT</version>

<properties>
    <java.version>16</java.version>
    <maven.compiler.target>${java.version}</maven.compiler.target>
    <maven.compiler.source>${java.version}</maven.compiler.source>
</properties>

<dependencies>

    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>javax.servlet-api</artifactId>
        <version>3.1.0</version>
        <scope>provided</scope>
    </dependency>

    <dependency>
        <groupId>org.junit.jupiter</groupId>
        <artifactId>junit-jupiter-engine</artifactId>
        <version>5.1.1</version>
        <scope>test</scope>
    </dependency>
</dependencies>

<build>
    <plugins>
        <!-- Optional. Allows the app to be run by simply typing mvn jetty:run -->
        <plugin>
            <groupId>org.mortbay.jetty</groupId>
            <artifactId>maven-jetty-plugin</artifactId>
            <version>6.1.4</version>
            <dependencies>
                <dependency>
                    <groupId>log4j</groupId>
                    <artifactId>log4j</artifactId>
                    <version>1.2.13</version>
                </dependency>
            </dependencies>
            <configuration>
                <contextPath>/</contextPath>
                <scanIntervalSeconds>10</scanIntervalSeconds>
                <connectors>
                    <connector
                        implementation="org.mortbay.jetty.nio.SelectChannelConnector">
                        <port>9090</port>
                    </connector>
                </connectors>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-war-plugin</artifactId>
            <version>2.2</version>
        </plugin>
    </plugins>
</build>

Solution

Change the version of the war plugin in your pom.xml and add maven-compiler-plugin according to your jdk version.

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-war-plugin</artifactId>
    <version>3.3.1</version>
</plugin>
<plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-compiler-plugin</artifactId>
      <version>3.8.1</version>
</plugin>

Answered By — Akshay
Answer Checked By — Terry (JavaFixing Volunteer)

I had the same problem. I am using Eclipse Jun 2021 release. The problem got resolved after manually configuring one of the recent war plug-ins in POM.xml.

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-war-plugin</artifactId>
    <version>3.3.1</version>
</plugin>

You can fix it by changing the JDK in your projects to JDK 14. Left-click on your project and go to properties -> build -> compile . Change the JDK to version 14. If you dont have JDK 14, you can manage it there by clicking Manage Java Platforms. The download of the JDK is here.

java – Error injecting: org.apache.maven.plugin.war.WarMojo

I have solved this by simply going in the Jenkins global tool configuration and changing the path of JDK to /usr/local/Cellar/[email protected]/11.0.10.
Previously it was /usr/local/Cellar/openjdk/16.0.1 in my local machine MAC.

Click here to see

This was the error :

Downloaded from central: https://repo.maven.apache.org/maven2/com/thoughtworks/xstream/xstream/1.3.1/xstream-1.3.1.jar (431 kB at 529 kB/s)
11:52:49 [WARNING] Error injecting: org.apache.maven.plugin.war.WarMojo
11:52:49 com.google.inject.ProvisionException: Unable to provision, see the following errors:
11:52:49 
11:52:49 1) Error injecting constructor, java.lang.ExceptionInInitializerError: Cannot access defaults field of Properties
11:52:49   at org.apache.maven.plugin.war.WarMojo.<init>(Unknown Source)

Are you having problems with the issue “Error injecting: org.apache.maven.plugin.war.WarMojo com.google.inject.ProvisionException: Unable to provision“? How to fix it? In today’s article, I will provide solutions for you to solve the issues. Please follow the below steps to get the problem resolved now

How did “Error injecting: org.apache.maven.plugin.war.WarMojo com.google.inject.ProvisionException: Unable to provision” occur?

Error injecting: org.apache.maven.plugin.war.WarMojo com.google.inject.ProvisionException: Unable to provision

When you work with JAVA, you may get the issue Error injecting: org.apache.maven.plugin.war.WarMojo com.google.inject.ProvisionException: Unable to provision. Don’t worry, we are here to provide you solutions in order to resolve your problem.

How to fix “Error injecting: org.apache.maven.plugin.war.WarMojo com.google.inject.ProvisionException: Unable to provision”?

To Solve Error injecting: org.apache.maven.plugin.war.WarMojo com.google.inject.ProvisionException: Unable to provision Error Just configure war plugin in your POM.xml. The second is to modify your JDK for a particular Project. This is the second step. Follow this step.

Solution 1: Configure war plugin

Simply configure the war plugin in your POM.xml as follows.

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-war-plugin</artifactId>
    <version>3.3.2</version>
</plugin>

Solution 2: Modify the JDK to suit your project

Simply change your JDK to suit a particular project. This is how it works.

  1. First, Left-click on the project.
  2. Select Properties.
  3. Now, select Build.
  4. Choose compile.
  5. Change the JDK version to 14.
  6. You don’t need JDK 14, then you can download it .
  7. You can now fix your problem.

Final words

The above are useful solutions that can help you fix “Error injecting: org.apache.maven.plugin.war.WarMojo com.google.inject.ProvisionException: Unable to provision” problem, if you can’t solve it well. Please leave a message.

Понравилась статья? Поделить с друзьями:
  • Ошибка f05 видеомагнитофон panasonic
  • Ошибка kadena keesler
  • Ошибка initializeprintprovider для поставщика localspl dll
  • Ошибка f044 на газовом счетчике что это
  • Ошибка jvcu камаз нео что означает