3

Previously I have been able to run this script that read events from a url.ics

import net.fortuna.ical4j.util.Calendars
import net.fortuna.ical4j.model.component.VEvent

@Grapes(
@Grab(group='org.mnode.ical4j', module='ical4j', version='2.2.0')
)
def url = 'https://calendar.google.com/calendar/ical/xxxx/basic.ics'.toURL()
def cal = Calendars.load(url)

However, now I am getting this exception java.lang.NoClassDefFoundError: javax/cache/configuration/Configuration.

I assume there is some sort of dependency change that has occurred. I have noted this

javax.cache.cache-api [optional*] - Supports caching timzeone definitions. * NOTE: when not included you must set a value for the net.fortuna.ical4j.timezone.cache.impl configuration

however, now I am getting this java.lang.NoClassDefFoundError: Could not initialize class net.fortuna.ical4j.validate.AbstractCalendarValidatorFactory

any help appreciated.

1 Answers1

5

ical4j looks for a properties file called ical4j.properties and loads configuration from it. Create this file in the same folder and add

net.fortuna.ical4j.timezone.cache.impl=net.fortuna.ical4j.util.MapTimeZoneCache

to specify in-memory cache provider that uses ConcurrentHashMap. When property net.fortuna.ical4j.timezone.cache.impl is not specified, ical4j falls back to JCacheTimeZoneCache which uses cache manager and requires valid caching library to be present in the classpath.

The alternative to using ical4j.properties file is to set this property programatically, e.g.

System.setProperty("net.fortuna.ical4j.timezone.cache.impl", "net.fortuna.ical4j.util.MapTimeZoneCache")

Just remember to set it before calling Calendars.load(url) and it should work.

Szymon Stepniak
  • 40,216
  • 10
  • 104
  • 131
  • The difficulty here is that I do not have the file locally, I am use grape to handle the dependency managment [link](http://docs.groovy-lang.org/latest/html/documentation/grape.html) So I have to do it in code something like `System.properties.'net.fortuna.ical4j.timezone.cache.impl' = 'net.fortuna.ical4j.util.MapTimeZoneCache'` this changes the exception to `java.lang.NoClassDefFoundError: Could not initialize class net.fortuna.ical4j.validate.AbstractCalendarValidatorFactory` the weird this is it was working fine a month ago – narayana takacs Jun 07 '18 at 22:17
  • @narayanatakacs It works with Grapes as well - this properties file can be added next to your Groovy script file and it will be seen in the classpath. Alternatively you can set this property with `System.setProperty()` method, I've updated the answer to cover this use case as well. – Szymon Stepniak Jun 08 '18 at 05:34