0

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

Shekhar
  • 11,438
  • 36
  • 130
  • 186
  • @equality, Thanks for help. I went through that question. Its not similar to my problem. I do not have duplicate classes and I am using windows machine so I cant use shell script and other commands specified in that question/answer. Is there any simple way to compile all the classes present in one package? – Shekhar May 11 '11 at 10:45

1 Answers1

2

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.

rickumali
  • 707
  • 8
  • 17