tags:

views:

26

answers:

2

I have the following directory structure form where I am invoking javac
src/ lib/ build/

Under src:

src/com/xyz/App.java -- contains the main class
src/com/xyz/base/j1.java
src/com/xyz/base/j2.java
src/com/xyz/exceptions/e1.java
src/com/xyz/hibernate/factory/hbf1.java
src/com/xyz/hibernate/helper/hbh1.java


Under lib:

lib/hibernate.jar lib/commons.jar



At the top level, I am using the following javac command:

javac -verbose -classpath lib/hibernate.jar:lib/commons.jar -d ./build -sourcepath ./src com/xyz/*.java

and I receive the following output
javac: No match

How should the args be passed to javac?

And here is the ANSWER:
javac -verbose -d build -classpath lib/commons.jar:lib/hibernate.jar [complete path for ALL the directories]/*.java

+1  A: 

Perhaps I'm being somewhat pedantic here, but I was wondering:

  -classpath ./lib/hibernate/jar:lib/commons.jar
#                           ^    ^^^
#                           |    shouldn't this be './lib', too?
#                           |
#                           shouldnt this be a '.'?
stakx
Does not make any difference even if I change all the lib -> ./lib
That was a typo.. thanks for pointing that out.
There are quite some subdirectories: com/xyz/base, com/xyz/exceptions, com/xyz/hibernate/factory and com/xyz/hibernate/helper.. Do i need to specifically list the .java files there?
_@user350129,_ I don't know Java that well; but I would suppose that `com/src/xyz/*.java` would not include the `.java` files in the various subdirectories, since -- like user nos states -- wildcards are expanded by your shell, ie. before `javac` even runs.
stakx
A: 

javac won't expand wildcards, that's what your shell does. so when you specify com/xyz/*.java , that will not expand to anything, as those files are under src/ but the shell doesn't know that. If you list out every java file as com/xyz/Foo.java com/xyz/Bar.java etc, it should work.

(note that if you're on windows you'll need ; and not : to seperate classpaths)

Something like this might work:

javac -verbose -classpath build:lib/hibernate.jar:lib/commons.jar -d ./build  ./src/com/xyz/base/*java ./src/com/xyz/exceptions/*.java ./src/com/xyz/hibernate/factory/*.java ./src/com/xyz/*.java

I'd not do this other than as an exercise on how to compile from a command line, otherwise use a build tool like ant

nos
I am on Linux..
before I compile from ant, I am curious to know the build process.. that's why all my effort
I tried the following and it all fails:
Fails with what ? How ? Where ? Possibly some source directories were missing, like ./src/com/xyz/*.java
nos
Why do I need to include the dir "build" in the classpath? i.e. javac -classpath build:lib/hibernate.jar:lib/commons.jar
And compile still fails:
javac -verbose -classpath build:lib/commons.jar:lib/hibernate.jar -d build ./src/com/xyz/base ./src/com/xyz/App.java ./src/com/xyz/hibermate/factory/*.java ...
So compiled classes can be resolved when something that depends on them is compiled. Anyway, What, specfiically, is the *exact* error you are getting ? Please post the output instead of "it failes"
nos
I am using hibernate annotations. Do I need to use an annotation processor for use with javac?
OK>. folks.. I got the build process to complete. Now how do I execute the program?
java ./build/com/xyz/App -- generates the error "Exception in thread "main" java.lang.NoClassDefFoundError: "
@user350129 You need to tell it the class path and the class that contains the main method to start `java -classpath build:lib/commons.jar:lib/hibernate.jar com.xyz.App`
nos

related questions