# Projekt mit Maven kompilieren



## Kirby.exe (13. Aug 2021)

Ich versuche gerade mein Java Projekt mit Maven via Command Line zu kompilieren, aber ich erhalte den folgenden Fehler:


```
mvn -X
Apache Maven 3.6.3
Maven home: /usr/share/maven
Java version: 16.0.1, vendor: Private Build, runtime: /usr/lib/jvm/java-16-openjdk-amd64
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "5.11.0-25-generic", arch: "amd64", family: "unix"
[ERROR] Error executing Maven.
com.google.common.util.concurrent.UncheckedExecutionException: java.lang.IllegalStateException: Unable to load cache item
    at com.google.common.cache.LocalCache$Segment.get (LocalCache.java:2205)
    at com.google.common.cache.LocalCache.get (LocalCache.java:3951)
    at com.google.common.cache.LocalCache.getOrLoad (LocalCache.java:3955)
    at com.google.common.cache.LocalCache$LocalLoadingCache.get (LocalCache.java:4870)
    at com.google.common.cache.LocalCache$LocalLoadingCache.getUnchecked (LocalCache.java:4876)
    at com.google.inject.internal.FailableCache.get (FailableCache.java:51)
    at com.google.inject.internal.ConstructorInjectorStore.get (ConstructorInjectorStore.java:48)
    at com.google.inject.internal.ConstructorBindingImpl.initialize (ConstructorBindingImpl.java:155)
    at com.google.inject.internal.InjectorImpl.initializeBinding (InjectorImpl.java:581)
    at com.google.inject.internal.AbstractBindingProcessor$Processor$1.run (AbstractBindingProcessor.java:176)
    at com.google.inject.internal.ProcessedBindingData.initializeBindings (ProcessedBindingData.java:49)
    at com.google.inject.internal.InternalInjectorCreator.initializeStatically (InternalInjectorCreator.java:122)
    at com.google.inject.internal.InternalInjectorCreator.build (InternalInjectorCreator.java:106)
    at com.google.inject.Guice.createInjector (Guice.java:87)
    at com.google.inject.Guice.createInjector (Guice.java:69)
    at com.google.inject.Guice.createInjector (Guice.java:59)
    at org.codehaus.plexus.DefaultPlexusContainer.addPlexusInjector (DefaultPlexusContainer.java:481)
    at org.codehaus.plexus.DefaultPlexusContainer.<init> (DefaultPlexusContainer.java:206)
    at org.apache.maven.cli.MavenCli.container (MavenCli.java:636)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:282)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:193)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:78)
    at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:567)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:282)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:225)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:406)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:347)
Caused by: java.lang.IllegalStateException: Unable to load cache item
    at com.google.inject.internal.cglib.core.internal.$LoadingCache.createEntry (LoadingCache.java:79)
    at com.google.inject.internal.cglib.core.internal.$LoadingCache.get (LoadingCache.java:34)
    at com.google.inject.internal.cglib.core.$AbstractClassGenerator$ClassLoaderData.get (AbstractClassGenerator.java:116)
    at com.google.inject.internal.cglib.core.$AbstractClassGenerator.create (AbstractClassGenerator.java:291)
    at com.google.inject.internal.cglib.reflect.$FastClass$Generator.create (FastClass.java:65)
    at com.google.inject.internal.BytecodeGen.newFastClassForMember (BytecodeGen.java:258)
    at com.google.inject.internal.BytecodeGen.newFastClassForMember (BytecodeGen.java:207)
    at com.google.inject.internal.DefaultConstructionProxyFactory.create (DefaultConstructionProxyFactory.java:49)
    at com.google.inject.internal.ProxyFactory.create (ProxyFactory.java:156)
    at com.google.inject.internal.ConstructorInjectorStore.createConstructor (ConstructorInjectorStore.java:92)
    at com.google.inject.internal.ConstructorInjectorStore.access$000 (ConstructorInjectorStore.java:29)
    at com.google.inject.internal.ConstructorInjectorStore$1.create (ConstructorInjectorStore.java:37)
    at com.google.inject.internal.ConstructorInjectorStore$1.create (ConstructorInjectorStore.java:33)
    at com.google.inject.internal.FailableCache$1.load (FailableCache.java:40)
    at com.google.common.cache.LocalCache$LoadingValueReference.loadFuture (LocalCache.java:3540)
    at com.google.common.cache.LocalCache$Segment.loadSync (LocalCache.java:2321)
    at com.google.common.cache.LocalCache$Segment.lockedGetOrLoad (LocalCache.java:2284)
    at com.google.common.cache.LocalCache$Segment.get (LocalCache.java:2199)
    at com.google.common.cache.LocalCache.get (LocalCache.java:3951)
    at com.google.common.cache.LocalCache.getOrLoad (LocalCache.java:3955)
    at com.google.common.cache.LocalCache$LocalLoadingCache.get (LocalCache.java:4870)
    at com.google.common.cache.LocalCache$LocalLoadingCache.getUnchecked (LocalCache.java:4876)
    at com.google.inject.internal.FailableCache.get (FailableCache.java:51)
    at com.google.inject.internal.ConstructorInjectorStore.get (ConstructorInjectorStore.java:48)
    at com.google.inject.internal.ConstructorBindingImpl.initialize (ConstructorBindingImpl.java:155)
    at com.google.inject.internal.InjectorImpl.initializeBinding (InjectorImpl.java:581)
    at com.google.inject.internal.AbstractBindingProcessor$Processor$1.run (AbstractBindingProcessor.java:176)
    at com.google.inject.internal.ProcessedBindingData.initializeBindings (ProcessedBindingData.java:49)
    at com.google.inject.internal.InternalInjectorCreator.initializeStatically (InternalInjectorCreator.java:122)
    at com.google.inject.internal.InternalInjectorCreator.build (InternalInjectorCreator.java:106)
    at com.google.inject.Guice.createInjector (Guice.java:87)
    at com.google.inject.Guice.createInjector (Guice.java:69)
    at com.google.inject.Guice.createInjector (Guice.java:59)
    at org.codehaus.plexus.DefaultPlexusContainer.addPlexusInjector (DefaultPlexusContainer.java:481)
    at org.codehaus.plexus.DefaultPlexusContainer.<init> (DefaultPlexusContainer.java:206)
    at org.apache.maven.cli.MavenCli.container (MavenCli.java:636)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:282)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:193)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:78)
    at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:567)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:282)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:225)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:406)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:347)
Caused by: java.lang.NoClassDefFoundError: Could not initialize class com.google.inject.internal.cglib.core.$MethodWrapper
    at com.google.inject.internal.cglib.core.$DuplicatesPredicate.evaluate (DuplicatesPredicate.java:104)
    at com.google.inject.internal.cglib.core.$CollectionUtils.filter (CollectionUtils.java:52)
    at com.google.inject.internal.cglib.reflect.$FastClassEmitter.<init> (FastClassEmitter.java:69)
    at com.google.inject.internal.cglib.reflect.$FastClass$Generator.generateClass (FastClass.java:77)
    at com.google.inject.internal.cglib.core.$DefaultGeneratorStrategy.generate (DefaultGeneratorStrategy.java:25)
    at com.google.inject.internal.cglib.core.$AbstractClassGenerator.generate (AbstractClassGenerator.java:329)
    at com.google.inject.internal.cglib.core.$AbstractClassGenerator$ClassLoaderData$3.apply (AbstractClassGenerator.java:93)
    at com.google.inject.internal.cglib.core.$AbstractClassGenerator$ClassLoaderData$3.apply (AbstractClassGenerator.java:91)
    at com.google.inject.internal.cglib.core.internal.$LoadingCache$2.call (LoadingCache.java:54)
    at java.util.concurrent.FutureTask.run (FutureTask.java:264)
    at com.google.inject.internal.cglib.core.internal.$LoadingCache.createEntry (LoadingCache.java:61)
    at com.google.inject.internal.cglib.core.internal.$LoadingCache.get (LoadingCache.java:34)
    at com.google.inject.internal.cglib.core.$AbstractClassGenerator$ClassLoaderData.get (AbstractClassGenerator.java:116)
    at com.google.inject.internal.cglib.core.$AbstractClassGenerator.create (AbstractClassGenerator.java:291)
    at com.google.inject.internal.cglib.reflect.$FastClass$Generator.create (FastClass.java:65)
    at com.google.inject.internal.BytecodeGen.newFastClassForMember (BytecodeGen.java:258)
    at com.google.inject.internal.BytecodeGen.newFastClassForMember (BytecodeGen.java:207)
    at com.google.inject.internal.DefaultConstructionProxyFactory.create (DefaultConstructionProxyFactory.java:49)
    at com.google.inject.internal.ProxyFactory.create (ProxyFactory.java:156)
    at com.google.inject.internal.ConstructorInjectorStore.createConstructor (ConstructorInjectorStore.java:92)
    at com.google.inject.internal.ConstructorInjectorStore.access$000 (ConstructorInjectorStore.java:29)
    at com.google.inject.internal.ConstructorInjectorStore$1.create (ConstructorInjectorStore.java:37)
    at com.google.inject.internal.ConstructorInjectorStore$1.create (ConstructorInjectorStore.java:33)
    at com.google.inject.internal.FailableCache$1.load (FailableCache.java:40)
    at com.google.common.cache.LocalCache$LoadingValueReference.loadFuture (LocalCache.java:3540)
    at com.google.common.cache.LocalCache$Segment.loadSync (LocalCache.java:2321)
    at com.google.common.cache.LocalCache$Segment.lockedGetOrLoad (LocalCache.java:2284)
    at com.google.common.cache.LocalCache$Segment.get (LocalCache.java:2199)
    at com.google.common.cache.LocalCache.get (LocalCache.java:3951)
    at com.google.common.cache.LocalCache.getOrLoad (LocalCache.java:3955)
    at com.google.common.cache.LocalCache$LocalLoadingCache.get (LocalCache.java:4870)
    at com.google.common.cache.LocalCache$LocalLoadingCache.getUnchecked (LocalCache.java:4876)
    at com.google.inject.internal.FailableCache.get (FailableCache.java:51)
    at com.google.inject.internal.ConstructorInjectorStore.get (ConstructorInjectorStore.java:48)
    at com.google.inject.internal.ConstructorBindingImpl.initialize (ConstructorBindingImpl.java:155)
    at com.google.inject.internal.InjectorImpl.initializeBinding (InjectorImpl.java:581)
    at com.google.inject.internal.AbstractBindingProcessor$Processor$1.run (AbstractBindingProcessor.java:176)
    at com.google.inject.internal.ProcessedBindingData.initializeBindings (ProcessedBindingData.java:49)
    at com.google.inject.internal.InternalInjectorCreator.initializeStatically (InternalInjectorCreator.java:122)
    at com.google.inject.internal.InternalInjectorCreator.build (InternalInjectorCreator.java:106)
    at com.google.inject.Guice.createInjector (Guice.java:87)
    at com.google.inject.Guice.createInjector (Guice.java:69)
    at com.google.inject.Guice.createInjector (Guice.java:59)
    at org.codehaus.plexus.DefaultPlexusContainer.addPlexusInjector (DefaultPlexusContainer.java:481)
    at org.codehaus.plexus.DefaultPlexusContainer.<init> (DefaultPlexusContainer.java:206)
    at org.apache.maven.cli.MavenCli.container (MavenCli.java:636)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:282)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:193)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:78)
    at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:567)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:282)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:225)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:406)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:347)
```

Ich hatte im Internet gelesen, dass das irgendwie mit der Java Version zusammenhängt, aber ich verstehe jetzt nicht wirklich wo ich was ändern soll...Das sind meine Java Installationen:

```
sudo apt install -y openjdk-16-jdk openjdk-16-jre
sudo apt install -y maven
```

Das ist meine 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>groupId</groupId>
    <artifactId>dbp-projekt</artifactId>
    <version>1.0-SNAPSHOT</version>

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

    <dependencies>
        <!-- https://mvnrepository.com/artifact/org.postgresql/postgresql -->
        <dependency>
            <groupId>org.postgresql</groupId>
            <artifactId>postgresql</artifactId>
            <version>42.2.23</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.mindrot/jbcrypt -->
        <dependency>
            <groupId>org.mindrot</groupId>
            <artifactId>jbcrypt</artifactId>
            <version>0.4</version>
        </dependency>
    </dependencies>
    
</project>
```


----------



## mrBrown (13. Aug 2021)

Update mal deine Maven-Version


----------



## kneitzel (13. Aug 2021)

Lad mal das aktuelle Maven direkt von der HP herunter, entpacke es und probiere es erst einmal damit.

In Debian Paketen gab es mal Probleme, die aber eigentlich behoben wurden,. Evtl. liegt es an sowas.

(3.8.1 ist aktuell aber auch 3.6.3 funktionierte bei mir bisher immer problemlos mit JDK 16)


----------



## Kirby.exe (13. Aug 2021)

Mhh also ich habe dass Gefühl das APT mein Java nicht richtig installiert hat, da JAVA_HOME fehlt...Ich vermute Maven möchte das gerne nutzen und schmeißt deswegen Error?


----------



## kneitzel (13. Aug 2021)

Maven braucht das JAVA_HOME und wenn es fehlt, dann kenne ich eigentlich eine klare Meldung, die das besagt....


----------



## sascha-sphw (13. Aug 2021)

Lösch mal den Maven Cache Ordner .m2. Ich hatte den Cache mal irgendwie kaputt gemacht, sodass Maven dachte die Lib wäre da, die Jar lag aber nicht im Ordner.


----------



## Kirby.exe (13. Aug 2021)

sascha-sphw hat gesagt.:


> Lösch mal den Maven Cache Ordner .m2. Ich hatte den Cache mal irgendwie kaputt gemacht, sodass Maven dachte die Lib wäre da, die Jar lag aber nicht im Ordner.


Hat leider nichts geholfen  Ist der selbe Fehler


----------



## sascha-sphw (13. Aug 2021)

Ein Versuch war es Wert.


----------



## Kirby.exe (13. Aug 2021)

Also ich habe probiert Maven so zu installieren von deren Homepage aber er finde es nicht...Habe hier mal das install script:


```
cd /usr/local/src
sudo wget https://mirror.synyx.de/apache/maven/maven-3/3.8.1/binaries/apache-maven-3.8.1-bin.tar.gz
sudo tar -zxvf apache-maven-3.8.1-bin.tar.gz
sudo mv apache-maven-3.8.1/ apache-maven/
cd /etc/profile.d/
sudo touch maven.sh
sudo echo '# Apache Maven Environment Variables' | sudo tee -a ~/.bashrc
sudo echo '# MAVEN_HOME for Maven 1 - M2_HOME for Maven 2' | sudo tee -a ~/.bashrc
sudo echo 'export JAVA_HOME=/usr/lib/jvm/java-8-oracle' | sudo tee -a ~/.bashrc
sudo echo 'export M2_HOME=/usr/local/src/apache-maven' | sudo tee -a ~/.bashrc
sudo echo 'export MAVEN_HOME=/usr/local/src/apache-maven' | sudo tee -a ~/.bashrc
sudo echo 'export PATH=${M2_HOME}/bin:${PATH}' | sudo tee -a ~/.bashrc
```


----------



## kneitzel (13. Aug 2021)

Das liegt im entpackten Verzeichnis in bin. Das kannst Du z.B. dem PATH hinzufügen. Wenn es also bei dir in /usr/local/src/apache-maven liegen sollte, dann wäre /usr/local/src/apache-maven/bin in den Pfad mit aufzunehmen.

Was das soll:
cd /etc/profile.d/
sudo touch maven.sh
entzieht sich mir aber auch. Was soll maven.sh für eine Datei sein?


----------



## Kirby.exe (13. Aug 2021)

Also ich habe es zum laufen bekommen  Hatte den falschen JAVA_HOME pfad  Jetzt kompiliert er richtig  Nur habe ich keinen Schimmer wie ich die .jar ausführe xD Also `java -jar nameOfFile` ist klar aber er meckert dann:

```
no main manifest attribute, in dbp-projekt-1.0-SNAPSHOT.jar
```


----------



## Kirby.exe (13. Aug 2021)

kneitzel hat gesagt.:


> entzieht sich mir aber auch. Was soll maven.sh für eine Datei sein?


Die wird mit source /etc/profile.d/maven.sh eingebunden


----------



## mihe7 (13. Aug 2021)

Kirby.exe hat gesagt.:


> Nur habe ich keinen Schimmer wie ich die .jar ausführe xD Also `java -jar nameOfFile` ist klar aber er meckert dann:


Möglichkeit 1: `java -cp target/DeinJarFile.jar:andereLib.jar:nocheineLib.jar de.kirby.DeineMainClass`
Möglichkeit 2: `mvn exec:java -Dexec.mainClass=de.kirby.DeineMainClass`
Möglichkeit 3: mit Maven-Plugins eine ausführbare jar erstellen.


----------



## Kirby.exe (13. Aug 2021)

Hat funktioniert danke


----------

