Search code examples
javamavenintellij-ideajava-web-startjnlp

How to copy jar-with-dependencies in my webapp\myfolder in maven Idea


I have the maven project in Idea with two modules: 1)web and 2)web-start-swt-jar.

The web-start-swt-jar pom.xml is configured to package with-dependencies.

My project looks like this:

[root]
  - web-start-swt-jar   pom.xml (packaging jar)
  - web  pom.xml (packaging war)
 pom.xml (packaging pom)

Is it possible to make theese steps I wanted to:

  1. Compile,pacakge with dependensies the web-start-swt-jar.
  2. Compile, package the web module with copying the recently packaged web-start-swt-jar to webapp\webstartFolder\ ?

Yes I use maven assemply plugin, but it copy the jar file wich without dependencies.

Thank you!

p.s. May be you suggest to use some plugins to comfort work with web-start? e.g. webstart-maven-plugin ? please help.


Solution

  • It seems to be answer was found: using maven-shade-plugin to package jar with dependensies and maven-dependency-plugin to copy to custom folder in prepare-package phase.

    Dont forget to set version of depended jar via <dependency managament>

    <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <version>2.1</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                        <configuration>
                            <transformers>
                                <transformer
                                        implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                    <mainClass>Main</mainClass>
                                </transformer>
                            </transformers>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
    
    
    
    <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-dependency-plugin</artifactId>
                    <version>2.10</version>
                    <executions>
                        <execution>
                            <id>copy</id>
                            <phase>prepare-package</phase>
                            <goals>
                                <goal>copy</goal>
                            </goals>
                            <configuration>
                                <artifactItems>
                                    <artifactItem>
                                        <groupId>my.group</groupId>
                                        <artifactId>webstart-swt-jar</artifactId>
                                        <type>jar</type>
                                        <overWrite>false</overWrite>
                                        <outputDirectory>
                                            ${project.build.directory}/${project.build.finalName}/SomeFolderHere
                                        </outputDirectory>
                                        <destFileName>(optional rename..)webstart-swt-jar.jar</destFileName>
                                    </artifactItem>
                                </artifactItems>
    
                                <overWriteReleases>true</overWriteReleases>
                                <overWriteSnapshots>true</overWriteSnapshots>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
    

    ADDED: But if I dont set webstart-swt-jar to dependency, build failed with error "webstart-swt-jar not found". Its not good, because artifact is duplicated in WEB-INF\lib and my \custom folder...