2

Packaging Akka application.

Hi I am trying to package my application into an executable Jar. Below 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>com.personalProjects</groupId>
    <artifactId>MyAkkaProject</artifactId>
    <version>1.0</version>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <version>1.5</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                        <configuration>
                            <shadedArtifactAttached>true</shadedArtifactAttached>
                            <shadedClassifierName>allinone</shadedClassifierName>
                            <artifactSet>
                                <includes>
                                    <include>*:*</include>
                                </includes>
                            </artifactSet>
                            <transformers>
                                <transformer
                                        implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
                                    <resource>reference.conf</resource>
                                </transformer>
                                <transformer
                                        implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                    <manifestEntries>
                                        <Main-Class>akka.Main</Main-Class>
                                    </manifestEntries>
                                </transformer>
                            </transformers>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

    <dependencies>
        <dependency>
            <groupId>com.typesafe.akka</groupId>
            <artifactId>akka-stream_2.12</artifactId>
            <version>2.5.18</version>
        </dependency>
        <dependency>
            <groupId>com.typesafe.akka</groupId>
            <artifactId>akka-stream-kafka_2.12</artifactId>
            <version>1.0-M1</version>
        </dependency>
        <dependency>
            <groupId>org.postgresql</groupId>
            <artifactId>postgresql</artifactId>
            <version>42.2.1</version>
        </dependency>

        <dependency>
            <groupId>org.mongodb</groupId>
            <artifactId>mongodb-driver</artifactId>
            <version>3.4.3</version>
        </dependency>

    </dependencies>

</project>

I can't seem to get the Jar to work, it states missing akka.streams config.

I went through the official doc here but it doesn't seem to work.

If I copy all Jar to output directory everything works just fine but the issue seems to be when I try to create a big fat jar with all the dependencies in it.

my MANIFEST.INF is below:

Manifest-Version: 1.0
Main-Class: MyAkkaProject.App

where App is the class with psvm and MyAkkaProject` is the package name

/targer dir

iam.Carrot
  • 4,976
  • 2
  • 24
  • 71
  • for sure you need to set the in the manifest entries. Other than that I would try with a more recent version of maven-shade-plugin (although I don't expect this to fix your issue). What is the output after executing `mvn clean package`? what are the contents of the /target dir? – foivaras Nov 24 '18 at 16:14
  • @foivaras I've edited my question with the details – iam.Carrot Nov 25 '18 at 17:20
  • that's weird... I have a very similar pom configuration on an akka project and the fat jar works fine. on the target directory, it generates only these 2 directories we can see on the screenshot? not any jars? – foivaras Nov 25 '18 at 21:01
  • @foivaras the jar gets created in the out directory, `./out.MyAkkaProject/artifacts/myAkkaProject_jars/MyAkkaProjext.jar`. Can you please post up a sample project on `git` so I can have a quick look on how are you getting to get that big fat jar. – iam.Carrot Nov 26 '18 at 03:41
  • https://github.com/halx4/activator-akka-stream-java8 (master branch) 1) clone 2) execute `mvn clean package` target directory will be: | | akka-stream-java8_2.11-1.0-allinone.jar | akka-stream-java8_2.11-1.0.jar | +---classes +---generated-sources +---maven-archiver \---maven-status the *-allinone.jar (its size is around 15MB) is the fat jar we want. – foivaras Nov 26 '18 at 12:40
  • @foivaras I'll check it out thank you – iam.Carrot Nov 27 '18 at 16:11

1 Answers1

0

I resolved the issue, the issue was my IDE when I ran he project or even build it, it wasn't using Maven Lifecycle commands and hence the plug-in wasn't getting triggered.

iam.Carrot
  • 4,976
  • 2
  • 24
  • 71