Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

maven, deploy a desktop application

Tags:

java

maven

I am switching from ant to maven.

To keep things simple, my application is a swing application that connects to a database. I want it to be packaged in a jar file.
The application requires an external library, that is Microsoft sql server library, contained in a jar file: sqljdbc4-3.0.jar.

So i tryed to include this library:

    <dependency>
        <groupId>com.microsoft.sqlserver</groupId>
        <artifactId>sqljdbc4</artifactId>
        <version>3.0</version>
    </dependency>

but when launching the jar, i get the exception:

java.lang.SecurityException: Invalid signature file digest for Manifest main attributes

This problem is already documented in other stackoverflow questions; i'm talking of this just to get to the point. My idea (maybe naive) is the following, i would like to

  • create a jar with only my code.
  • create a distribution that contains in a directory (lib) all my libraries.
  • the manifest file to correctly reference all the libraries.

Searching around, i've found that each one of this issues is performed by a different maven plugin: jar plugin, dependency plugin and assembly plugin.
Is this the way to go?
I don't feel it right because i've undesrtood that maven would handle easily "regular" configurations and this solutions of the three plugins seems a bit over-complex.

like image 255
AgostinoX Avatar asked Nov 17 '25 10:11

AgostinoX


2 Answers

You need to add these plugins to pom

        <plugin>
            <artifactId>maven-jar-plugin</artifactId>
            <configuration>
                <archive>
                    <manifest>
                        <addClasspath>true</addClasspath>
                        <classpathPrefix>lib</classpathPrefix>
                    </manifest>
                </archive>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-assembly-plugin</artifactId>
            <version>2.4</version>
            <configuration>
                <descriptor>src/main/assembly/assembly.xml</descriptor>
            </configuration>
        </plugin>

src/main/assembly/assembly.xml

<assembly>
    <id>assembly</id>
    <formats>
        <format>zip</format>
    </formats>
    <dependencySets>
        <dependencySet>
            <outputDirectory>/lib</outputDirectory>
            <unpack>false</unpack>
        </dependencySet>
    </dependencySets>
</assembly>

run assembly

mvn clean package assembly:single
like image 85
Evgeniy Dorofeev Avatar answered Nov 18 '25 23:11

Evgeniy Dorofeev


This is the maven way. By the way: the jar plugin and the dependency plugin are included always in a maven build and there should be no need to configure them.

Additionally a good help could be the appassembler that creates a distributable including all jar files needed.

like image 29
Uwe Plonus Avatar answered Nov 19 '25 01:11

Uwe Plonus



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!