Merge pull request #6267 from macroscopic64/master

example for multi-release jar
This commit is contained in:
Eric Martin 2019-02-17 22:22:27 -06:00 committed by GitHub
commit cf25075e22
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 56 additions and 0 deletions

View File

@ -0,0 +1,16 @@
package com.baeldung.multireleaseapp;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class App {
private static final Logger logger = LoggerFactory.getLogger(App.class);
public static void main(String[] args) throws Exception {
String dateToCheck = args[0];
boolean isLeapYear = DateHelper.checkIfLeapYear(dateToCheck);
logger.info("Date given " + dateToCheck + " is leap year: " + isLeapYear);
}
}

View File

@ -0,0 +1,22 @@
package com.baeldung.multireleaseapp;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.GregorianCalendar;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class DateHelper {
private static final Logger logger = LoggerFactory.getLogger(DateHelper.class);
public static boolean checkIfLeapYear(String dateStr) throws Exception {
logger.info("Checking for leap year using Java 1 calendar API");
Calendar cal = Calendar.getInstance();
cal.setTime(new SimpleDateFormat("yyyy-MM-dd").parse(dateStr));
int year = cal.get(Calendar.YEAR);
return (new GregorianCalendar()).isLeapYear(year);
}
}

View File

@ -0,0 +1,18 @@
package com.baeldung.multireleaseapp;
import java.time.LocalDate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class DateHelper {
private static final Logger logger = LoggerFactory.getLogger(DateHelper.class);
public static boolean checkIfLeapYear(String dateStr) throws Exception {
logger.info("Checking for leap year using Java 9 Date Api");
return LocalDate.parse(dateStr)
.isLeapYear();
}
}