No main manifest attribute in .jar - java

I search in Internet many information, but I don't know what's porblem is that...
Please, check this:
Manifest:
Manifest-Version: 1.0
Main-Class: BotPolytechnic
POM:
<groupId>FPolytechnic</groupId>
<artifactId>FPolytechnic</artifactId>
<version>1.0</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
<archive>
<manifest>
<mainClass>BotPolytechnic</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>

use instead the maven-jar-plugin to make the JAR executable:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>fully.qualified.MainClass</mainClass>
</manifest>
</archive>
</configuration>
</plugin>

Related

org.apache.flink.client.program.ProgramInvocationException: The program's entry point class 'com.example.KafkaFlink' was not found in the jar file

I was getting an error ProgramInvocationException while trying upload a jar file to flink local server
Here is the pom.xml of code
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<mainClass>com.example.KafkaFlink</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>

Making absolute reference to a classpath in Maven

I have a customized jar that the application uses. Instead of installing jar in maven I want to make reference to it by defining absolute location for that jar in the manifest file. I am using the code shown below to update information in manifest file. However, I am not sure how can I reference to the jar location that uses absolute path like : D:/Shared_library/Test.jar . This might not be a good practice but I want to see if there is anything like that:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>org.ad.MainClass</mainClass>
<addClasspath>true</addClasspath>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
You can add it using <manifestEntries> tag.
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifestEntries>
<Class-Path>file:///D:/Shared_library/Test.jar</Class-Path>
</manifestEntries>
<manifest>
<mainClass>org.ad.MainClass</mainClass>
<addClasspath>true</addClasspath>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>

How to run properly an Akka application with a fat-JAR? (No configuration setting found for key 'akka.remote.log-received-messages')

I have a simple Java application that uses Akka. I decided to dockerize it.
When i build and run the application everything seems fine but Akka throws this error:
< com.typesafe.config.ConfigException$Missing: No configuration setting found for key 'akka.remote.log-received-messages' >
This is the plugins section of the pom.xml:
...
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<!-- Build an executable JAR -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>${project.build.directory}/dependency</classpathPrefix>
<mainClass>it.uniroma3.initialization.Init</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.4.1</version>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<mainClass>it.uniroma3.initialization.Init</mainClass>
</manifest>
</archive>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
It seems like the libraries are correctly accessed but for some reason akka cannot start properly. How can I solve this?

Putting version information in manifest file into JAR using Maven

I am trying to find a way of putting version information in manifest file into JAR using Maven?
For WAR files I use the following in my POM.XML
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.6</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
</manifest>
</archive>
</configuration>
</plugin>
and then I run "mv clean package"
How would you do this for a JAR.. Can you please give me details information on the changes and the commands... thanks
You can use maven-jar-plugin (the configuration is nearly the same as maven-war-plugin)
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.6</version>
<configuration>
<archive>
<index>true</index>
<manifest>
<addClasspath>true</addClasspath>
</manifest>
<manifestEntries>
<mode>development</mode>
<url>${project.url}</url>
<key>value</key>
</manifestEntries>
</archive>
</configuration>
...
</plugin>
Here the documentation of the plugin: https://maven.apache.org/plugins/maven-jar-plugin/examples/manifest-customization.html
And all options: http://maven.apache.org/shared/maven-archiver/index.html

Can not set the final jar name with maven-assembly-plugin

This is how I configured maven-assembly-plugin
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.4</version>
<configuration>
<finalName>myapp</finalName>
<archive>
<manifest>
<mainClass>com.myapp.Main</mainClass>
</manifest>
</archive>
<!--
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
-->
</configuration>
</plugin>
and I expect the final jar file should be myapp.jar but it ends up with myapp-jar-with-dependencies.jar
Can you tell me how to configure to exclude "jar-with-dependencies" out of the final name?
You can specify the finalName property to give the jar the name you want, and specify that appendAssemblyId should be false to avoid the jar-with-dependencies suffix.
The configuration below will output a jar called test.jar
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.4</version>
<configuration>
<finalName>test</finalName>
<archive>
<manifest>
<mainClass>com.myapp.Main</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<appendAssemblyId>false</appendAssemblyId>
</configuration>
</plugin>

Categories