0

I have created a Dropwizard application using Intellij. (Here com.indore.GalaxyApp is name of my MainClass)

This is the pom.xml of my application.

After building the project using mvn clean package, in my target directory a jar file is created.

enter image description here

enter image description here

Now, I am trying to run the application with the jar file through terminal, I get the following response :

enter image description here

enter image description here MANIFEST.MF

enter image description here

In order to make the jar executable

  1. I have configured the Maven Archiver and added the following plugin in pom.xml acc to this SO answer

    enter image description here

  2. I even run the application by:

    java -cp target/galaxy-1.0-SNAPSHOT.jar com.indore.GalaxyApp

but still getting the same error.

I have referred to these post :

setup-main-class-in-manifest, Cant execute jar file

Can anyone tell me a way to fix this issue??

ESCoder
  • 15,431
  • 2
  • 19
  • 42
  • The error is telling you a class io.dropwizard.Application is required but is not found, that sounds like a missing extra jar which needs to be available on the application runtime classpath. Does the manifest have a class-path line? – Gimby Feb 18 '20 at 14:31
  • @Gimby there is no class-path line in manifest – ESCoder Feb 18 '20 at 15:47
  • @Gimby can you tell me how to add a class-path line in manifest – ESCoder Feb 19 '20 at 17:32
  • 1
    Maven should do that for you if the plugins are configured correctly. It is quite well documented. You may want to create a fat jar by using the Maven Shade plugin though, then you have only one (big) jar to worry about. – Gimby Feb 20 '20 at 08:53
  • 1
    Follow [the documentation](https://www.dropwizard.io/en/latest/getting-started.html) to a T, including the pom.xml. – Paul Samsotha Feb 26 '20 at 04:06

1 Answers1

0

I was able to fix this issue by following the documentation.

Here is the sample pom.xml for reference

<?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.example</groupId>
<artifactId>example</artifactId>
<version>1.0-SNAPSHOT</version>

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

<dependencies>
    <!-- https://mvnrepository.com/artifact/io.dropwizard/dropwizard-core -->
    <dependency>
        <groupId>io.dropwizard</groupId>
        <artifactId>dropwizard-core</artifactId>
        <version>2.0.25</version>
    </dependency>
    <!-- https://mvnrepository.com/artifact/io.dropwizard/dropwizard-db -->
    <dependency>
        <groupId>io.dropwizard</groupId>
        <artifactId>dropwizard-db</artifactId>
        <version>2.0.25</version>
    </dependency>
    <!-- https://mvnrepository.com/artifact/io.dropwizard/dropwizard-hibernate -->
    <dependency>
        <groupId>io.dropwizard</groupId>
        <artifactId>dropwizard-hibernate</artifactId>
        <version>2.0.13</version>
    </dependency>
    <!-- https://mvnrepository.com/artifact/org.postgresql/postgresql -->
    <dependency>
        <groupId>org.postgresql</groupId>
        <artifactId>postgresql</artifactId>
        <version>42.3.1</version>
    </dependency>
</dependencies>
<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <version>2.4</version>
            <configuration>
                <archive>
                    <manifest>
                        <addDefaultImplementationEntries>true</addDefaultImplementationEntries>
                    </manifest>
                </archive>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-shade-plugin</artifactId>
            <version>2.3</version>
            <configuration>
                <createDependencyReducedPom>true</createDependencyReducedPom>
                <filters>
                    <filter>
                        <artifact>*:*</artifact>
                        <excludes>
                            <exclude>META-INF/*.SF</exclude>
                            <exclude>META-INF/*.DSA</exclude>
                            <exclude>META-INF/*.RSA</exclude>
                        </excludes>
                    </filter>
                </filters>
            </configuration>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>shade</goal>
                    </goals>
                    <configuration>
                        <transformers>
                            <transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
                            <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                <mainClass>com.example.helloworld.HelloWorldApplication</mainClass>
                            </transformer>
                        </transformers>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>
</project>
Nishant Mendiratta
  • 760
  • 13
  • 25