4

I created a Confluence plugin(A Java application) which has Maven on it and includes some dependencies in the pom.xml as follows: (It needs to use the Google Client Library)

<dependencies>
    <dependency>
        <groupId>com.google.apis</groupId>
        <artifactId>google-api-services-calendar</artifactId>
        <version>v3-rev254-1.22.0</version>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>com.google.api-client</groupId>
        <artifactId>google-api-client</artifactId>
        <version>1.22.0</version>
        <scope>compile</scope>
    </dependency>

    ..... Skip .....

</dependencies>

I also downloaded the Google Client Library and created a "libs" folder at the "src/main/resources/" path in this maven project to store them, and added them as jars in Eclipse as follows:

enter image description here

However, after executed "atlas-debug" to invoke a Confluence instance or "atlas-package" commands, the final exported jar file usually does not include the dependencies/libraries (I found this according to the failed jar file size, it is much smaller than the successful one).

How to make the library files really be included into the exported jar file every time I executed "atlas-debug" or "atlas-package" commands?

skyline
  • 443
  • 9
  • 31
  • 1
    @Ravi ant != maven – jmj Oct 01 '17 at 07:29
  • @Ravi ant != maven – skyline Oct 01 '17 at 07:30
  • Maybe I'm missing something but why are you downloading anything at all? If maven is configured properly in your computer and eclipse, it does all the downloading and exporting to jar for you. – Ray Oct 01 '17 at 07:44
  • Maybe there is something wrong with my Maven or Eclipse? If I didn't add the library in the libs folder, there would not be a successful one exported so far. – skyline Oct 01 '17 at 08:34
  • location `src/main/resources` is intended for resources but never for jar files nor should you handle that manually. Let Maven do the work...Please show your pom file.. – khmarbaise Oct 01 '17 at 10:33

1 Answers1

2

You can use the maven-assembly-plugin plugin that will package all your dependency in the jar. You can configure it in the plugins section under the build section in your pom.xml:

<build>
...
    <plugins>
    ...
       <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-assembly-plugin</artifactId>
                <version>2.2.2</version>
                <executions>
                    <execution>
                        <id>assembly</id>
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                        <configuration>
                            <descriptorRefs>
                                <descriptorRef>jar-with-dependencies</descriptorRef>
                            </descriptorRefs>
                            <archive>
                            </archive>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
    ...
    </plugins>
...
</build>

Remember that the dependency configured with <scope>provided</scope> won't be included in the jar.

araknoid
  • 3,065
  • 5
  • 33
  • 35