1

In IntelliJ it gives you the option to put a library (dependency) to the artifact you are creating. I want to do this because some of the libraries I have are digitally signed and if I extract them to the jar it causes it to not run (no main method found)

However when I do this I get a bunch of exceptions saying that the class cannot be found. Is there a special way I have to configure this jar setup so that this will be able to find the jars within the artifact?

MrDaveForDays
  • 121
  • 1
  • 7
  • Why don't you do using Maven or Gradle instead of using any IDE ? It is pretty simple and better. – Sambit May 03 '19 at 20:27
  • I am using maven, however I still need to extract the jars into the runnable artifact which is where I am having the issue – MrDaveForDays May 03 '19 at 20:32
  • Look into this post. https://stackoverflow.com/questions/16222748/building-a-fat-jar-using-maven. You have to create a fat jar file using maven shade plugin. – Sambit May 03 '19 at 20:34

2 Answers2

0

Jar file placed inside another jar will not work out of the box with IntelliJ IDEA. It requires a custom classloader to handle such dependencies. You either put the jars next to the main jar and link them via manifest or you strip the digital signature from the dependent jars and unpack their contents into the single jar.

Your another option is to build the jar via the Maven or Gradle plug-ins which can handle the signed jars better.

CrazyCoder
  • 389,263
  • 172
  • 990
  • 904
0
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.6.1</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <version>3.2.1</version>
                <configuration>
                    <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>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>3.0.2</version>
                <configuration>
                    <archive>
                        <manifest>
                            <addClasspath>true</addClasspath>
                            <mainClass>sample.Main</mainClass>
                        </manifest>
                    </archive>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-assembly-plugin</artifactId>
                <version>2.5.5</version>
                <configuration>
                    <archive>
                        <manifest>
                            <mainClass>sample.Main</mainClass>
                        </manifest>
                    </archive>
                    <descriptorRefs>
                        <descriptorRef>jar-with-dependencies</descriptorRef>
                    </descriptorRefs>
                </configuration>
                <executions>
                    <execution>
                        <id>make-assembly</id>
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

The previous maven set up solved this issue for me. Then I ran mvn clean package and it is working.

MrDaveForDays
  • 121
  • 1
  • 7