开发者

How to compile java classes which are inside multiple folders?

I am new to Java world. I have got few classes which are inside nested folders.

My namespace has following folder structure (Assume that companyName folder is on C:\ ):

companyName -> isuName -> projectName -> module1 -> sampleclass1.java
companyName -> isuName -> projectName -> module2 -> sampleclass2.java
companyName -> isuName -> projectName -> module3 -> codePart3.1 -> sampleclass3.java
companyName -> isuName -> projectName -> module3 -> codePart3.2 -> sampleclass4.java

My problem is, I want to compile all of these classes from command prompt.

I tried the following command but its not working :

C:\> javac -sourcepath companyName\*.java

but its not working. I a开发者_运维知识库m getting following error :

javac: no source files
Usage: javac <options> <source files>

Please help to compile all of these classes and possibly to create jar out of it.


I looked at the manual page for javac, and it seems you'll have to spell out the source files on the command line, or you'll have to list them in a separate file, and reference that file on the command line.

I set up the first two source files in your question in a similar tree, and compiled them as follows:

C:\>"\Program Files\Java\jdk1.6.0_24\bin\javac.exe" company\isu\project\module\HelloJava.java company\isu\project\module\ByeBye.java

Using the other method, I produced this file:

C:\>type sourcefiles.txt
company\isu\project\module\HelloJava.java
company\isu\project\module\ByeBye.java

Then I fed that file to the javac compiler, prepending the "@" specifier per the manual.

C:\>"\Program Files\Java\jdk1.6.0_24\bin\javac.exe" @sourcefiles.txt

The manual page for jar doesn't seem to yield the same techniques, so I specified the files on the command line as before.

C:\>"\Program Files\Java\jdk1.6.0_24\bin\jar.exe" -cf myjar.jar company\isu\project\module\HelloJava.class company\isu\project\module\ByeBye.class

Of course, doing it this way is somewhat tedious, so I highly recommend Ant, which you can run on Windows.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜