テンプレート処理中にエラーが発生しました。
Java method "com.liferay.portal.json.JSONFactoryImpl.createJSONObject(String)" threw an exception when invoked on com.liferay.portal.json.JSONFactoryImpl object "com.liferay.portal.json.JSONFactoryImpl@2ad66ae2"; see cause exception in the Java stack trace.

----
FTL stack trace ("~" means nesting-related):
	- Failed at: navigationJSONObject = jsonFactoryUti...  [in template "17855804202317#32484267#LEARN-ARTICLE-NAV" at line 4, column 9]
----
1<#assign 
2	groupFriendlyURL = themeDisplay.getScopeGroup().getFriendlyURL() 
3	groupPathFriendlyURLPublic = themeDisplay.getPathFriendlyURLPublic() + groupFriendlyURL 
4	navigationJSONObject = jsonFactoryUtil.createJSONObject(navigation.getData()) 
5	navigationMenuItems = 
6
7			"Analytics Cloud": { 
8				"image": "/documents/d${groupFriendlyURL}/analytics_c-svg", 
9				"title": "Analytics Cloud", 
10				"url": "analytics-cloud" 
11			}, 
12			"Commerce": { 
13				"image": "/documents/d${groupFriendlyURL}/commerce_product-svg", 
14				"title": "Commerce", 
15				"url": "commerce" 
16			}, 
17			"DXP": { 
18				"image": "/documents/d${groupFriendlyURL}/dxp_p-svg", 
19				"title": "DXP / Portal", 
20				"url": "dxp" 
21			}, 
22			"Liferay Cloud": { 
23				"image": "/documents/d${groupFriendlyURL}/dxp_c-svg", 
24				"title": "Liferay Cloud", 
25				"url": "liferay-cloud" 
26			}, 
27			"Reference": { 
28				"image": "/documents/d${groupFriendlyURL}/reference-svg", 
29				"title": "Reference", 
30				"url": "reference" 
31
32
33 
34	breadcrumbJSONArray = navigationJSONObject.getJSONArray("breadcrumb") 
35	childrenJSONArray = navigationJSONObject.getJSONArray("children") 
36	parentJSONObject = navigationJSONObject.getJSONObject("parent") 
37	productJSONObject = breadcrumbJSONArray.getJSONObject(breadcrumbJSONArray.length()-1)!navigationJSONObject.getJSONObject("self") 
38	siblingsJSONArray = navigationJSONObject.getJSONArray("siblings") 
39/> 
40 
41<div class="learn-article-nav"> 
42	<#if productJSONObject?has_content && productJSONObject.getString("title")?has_content && navigationMenuItems[productJSONObject.getString("title")]?has_content && navigationMenuItems[productJSONObject.getString("title")].title?has_content> 
43		<div 
44			class="dropdown learn-article-nav-root learn-dropdown" 
45
46			<div class="learn-article-nav-item"> 
47				<div class="d-flex"> 
48					<div class="learn-article-nav-image"> 
49						<img 
50							class="lexicon-icon lexicon-icon-caret-bottom product-icon" 
51							role="presentation" 
52							src='${navigationMenuItems[productJSONObject.getString("title")].image}' 
53							viewBox="0 0 512 512" 
54						/> 
55					</div> 
56 
57					<span class="learn-article-nav-text">${navigationMenuItems[productJSONObject.getString("title")].title}</span> 
58				</div> 
59 
60				<div id="dropdown-icon"> 
61					<svg 
62						class="lexicon-icon lexicon-icon-caret-bottom" 
63						role="presentation" 
64						viewBox="0 0 512 512" 
65
66						<use xlink:href="/o/admin-theme/images/clay/icons.svg#caret-bottom"></use> 
67					</svg> 
68				</div> 
69			</div> 
70 
71			<ul class="dropdown-menu learn-dropdown-menu"> 
72				<#list navigationMenuItems as key, value> 
73					<li> 
74						<a 
75							class="dropdown-item learn-article-nav-item" 
76							href="/w/${navigationMenuItems[key].url}/index" 
77							tabindex="4" 
78
79							<span class="d-flex"> 
80								<span class="learn-article-nav-image"> 
81									<img 
82										class="lexicon-icon lexicon-icon-caret-bottom product-icon mt-0 mr-2" 
83										role="presentation" 
84										src="${value.image}"height: 25px; margin-left: 5px; max-width: none; width: 25px; 
85										viewBox="0 0 512 512" 
86									/> 
87								</span> 
88								<span class="learn-article-nav-text">${value.title}</span> 
89							</span> 
90 
91							<#if navigationMenuItems[productJSONObject.getString("title")].url == value.url> 
92								<span> 
93									<@clay["icon"] symbol="check" /> 
94								</span> 
95							</#if> 
96						</a> 
97					</li> 
98				</#list> 
99			</ul> 
100		</div> 
101	</#if> 
102 
103	<div class="learn-article-nav-content"> 
104		<#if parentJSONObject?has_content && parentJSONObject.getString("url")?has_content> 
105			<div class="learn-article-nav-item learn-article-nav-parent liferay-nav-item p-2"> 
106				<div class="mr-2"> 
107					<a 
108						href='${parentJSONObject.getString("url")}' 
109
110						<svg 
111							class="lexicon-icon lexicon-icon-angle-left" 
112							role="presentation" 
113							viewBox="0 0 512 512" 
114
115							<use xlink:href="/o/admin-theme/images/clay/icons.svg#angle-left"></use> 
116						</svg> 
117					</a> 
118				</div> 
119 
120				<span>${parentJSONObject.getString("title")}</span> 
121			</div> 
122		</#if> 
123 
124		<#if childrenJSONArray.length() gt 0> 
125			<ul class="m-0 p-2"> 
126				<#list 0..childrenJSONArray.length()-1 as i> 
127					<li class="learn-article-nav-item"> 
128						<a 
129							class='liferay-nav-item ${(navigationJSONObject.getJSONObject("self").url == childrenJSONArray.getJSONObject(i).url)?then("selected", "")}' 
130							href="${childrenJSONArray.getJSONObject(i).url}" 
131
132							<span>${childrenJSONArray.getJSONObject(i).getString("title")}</span> 
133						</a> 
134					</li> 
135				</#list> 
136			</ul> 
137		<#elseif siblingsJSONArray.length() gt 0> 
138			<ul class="m-0 p-2"> 
139				<#list 0..siblingsJSONArray.length()-1 as i> 
140					<li class="learn-article-nav-item"> 
141						<a 
142							class='liferay-nav-item ${(navigationJSONObject.getJSONObject("self").url == siblingsJSONArray.getJSONObject(i).url)?then("selected", "")}' 
143							href="${siblingsJSONArray.getJSONObject(i).url}" 
144
145							<span>${siblingsJSONArray.getJSONObject(i).getString("title")}</span> 
146						</a> 
147					</li> 
148				</#list> 
149			</ul> 
150		</#if> 
151	</div> 
152</div> 

コンテナでのスクリプトの実行

TomcatおよびLiferayファイルの設定、アーティファクトのデプロイ、およびパッチの適用以外に、Liferayコンテナで実行したいことが他にもある場合は、スクリプトを使用できます。 コンテナは、 ライフサイクルのいくつかの時点で特定のフォルダー内のスクリプトをスキャンします。 次の表に、スクリプトの挿入ポイントを示します。

ライフサイクルフェーズDescriptionターゲットコンテナフォルダー
事前構成構成フェーズの前にスクリプトを実行する/usr/local/liferay/scripts/pre-configure
設定ファイルを [Liferay Home]にコピーしてから実行する/mnt/liferay/scripts
スタートアップ前Tomcatを起動する前にスクリプトを実行します/usr/local/liferay/scripts/pre-startup
シャットダウン後Tomcatをシャットダウンした後にスクリプトを実行する/usr/local/liferay/scripts/post-shutdown

次のセクションでは、上記のフェーズでのスクリプトの作成と実行について説明します。

構成フェーズでのスクリプトの実行

TomcatとLiferayを構成する方法が、構成フェーズが提供する方法以外にもある場合は、それらを構成フェーズスクリプトに実装します。 構成フェーズの詳細は、 コンテナのライフサイクルとAPI を参照してください。

ここでは、バインドマウントを使用して構成フェーズスクリプトを設定する手順を示します。

  1. ローカル構成スクリプト用の任意のフォルダーを作成します。

    mkdir scripts
    
    tip

    コンテナの /mnt/liferay フォルダをマウント を既に計画している場合は、構成フェーズスクリプトをローカルのマウントフォルダ内のscriptsというフォルダに入れてConfigure Phaseに含めることができます。 [local-folder]/scripts フォルダは、コンテナの /mnt/liferay/scripts フォルダにマッピングされます。

  2. 事前に設定したアクションを実行するためのスクリプトを作成します。

    echo "inside some-pre-configure.sh" > scripts/configure-phase-script.sh
    
  3. スクリプトのフォルダーをコンテナの /mnt/liferay/scripts フォルダーにバインドマウントするDockerコンテナを実行します。

    docker run -v $(pwd)/scripts:/opt/liferay/scripts ...
    

エントリポイントは、ファイルを /mnt/liferay/files にコピーした後、構成フェーズでスクリプトを実行し、次のメッセージを出力します。

[LIFERAY] Executing scripts in /mnt/liferay/scripts:

[LIFERAY] Executing configure-phase-script.sh.
in configure-phase-script.sh

他のフェーズでのスクリプトの実行

コンテナは、構成フェーズの以外でもスクリプトを実行する方法を提供します。

ライフサイクルフェーズ説明ターゲットコンテナフォルダー
事前構成構成フェーズの前にスクリプトを実行する/usr/local/liferay/scripts/pre-configure
スタートアップ前Tomcatを起動する前にスクリプトを実行します/usr/local/liferay/scripts/pre-startup
シャットダウン後Tomcatをシャットダウンした後にスクリプトを実行する/usr/local/liferay/scripts/post-shutdown

コンテナの /usr/local/liferay/scripts フォルダーの構造は次のとおりです。

/usr/local/liferay/scripts
├───pre-configure
├───pre-startup
└───post-shutdown

同じ構造のホストフォルダーを作成し(以下を参照)、スクリプトを入力すると、ホストフォルダーを / usr/local/liferay/scripts フォルダーにマッピングすることで、コンテナでスクリプトを使用できるようになります。

[host folder]
├───pre-configure
├───pre-startup
└───post-shutdown

上記のサブフォルダにスクリプトを作成する一般的な手順は次のとおりです。

  1. スクリプトフェーズフォルダーの任意の親フォルダーを作成します。

    mkdir [host-folder]
    
  2. スクリプトフェーズフォルダーを作成します。

    cd [host-folder]
    mkdir pre-configure pre-startup post-shutdown
    
  3. アクションをフェーズフォルダーの任意のスクリプトに実装します。

    warning

    スクリプトに exit キーワードを使用しないでください。 スクリプトで exit を実行すると、エントリーポイントの起動処理が中断されます。

    echo "inside pre-configure-script.sh" > pre-configure/some-pre-configure-script.sh
    
    echo "inside pre-startup-script.sh" > pre-startup/some-pre-startup-script.sh
    
    echo "inside some-post-shutdown-script.sh" > post-shutdown/some-post-shutdown-script.sh
    
  4. ホストフォルダーをコンテナの /usr/local/liferay/scripts / フォルダーにバインドマウントするDockerコンテナを実行します。

    docker run -v $(pwd)/[host-folder]:/usr/local/liferay/scripts ...
    

エントリポイントは、それぞれのフェーズ中にスクリプトを実行し、次のようなメッセージを出力します。

[LIFERAY] Executing scripts in /usr/local/liferay/scripts/pre-configure:

[LIFERAY] Executing some-pre-configure-script.sh.
inside some-pre-configure-script.sh

まとめ

これで、コンテナのライフサイクルのすべての部分でスクリプトを実行する方法がわかりました。

関連トピック