如何编译多个文件夹中的java类?

发布于 2024-11-06 14:08:36 字数 746 浏览 2 评论 0原文

我是 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

孤蝉 2024-11-13 14:08:36

我查看了 javac 的手册页,看来您必须在命令行上拼写出源文件,或者您必须将它们列出在单独的文件中,并在命令行上引用该文件。

我在类似的树中设置了您的问题中的前两个源文件,并按如下方式编译它们:

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

使用另一种方法,我生成了这个文件:

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

然后我将该文件提供给 javac 编译器,在每个前面添加“@”说明符手动的。

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

jar 的手册页似乎没有为了产生相同的技术,所以我像以前一样在命令行上指定了文件。

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

当然,这样做有点乏味,所以我强烈推荐 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:

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文