我有一个网站在我的 Mac 上运行良好,运行 commandbox v5.0.1+00137(cfengine:[电子邮件受保护]+330608)。我正在设置一个新的 MBP (M3),其中安装了 commandbox v6.0.0+00787(cfengine:[电子邮件受保护]+330617)。启动我的开发服务器并启动站点后,我从我使用的名为 timezone.cfc 的第三方组件收到以下错误。
java.lang.reflect.InaccessibleObjectException:无法使 public sun.util.calendar.ZoneInfo(java.lang.String,int) 可访问:模块 java.base 不会“导出 sun.util.calendar”到未命名模块 @591fd34d
它在
timezone.cfc
(第 87 行)中被阻塞的代码的具体部分如下......
82: <!--- the time zone object itself --->
83: <cfset variables.tzObj = createObject("java","java.util.TimeZone")>
84: <!--- list of all available timezone ids --->
85: <cfset variables.tzList = listsort(arrayToList(variables.tzObj.getAvailableIDs()), "textnocase")>
86: <!--- default timezone on the server --->
87: <cfset variables.mytz = variables.tzObj.getDefault().ID>
无论我抛弃
variables.tzObj.getDefault()
-还是- variables.tzObj.getDefault().ID
,我都会...
[未定义的结构元素]
当我倾倒
variables.tzObj
时,我得到...
根据最初的错误,这感觉更像是 Java 问题而不是命令框问题,但我不确定。似乎 `sun.util.calendar.ZoneInfo(java.lang.String, int) 应该是公共的,但事实并非如此。假设这就是问题所在,我该如何公开?
欢迎任何和所有的想法。我已经在该对象上尝试了各种方法,有些有效……有些无效。那些没有的(比如
getID()
)似乎会抛出这个错误......
对象实例化异常。 实例化 Java 对象时发生异常。该类不能是接口或抽象类。如果类具有接受参数的构造函数,则必须使用 init(args) 方法显式调用该构造函数。错误:''
我只使用了 timezone.cfc 库的
castToUTC
和 castFromUTC
方法,因此,我没有继续解决它不起作用的原因...我编写了自己的组件,仅限于我需要的功能。这是为其他可能遇到此问题的人提供的组件。
component displayname="Timezone Service" hint="Provides methods to convert from/to UTC timezone" {
public any function init() {
this.format = "yyyy-MM-dd HH:mm:ss";
this.LocalDateTime = createObject("java", "java.time.LocalDateTime");
this.ZoneId = createObject("java", "java.time.ZoneId");
this.ZonedDateTime = createObject("java", "java.time.ZonedDateTime");
this.DateTimeFormatter = createObject("java", "java.time.format.DateTimeFormatter");
return this;
}
/**
* Converts given local date-time to UTC.
* @param localDateTime
* @param localTimezone Timezone of the local date-time.
* @return ColdFusion DateTime Object in UTC Timezone
*/
public date function toUTC(date localDateTime, string localTimezone) {
var localZone = this.ZoneId.of(localTimezone); // e.g. "US/Pacific"
var utcZone = this.ZoneId.of("UTC");
// Parse localDateTime to a ZonedDateTime in the local timezone
var zonedDateTime = this.ZonedDateTime.of(
this.LocalDateTime.parse(
DateTimeFormat(arguments.localDateTime, "yyyy-mm-dd'T'HH:nn:ss")
),
localZone
);
// Convert to UTC
var utcDateTime = zonedDateTime.withZoneSameInstant(utcZone);
return utcDateTime.format(
this.DateTimeFormatter.ofPattern(this.format)
);
}
/**
* Converts given UTC date-time to local timezone.
* @param utcDateTime
* @param localTimezone target timezone
* @return ColdFusion DateTime Object in Local Timezone
*/
public date function fromUTC(date utcDateTime, string localTimezone) {
var localZone = this.ZoneId.of(localTimezone); // e.g. "US/Pacific"
var utcZone = this.ZoneId.of("UTC");
// Parse utcDateTime to a ZonedDateTime in UTC
var zonedDateTime = this.ZonedDateTime.of(
this.LocalDateTime.parse(
DateTimeFormat(arguments.utcDateTime, "yyyy-mm-dd'T'HH:nn:ss")
),
utcZone
);
// Convert to local timezone
var localDateTime = zonedDateTime.withZoneSameInstant(localZone);
return localDateTime.format(
this.DateTimeFormatter.ofPattern(this.format)
);
}
}