开发者

Compiling java programs from CLI using javac

开发者 https://www.devze.com 2023-01-15 18:56 出处:网络
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

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


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

0

精彩评论

暂无评论...
验证码 换一张
取 消