如何编译多个文件夹中的java类?
我是 Java 世界的新手。我有几个类位于嵌套文件夹内。
我的命名空间具有以下文件夹结构(假设 companyName 文件夹位于 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
我的问题是,我想从命令提示符编译所有这些类。
我尝试了以下命令,但它不起作用:
C:\> javac -sourcepath companyName\*.java
但它不起作用。我收到以下错误:
javac: no source files
Usage: javac <options> <source files>
请帮助编译所有这些类,并可能从中创建 jar。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我查看了 javac 的手册页,看来您必须在命令行上拼写出源文件,或者您必须将它们列出在单独的文件中,并在命令行上引用该文件。
我在类似的树中设置了您的问题中的前两个源文件,并按如下方式编译它们:
使用另一种方法,我生成了这个文件:
然后我将该文件提供给 javac 编译器,在每个前面添加“@”说明符手动的。
jar 的手册页似乎没有为了产生相同的技术,所以我像以前一样在命令行上指定了文件。
当然,这样做有点乏味,所以我强烈推荐 Ant,它可以在 Windows 上运行。
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:
Using the other method, I produced this file:
Then I fed that file to the javac compiler, prepending the "@" specifier per the manual.
The manual page for jar doesn't seem to yield the same techniques, so I specified the files on the command line as before.
Of course, doing it this way is somewhat tedious, so I highly recommend Ant, which you can run on Windows.