自分でjavaソースのコンパイルを試しました

既存のあるjavaプロジェクト、あるファイル(C:/source-root/source/target-package/TargetFile.java)のソースを修正して、コンパイルしてデバッグしたいです。 でもコンパイルのバッチを実行すると、たくさんのファイルに妙な文字が存在し、文字化けでコンパイルできません。 そのため、自分で(修正されたファイルだけを)コンパイルを試しました。

※問題解決して数日後経って記録するので、一部の順序が間違いたかもしれません。

①操作:

cd C:/source-root/source/target-packageして、javac -d . TargetFile.java
結果:
  can not find other java file of my project
  パッケージjp.co.project-name.online.entityは存在しません

②操作:

cd C:/source-root/sourceして、javac -d . target-package/TargetFile.java
結果:
  シンボルを見つけられません、caused by パッケージ******は存在しません
原因と解決方法:
  classpathを指定してない

③操作:

javac -d . -cp “C:/classpath1/common” target-package/TargetFile.java -Xmaxerrs 200
結果:
  シンボルを見つけられません、caused by パッケージ******は存在しません
原因と解決方法:
  文字化け発生

④操作:

javac -d C:/source-root/target -encoding SJIS -cp “C:/classpath1/common;” target-package/TargetFile.java -Xmaxerrs 200
結果:
  can not find third-party libraries i imported (e.g. org.apache.commons.collections)
原因と解決方法:
  classpathにthird-partyのパスを指定してない

⑤操作:

javac -d C:/source-root/target -encoding SJIS -cp “C:/classpath1/common;C:/source-root/target” target-package/TargetFile.java -Xmaxerrs 200
結果:
想定外のエラーが発生しました。java.lang.UnsupportedClassVersionError: target-package/TargetFile has been compiled by a more recent version of the Java Runtime (class file version 61.0), this version of the Java Runtime only recognizes class file versions up to 52.0 (クラス[jp.co.project-name.online.blogic.TargetFile]をロードできません)
原因と解決方法:
  コンパイル用のjavaのバージョンを変更
プロジェクトを立ち上げるバッチに、次の行があります、そのjavaのバージョンを用いる。
SET JAVA_HOME=C:java-path1/jdk-8u202-windows-x64

⑥操作:

C:java-path1/jdk-8u202-windows-x64/bin/javac.exe -d C:/source-root/target -encoding SJIS -cp “C:/classpath1/common;C:/source-root/target” target-package/TargetFile.java -Xmaxerrs 200
結果:
コンパイル成功、後はプロジェクトも立ち上げた。

⑦操作:vscodeでdebugする

結果:
Cannot evaluate because of java.lang.IllegalStateException: Project frontend1 cannot be found

"configurations": [
    {
        "type": "java",
        "name": "Debug (Attach)",
        "projectName": "error-project-name",
        "request": "attach",
        "hostName": "localhost",
        "port": 8000
    }
]

原因と解決方法:
projectNameが間違いました。 “projectName”: “error-project-name"をprojectName”: "frontend1"に修正します。

⑧操作:vscodeでdebugする

結果:
vscodeのdebugのwatchパネルで次のエラーが出ます。
Cannot evaluate because of compilation error(s): The type java.lang.Object cannot be resolved. It is indirectly referenced from required .class files
The type java.lang.Object cannot be resolved. It is indirectly referenced from required .class files
a cannot be resolved to a variable
Evaluations must contain either an expression or a block of well-formed statements.
原因と解決方法:
vscodeのjavaのバージョンを変更、setting.jsonで"java.configuration.runtimes"を設置

⑨操作:vscodeでdebugする

結果:
vscodeのdebugのwatchパネルで次のエラーが出ます。
Cannot evaluate because of compilation error(s): parm2 cannot be resolved to a variable.
原因と解決方法:
プラグインのjavaのバージョンが不一致です。
setting.jsonで"java.jdt.ls.java.home": "C:java-path1/jdk-8u202-windows-x64"を設置、
ついでにソースの文字コードがsjisなので、“files.encoding”: "sjis"も設置

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值