0

I Made a java maven project for rest api .. now i need to deploy it on server .. that's why i wanted to make a executable jar .. How can i make this....?

Here i used Jersey-2 for rest api. Project File Structure

Maven Plugin:

 <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <version>3.1.1</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                        <configuration>
                            <transformers>
                                <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                    <mainClass>net.javatutorial.tutorials.services.FileUploadService</mainClass>
                                </transformer>
                            </transformers>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
tanvirHaque
  • 41
  • 1
  • 7

1 Answers1

0

If you want an executable jar, your Jersey app needs to be a standalone app, which is an app that runs from a "main" class with a main method. To easily create a standalone app, you can use the Maven archetype mentioned in the Jersey Getting Started. (You can see the generated files from the archetype in this post).

mvn archetype:generate -DarchetypeArtifactId=jersey-quickstart-grizzly2 \
-DarchetypeGroupId=org.glassfish.jersey.archetypes -DinteractiveMode=false \
-DgroupId=com.example -DartifactId=simple-service -Dpackage=com.example \
-DarchetypeVersion=2.27

Once you have your standalone app, then you can build it with the maven-shade-plugin like you are currently doing. The Main class is what you should specify in the <mainClass> element. One thing I should mention is that you should also use the ServicesResourceTransformer to concatenate the services files1


1 - See Jersey fails when creating uber jar with maven-assembly-plugin

Paul Samsotha
  • 205,037
  • 37
  • 486
  • 720