• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Maven: How to package a jar and execute it with dependencies?

 
Greenhorn
Posts: 7
1
Python VI Editor Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello all. I am still new to the world of deployment, packaging, etc.

I am currently operating purely on the CLI, so eclipse/IDEA plugins etc are not a very good option for me. I was hoping more of a pure solution to this problem using only maven.

Preferably I don't want to have my user adding additional things to the class path of the jar to get the code to execute.

So I have the following project:



Then I have the following in my POM.xml



Now all that I want is for the user to be able to execute the jar without having to specific the commons-cli library.

Is there a way I can get maven to handle this for me in a simple fashion?
 
Saloon Keeper
Posts: 10732
86
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Look up: jar with dependencies


 
Carl McGraw
Greenhorn
Posts: 7
1
Python VI Editor Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is this the standard way of overcoming dependencies for deployments? Or do you usually just have the user specify the class path?
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Carl McGraw wrote:Is this the standard way of overcoming dependencies for deployments? Or do you usually just have the user specify the class path?


No, that would be incredibly cumbersome, real-world projects often have many dependencies.

You can ofcourse simply make a Windows batch file or Linux/OS X shell script to run the application. For example a file named run.bat that would contain the command needed to run the application:

If you package your program as an executable JAR file then the classpath is specified in the manifest file inside the JAR file, and you can execute it with java -jar myprogram.jar, or even by double-clicking on the JAR file.
reply
    Bookmark Topic Watch Topic
  • New Topic