Monday 2 February 2015

Maven Tip: All about executable jars

An executable jar is an extremely useful artefact when it comes to distributing your code.  It means that, as long as Java is installed on the client machine, on Windows and Mac at least, your users can just double click the jar and program will launch. Alternatively on the command line the program can easily be launched with the simple command line java -jar xxx.jar. No fussing with classpaths and dependent jars.

Creating a executable jar from Maven is pretty straight forward and involves using the maven-assembly-plugin. This can be configured and added to your pom.xml as below:

            <plugin>
                <artifactId>maven-assembly-plugin</artifactId>
                <configuration>
                    <archive>
                        <manifest>
                            <mainClass>com.example.Main</mainClass>
                        </manifest>
                    </archive>
                    <descriptorRefs>
                        <descriptorRef>jar-with-dependencies</descriptorRef>
                    </descriptorRefs>
                </configuration>
                <executions>
                        <execution>
                            <phase>install</phase>
                            <goals>
                                <goal>single</goal>
                            </goals>
                        </execution>
                </executions>
            </plugin>

Let's drill into the details:
<goal>single<goal> tells the plugin that we want to execute the single goal. For more documentation see here.
<phase>install<phase> tells the plugin that we want this task to be run as part of the install lifecycle event.
<descriptorRef>jar-with-dependencies</descriptorRef> tells the plugin that we want the jar to include all dependencies.
<mainClass>com.example.Main</mainClass> tells the plugin which class should be launched when the jar is executed.

In this case I set up the plugin to produce an executable jar during the install life-cycle but of course you can change that setting if you want it to be part of a different part of the life-cycle.

Another task you will want Maven to do for you is to create your executable jar as part of the release.

In order to do this you will need to configure the maven-release-plugin to create the executable jar. This can be done as below:


<plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-release-plugin</artifactId>
      <version>2.5.1</version>
      <configuration>
           <goals>install</goals>
           <preparationGoals>install</preparationGoals>
      </configuration>
</plugin>

The key thing here is the configuration of the preparationGoals which is called by release:prepare. When configured as a preparationGoal install is executed before committing (default preparationGoals are clean verify). By adding install to the preparationGoals we ensure that our executable jar will be built before the commit.  It will be tagged with the same number as the release.  If we are moving from version 1.3 to 1.4 the executable jar will be named xxx-jar-with-dependencies-1.4.jar.

Compare what happens when you configure install as a completionGoal as opposed to a preparationGoal. In the same example as above, moving from version 1.3 to 1.4, if install was configured as a completionGoal, install would be run after the commit and the resulting executable jar would be called xxx-jar-with-dependencies-1.5-SNAPSHOT.jar.

Goal (as opposed to preparationGoal and completionGoal) is run by release:perform. By default it calls deploy. See here as to why I configured it to call install.

In summary I hope you can see how easy it is to build an executable jar with Maven and to have it released with the correct release tag every time you release your project.

8 comments:

  1. http://www.rationaljava.com/2015/02/maven-tip-all-about-executable-jars.html
    http://www.myjourneyto5thgrade.com/2013/03/math-workshop-task-cards-and-freebie.html
    http://www.cx-journey.com/2011/12/customer-experience-lifecycle.html
    http://www.directory10.biz/index.php?p=d
    http://www.justdirectory.org/index.php?p=d

    ReplyDelete
  2. https://canelovsjacobsfights.com/canelo-alvarez-vs-jacobs-event-time/
    Canelo Alvarez vs Jacobs Event Time That's where using a VPN comes in.Short for Virtual Private Networking, it's an ideal piece of software that allows you to change your IP address so you appear to be in a completely different location. (i.e. one that's actually showing the boxing).They're are also really handy if you're concerned about streaming safely on the web, thanks to the encryption they use to hide your details. Canelo Alvarez vs Jacobs Event Time And the best won't log your personal information, either. Big-time boxing season is here. Over the next few weeks, the top three heavyweights in the world -- Anthony Joshua, Deontay Wilder and Tyson Fury -- and top middleweights Canelo Alvarez and Gennady Golovkin are each headlining major events in New York City or Las Vegas.

    ReplyDelete

  3. https://canelovsjacobsfights.com/when-is-canelo-alvarezs-next-fight-date-time-price/
    When Is Canelo Alvarez's Next Fight Date Time Price

    Boxing fans wanted Crawford to face IBF titlist Errol Spence Jr. tosee who the king of the division and the sport would be. Spence fought Mikey Garcia in March instead, so Crawford went to one of the biggest names in the game. Khan won the 140-pound WBA title from Andreas Kotelnik in July 2009. The 32-year-old made four straight defenses of the belt before adding the IBF strap in when he scored a fifth-round knockout of Zab Judah in July 2011. The sentiment is that Jacob, 32, will be one of the stiffest tests of When Is Canelo Alvarez's Next Fight Date Time Price which is saying something, considering the Mexican star has been inside the ring two times with Golovkin and Mayweather. Boxing pundits and fans alike feel Khan has seen his better days, and Crawford will make it look rather easy. Khan possesses the experience and packs a hard enough punch to where he can give Crawford plenty of problems.

    ReplyDelete
  4. https://canelovsjacobsfights.com/how-to-watch-canelo-alvarez-vsdaniel-jacobs-live-online/
    How To Watch Canelo Alvarez vs Daniel Jacobs Live Online

    The card starts at 8 p.m. ET. It won’t be televised on regular cable in the United States, but you can watch a live stream of both semifinal fights on DAZN. DAZN, which also has exclusive broadcasting rights in the US for the fights of Canelo Alvarez next weekend, May 4 vs Daniel Jacobs, How To Watch Canelo Alvarez vs Daniel Jacobs Live Online Anthony and Gennady Golovkin costs either $19.99 per month or $99.99 for a year, which comes out to just over $8 per month. Jacobs, 31, is a native of Brooklyn, New York who is widely considered as one of the best middleweights of this era. Jacobs rose up the middleweight rankings to win the WBA Middleweight World Title against Jarrod Fletcher in 2014 after being away from the sport for 19 months, due to a form of bone cancer that he courageously overcame. Jacobs made several successful defenses, including a thunderous first-round knockout of Peter Quillin the following year.

    ReplyDelete

  5. https://canelovsjacobsfights.com/canelo-alvarez-vs-daniel-jacobs-predictions-odds-preview/
    Canelo Alvarez vs Daniel Jacobs Predictions Odds Preview

    Canelo Alvarez is set to face Daniel Jacobs on May 4 and the Mexican brawler is busy training for the said fight. However, that does not mean that the 28-year-old is not accommodating visitors. In fact, he welcomed Maverick Carter recently and got something from NBA star LeBron James. According to TMZ Sports, Carter took a trip to Alvarez’ training camp in San Diego and gave the Mexican some hot kicks. They were a pair of LeBron 16 “Martin” shoes, one of the most coveted shoes in the market. Canelo Alvarez vs Daniel Jacobs Predictions Odds Preview was awed by the gift and told Carter to give James his thanks for the kicks. For those who may be unaware, James and Carter are producing a docuseries of the fight.

    ReplyDelete
  6. https://emmyawardsdaytime.com/46th-daytime-emmy-awards-nommés-et-lauréats/
    46th Daytime Emmy Awards Nommés Et Lauréats

    The final round of voting will be underway, as the 2019 Daytime Emmy Awards nominations were announced back in March to include various soap opera actors hoping to take home an Emmy statuette. The live ceremony will not be televised but fans will be able to watch the 2019 Daytime Emmys live streamed online via social media platforms such 46th Daytime Emmy Awards Nommés Et Lauréats Facebook Live, Twitter and Instagram. Earlier, we reported that Extra’s Mario Lopez and The Talk’s Sheryl Underwood will host the 2019 Daytime Emmys ceremony. The Talk has won a few Daytime Emmys over the years since its debut on October 18, 2010 as part of CBS’ Daytime programming. The show is currently in its 9th season and discusses the latest headlines.

    ReplyDelete
  7. https://emmyawardsdaytime.com/will-the-daytime-emmy-awards-be-televised/
    Will The Daytime Emmy Awards Be Televised

    On September 18, 2018, Soaps.com first announced the air date for this year’s the 46thth Annual Daytime Emmys Awards, which will be held at the Pasadena Civic Auditorium at 300 E Green Street in Pasadena, California on Sunday May 5 to honor The Bold and the Beautiful, Days of our Lives, General Hospital and The Young and the Restless along with their actors. Following the big night where soap stars and other daytime personalities come together to celebrate excellence in American Will The Daytime Emmy Awards Be Televised television, winners will join hosts Sheryl Underwood, Sharon Osborne, Eve and Carrie Ann Inaba for The Talk’s After Party on Monday May 6 at 2:00 PM Eastern. Former host and creator Sara Gilbert announced on Tuesday April 9 that she would be leaving the talk show but would return for guest-hosting in the future.


    https://emmyawardsdaytime.com/46th-daytime-emmy-awards-nommés-et-lauréats/
    46th Daytime Emmy Awards Nommés Et Lauréats

    The final round of voting will be underway, as the 2019 Daytime Emmy Awards nominations were announced back in March to include various soap opera actors hoping to take home an Emmy statuette. The live ceremony will not be televised but fans will be able to watch the 2019 Daytime Emmys live streamed online via social media platforms such 46th Daytime Emmy Awards Nommés Et Lauréats Facebook Live, Twitter and Instagram. Earlier, we reported that Extra’s Mario Lopez and The Talk’s Sheryl Underwood will host the 2019 Daytime Emmys ceremony. The Talk has won a few Daytime Emmys over the years since its debut on October 18, 2010 as part of CBS’ Daytime programming. The show is currently in its 9th season and discusses the latest headlines.

    https://emmyawardsdaytime.com/46th-daytime-emmy-awards-nominados-y-ganadores/
    46th Daytime Emmy Awards Nominados Y Ganadores

    Be sure to make your Daytime Emmy predictions so that Hollywood insiders can see how their shows and performers are faring in our odds. You can keep changing your predictions until winners are announced on May 5. And join in the fierce debate over the 2019 Daytime Emmys taking place right now with Hollywood insiders in our daytime TV forums. Read more Gold Derby entertainment news. The 46th Daytime Emmy Awards Nominados Y Ganadores nominees include household names such as Ellen DeGeneres, Whoopi Goldberg, Kelly Ripa, Ryan Seacrest, and O's very own Gayle King. And while watching the show sounds like it'd be easy, things get somewhat tricky. The National Academy of Television Arts and Sciences (NATAS) also sub-divides the daytime ceremonies into regular and Creative Arts Awards. Confused yet? Don’t worry, we’ve got you covered. Here’s everything you need to know about the 46th annual Daytime Emmy Awards.

    ReplyDelete
  8. slot pg สล็อตออนไลน์ ค่าย พีจี ฝาก-ถอน ไม่มีอย่างน้อย เร็วทันใจด้วยระบบอัตโนมัติ สมัคร PGSLOT ก็สามารถสร้างรายได้ กับ PGSLOT พอดี pg-slot.game สล็อตเว็บไซต์ตรงชั้น 1

    ReplyDelete