0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【SAP BAS】Java実行時の文字化けとその対処法

Last updated at Posted at 2025-07-11

はじめに

Visual Studio Code(VSCode)で正常に動作していたJavaアプリケーションを、SAP Business Application Studio(BAS)に移行して実行しようとしたところ、ファイルの文字化けが原因でエラーが発生しました。
本記事では、発生した問題の原因と解決策について記載します。

環境

  • 開発環境:Visual Studio Code (VSCode)
  • 移行先の開発環境:SAP Business Application Studio (BAS)
  • 言語 / フレームワーク:Java / Spring Boot
  • 実行方法:launch.jsonによるデバッグ実行
  • データベース:H2 Database

エラー内容

文字化けによりデータが桁数制限を超え、エラーが発生
※以下は一部抜粋したエラーメッセージです

org.h2.jdbc.JdbcSQLDataException:Value too long for column "IF_STATUS":"U&'\fffd\fffd\fffd\fffd...'" (12)

原因

VSCodeではJVMのデフォルト文字コードがUTF-8に設定されているのに対し、BASのJVMではANSI_X3.4-1968に設定されていたため、文字化けが発生しました。
以下のコードで確認した結果は次の通りです。

System.out.println(System.getProperty("file.encoding"));
実行環境 文字コード
Visual Studio Code (VSCode) UTF-8
SAP Business Application Studio (BAS) ANSI_X3.4-1968

試したこと

①application.ymlでSQLの文字エンコードを指定

application.yml
sql:
  init:
    mode: always
    encoding: UTF-8

→同様のエラーが発生しました。

②pom.xmlのSpring Boot Maven PluginにJVM引数を追加

pom.xml
	<build>
		<plugins>
			<plugin>
				<groupId>org.springframework.boot</groupId>
				<artifactId>spring-boot-maven-plugin</artifactId>
				<configuration>
				<jvmArguments>-Dfile.encoding=UTF-8</jvmArguments>
					<excludes>
						<exclude>
							<groupId>org.projectlombok</groupId>
							<artifactId>lombok</artifactId>
						</exclude>
					</excludes>
				</configuration>
			</plugin>
		</plugins>
	</build>

→こちらも同様のエラーが発生しました。

解決策

launch.jsonvmArgs-Dfile.encoding=UTF-8 を追記することで解決しました。

launch.json
"vmArgs": "-Dspring.profiles.active=development -Duser.timezone=UTC -Dfile.encoding=UTF-8"

結果

SQLの文字化けと桁数エラーが解消し、BASでも正常に動作することが確認できました。

System.out.println(System.getProperty("file.encoding")); 
// 出力結果: UTF-8

さいごに

今回は、開発環境をVSCodeからBASへ移行した際に発生したJavaアプリの文字化け問題と、その原因・対処法をご紹介しました。
少しでも参考になれば幸いです。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?