How to produce a jar file for existing maven project without (no main manifest attribute)?

aga.91 :

I am new to Maven. I do not know anything about it. I download an open source maven project form Github. I open it in Eclipse. I modified only one line to modified the pattern for date from this format:

final String pattern = "%d{yyyy-MM-dd HH:mm:ss} %-5p - %m%n";

To this

final String pattern = "%d{yyyy-MM-dd HH:mm:ss:SSS} %-5p - %m%n";

Then, I tried to produce the jar file for the project. The pom.xml that come with the downloaded project is using package shade plugin.

<plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-shade-plugin</artifactId>
                        <version>${shade.version}</version>
                        <executions>
                            <execution>
                                <phase>package</phase>
                                <goals>
                                    <goal>shade</goal>
                                </goals>
                                <configuration>
                                    <finalName>name-of-pro-${project.version}</finalName>
                                    <transformers>
                                        <transformer
                                            implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                            <mainClass>name.of.the.package.and.Mainclass</mainClass>
                                        </transformer>
                                        <transformer
                                            implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer" />
                                    </transformers>
                                    <filters>
                                        <!-- This is necessary to avoid a java.lang.SecurityException -->
                                        <filter>
                                            <artifact>*:*</artifact>
                                            <excludes>
                                                <exclude>META-INF/*.SF</exclude>
                                                <exclude>META-INF/*.DSA</exclude>
                                                <exclude>META-INF/*.RSA</exclude>
                                            </excludes>
                                        </filter>
                                    </filters>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>

So, I tried to get jar file from maven using this command:

mvn clean package

However, when I run the produced jar file using this command:

java -jar app-0.2.0-SNAPSHOT.jar

I got the (no main manifest attribute) error.

no main manifest attribute, in app-0.2.0-SNAPSHOT.jar

I searched for the MANIFEST.MF file to check for the attributes there, but I cloud not find it.

Cloud anyone help me if I missing some setting?

JF Meier :

You cannot just run a jar.

Either you need to specify the full classpath on the command line or you need to build the jar as jar-with-dependencies as e.g. described here:

https://stackoverflow.com/a/574650/927493

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=385293&siteId=1