在部署 Java 时,我在理解如何管理文件夹和包名称时遇到了严重的问题。我有这个小程序,构造如下:
deployer-classpath.bat
deployer-modulepath.bat
src
data
com
myname
appname
data
*.java
resources.properties
resources_en_GB.properties
main
com
myname
appname
main
App.java (main)
所以,我的意图是有两个包:com.myname.appname.data 和com.myname.appname.main,如果我错了,请纠正我,我选择这个布局以便能够创建两个模块来设置以模块化方式应用程序。
我使用deployer-classpath.bat编译(旧式编译):
call "javac.exe" -d ".\output\classes" ".\src\data\com\micesp\PMapp\data\*.java"
call "jar.exe" --create --file ".\output\libs\data.jar" -C ".\output\classes" .
rmdir /q/s ".\output\classes"
mkdir ".\output\classes"
call "javac.exe" -d ".\output\classes" -classpath ".\output\libs\data.jar" ".\src\main\com\micesp\PMapp\main\*.java"
call "jar.exe" -c -f ".\output\libs\main.jar" -C ".\output\classes" .
rmdir /q/s ".\output\classes"
call "java.exe" -classpath "%cd%\output\libs\data.jar";"%cd%\output\libs\main.jar" "com.micesp.PMapp.main.App"
<!-- language: lang-none -->
好吧,这是输出:
Exception in thread "main" java.lang.ExceptionInInitializerError
at com.micesp.PMapp.main.App.main(App.java:25)
Caused by: java.util.MissingResourceException: Can''t find bundle for base name com.micesp.PMapp.data.resources, locale en_GB
at java.base/java.util.ResourceBundle.throwMissingResourceException(ResourceBundle.java:2055)
at java.base/java.util.ResourceBundle.getBundleImpl(ResourceBundle.java:1689)
at java.base/java.util.ResourceBundle.getBundleImpl(ResourceBundle.java:1593)
at java.base/java.util.ResourceBundle.getBundleImpl(ResourceBundle.java:1556)
at java.base/java.util.ResourceBundle.getBundle(ResourceBundle.java:932)
at com.micesp.PMapp.data.ProductManager$ResourceFormatter.<init>(ProductManager.java:219)
at com.micesp.PMapp.data.ProductManager.<clinit>(ProductManager.java:36)
... 1 more
如果我使用deployer_modulepath.bat将其作为模块化应用程序运行,结果相同:
call "javac.exe" -d ".\output\classes" ".\src\data\com\micesp\PMapp\data\*.java"
call "jar.exe" --create --file ".\output\libs\data.jar" -C ".\output\classes" .
rmdir /q/s ".\output\classes"
mkdir ".\output\classes"
call "javac.exe" -d ".\output\classes" -classpath ".\output\libs\data.jar" ".\src\main\com\micesp\PMapp\main\*.java"
call "jar.exe" -c -f ".\output\libs\main.jar" -C ".\output\classes" .
rmdir /q/s ".\output\classes"
call "java.exe" --module-path ".\output\libs" -m "main/com.micesp.PMapp.main.App"