Not able to compile and run a classpath Java Application

68 views Asked by At

I'm having serious problems understanding how to manage folders vs. packages names when it comes to deploying Java. I have this little program, constructed like this:

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)

So, my intentions were to have two packages: com.myname.appname.data and com.myname.appname.main, and correct me if I am wrong, I choose this layout so to be able to create two modules to set up the app in a modular way.

I compile using deployer-classpath.bat (old-style compilation):

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 -->

Well, this is the output:

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

Same result if I run it as a modular application, using 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"
1

There are 1 answers

0
JohnXF On

Without being able to try this myself it is hard to diagnose the problem. But are you sure the JARs contain what you think they contain and in the right folders? Your manual scripting of the compilation and packaging is a likely source of errors. Doing that sort of thing manually with Java requires a lot of things to be exactly correct. That is why build tools like ant, maven and so on are usually used and also the reason people use IDEs. You pick a tool, layout your source to match the tools preferences and then take advantage of the tool's abilities to abstract away all the complexity of the compilation and packaging.

I would suggest you perhaps take a look at Maven as a good starting point and rework your folder structure to play nicely with that.