Java source won't compile as soon as I put it in a package?
I installed Maven on my archlinux desktop. I have a perplexing issue.
Following the getting started guide and installing Maven, at the end of it all I had the default company set to zerovector (instead of my-company.) So the directory structure (and package) looks like this: src/com/zerovector/app (or com.zerovector.app)
App just says "Hello World" mvn compile fails. mvn build fails. NoClassDefFound errors when I try to run the product of Maven's processes. Trying to compile it manually (javac App.java) fails with NoClassDefFound. As soon as I remove the package com.zerovector.app; line suddenly it compiles and works. I can go javac App.java and it compiles just fine into App.class (simple Hello World prog.) And this App.class does it's little "Hello World" and exits fine.
Why is the package line throwing java for a bunch of nonesense? Can I fix this or am I going to have to manually code/organize and forget Maven and Packages?
With Maven, the Java class code should be in the directory src/main/java/com/zerovector/app and not in src/com/zerovector/app. If you don't want to use the default source directory you have to change the configuration.
If you use javac then don't change your current directory to src/main/java/com/zerovector/app but stay in the source root directory:
cd src/main/java javac com/zerovector/app/App.java
If you follow this rule, the package declaration and the relative path to the Java source file match and everything works. If you change your current directory to the place where the Java Source file is, then the compiler expects no package (= default package):
cd src/main/java/com/zerovector/app/ javac App.java