1

I'm trying to create a runnable jar file, but somehow my Maven/Netbeans fails to do so. This is my 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>de.ksw</groupId>
    <artifactId>KBSE-CDI-Testprogram</artifactId>
    <version>1.0</version>
    <packaging>jar</packaging>
    <build>
        <plugins>
            <plugin>
                <version>1.8.1</version>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <configuration>
                    <archive>
                        <manifest>
                            <addClasspath>true</addClasspath>
                            <mainClass>de.ksw.kbse.cdi.testprogram.App</mainClass>
                        </manifest>
                    </archive>
                </configuration>
            </plugin>
        </plugins>
    </build>
    <dependencies>
        <dependency>
            <groupId>javax.inject</groupId>
            <artifactId>javax.inject</artifactId>
            <version>1</version>
        </dependency>
        <dependency>
            <groupId>${project.groupId}</groupId>
            <artifactId>KBSE-CDI</artifactId>
            <version>${project.version}</version>
        </dependency>
        <dependency>
            <groupId>maven</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <version>1.8.1</version>
        </dependency>
    </dependencies>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
    </properties>
</project>

As you can see I already tried to add the main class. I also added the dependency maven-jar-plugins, but I still get an error messagen when I try to compile the project:

Plugin org.apache.maven.plugins:maven-jar-plugin:1.8.1 or one of its dependencies could not be resolved: Failed to read artifact descriptor for org.apache.maven.plugins:maven-jar-plugin:jar:1.8.1: Failure to find org.apache.maven.plugins:maven-jar-plugin:pom:1.8.1 in http://repo.maven.apache.org/maven2 was cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or updates are forced -> [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/PluginResolutionException

What am I doing wrong here? How to fix this?

2 Answers2

1

What I do in one project of mine is to use the maven-jar-plugin and the maven-assembly-plugin

The result is an executable fat-jar.

<artifactId>maven-assembly-plugin</artifactId>
            <version>2.5.5</version>
            <configuration>
                <archive>
                    <manifest>
                        <mainClass>de.ksw.kbse.cdi.testprogram.App</mainClass>
                    </manifest>
                    <manifestEntries>                      
                        <!--this one is to add the version information in the manifest. This is something that I need but you can ignore it-->  
                        <version>${project.version}</version>
                    </manifestEntries>
                </archive>
                <descriptorRefs>
                    <descriptorRef>jar-with-dependencies</descriptorRef>
                </descriptorRefs>
                <finalName>${project.artifactId}</finalName>
                <appendAssemblyId>false</appendAssemblyId> 
                <classifier>DEV</classifier>
            </configuration>
            <executions>
                <execution>
                    <id>make-assembly</id> <!-- to inheritance merges -->
                    <phase>package</phase> <!-- just to use in the packaging phase -->
                    <goals>
                        <goal>single</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <!--This plugin is used to have just one jar instead of 2-->
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <version>3.0.1</version>
            <configuration>
                <classesDirectory>${project.build.outputDirectory}</classesDirectory>
                <finalName>${project.artifactId}</finalName>
                <outputDirectory>${project.build.directory}</outputDirectory>
                <verify>false</verify>
            </configuration>
        </plugin>

After this just it the clean and build button in netbeans and search for something

with assembly file: PATH_TO_JAR/KBSE-CDI-Testprogram.jar

liponcio
  • 264
  • 1
  • 9
0

There is no version 1.8.1 of maven-jar-plugin.

Here the list of all available versions of maven-jar-plugin : https://mvnrepository.com/artifact/org.apache.maven.plugins/maven-jar-plugin

You have to update version into an earlier version.

Example with the latest version :

<version>3.0.2</version>
Mickael
  • 4,458
  • 2
  • 28
  • 40
  • 1
    You should use Maven Central as Reference http://search.maven.org/#search|gav|1|g%3A%22org.apache.maven.plugins%22%20AND%20a%3A%22maven-jar-plugin%22 – khmarbaise Jul 06 '16 at 13:49
  • Nice! I didn't know this site. Thanks. – Mickael Jul 06 '16 at 13:55
  • Finally... As it turns out I used the wrong version as you said. I used it, because I took the first maven-jar-plugin I found, that was probably an old one. However, not I don't have any problems. :) Thanks! –  Jul 06 '16 at 15:29