Skip to content

Commit cf25075

Browse files
authored
Merge pull request eugenp#6267 from macroscopic64/master
example for multi-release jar
2 parents 8734cdf + 7e84372 commit cf25075

3 files changed

Lines changed: 56 additions & 0 deletions

File tree

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package com.baeldung.multireleaseapp;
2+
3+
import org.slf4j.Logger;
4+
import org.slf4j.LoggerFactory;
5+
6+
public class App {
7+
8+
private static final Logger logger = LoggerFactory.getLogger(App.class);
9+
10+
public static void main(String[] args) throws Exception {
11+
String dateToCheck = args[0];
12+
boolean isLeapYear = DateHelper.checkIfLeapYear(dateToCheck);
13+
logger.info("Date given " + dateToCheck + " is leap year: " + isLeapYear);
14+
}
15+
16+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package com.baeldung.multireleaseapp;
2+
3+
import java.text.SimpleDateFormat;
4+
import java.util.Calendar;
5+
import java.util.GregorianCalendar;
6+
7+
import org.slf4j.Logger;
8+
import org.slf4j.LoggerFactory;
9+
10+
public class DateHelper {
11+
12+
private static final Logger logger = LoggerFactory.getLogger(DateHelper.class);
13+
14+
public static boolean checkIfLeapYear(String dateStr) throws Exception {
15+
logger.info("Checking for leap year using Java 1 calendar API");
16+
Calendar cal = Calendar.getInstance();
17+
cal.setTime(new SimpleDateFormat("yyyy-MM-dd").parse(dateStr));
18+
int year = cal.get(Calendar.YEAR);
19+
return (new GregorianCalendar()).isLeapYear(year);
20+
}
21+
22+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package com.baeldung.multireleaseapp;
2+
3+
import java.time.LocalDate;
4+
5+
import org.slf4j.Logger;
6+
import org.slf4j.LoggerFactory;
7+
8+
public class DateHelper {
9+
10+
private static final Logger logger = LoggerFactory.getLogger(DateHelper.class);
11+
12+
public static boolean checkIfLeapYear(String dateStr) throws Exception {
13+
logger.info("Checking for leap year using Java 9 Date Api");
14+
return LocalDate.parse(dateStr)
15+
.isLeapYear();
16+
}
17+
18+
}

0 commit comments

Comments
 (0)