Java/Eclipse 相当于 Visual Studio 控制台应用程序 +类库解决方案

发布于 2024-08-08 12:20:30 字数 478 浏览 5 评论 0原文

我是一名 .Net 开发人员,但对于我当前的项目,我必须创建一些 Java 代码。我过去做过一些 Java 编码(我什至使用 Java 学习了 OOP),但对 Eclipse 很陌生,我必须使用它。

我必须创建一些共享通用功能的 Java 控制台应用程序。我想将常见功能捆绑到一个库(JAR 文件)中,并从命令行程序使用该文件。当我更改库时,所有依赖的控制台应用程序也必须重新构建。

在 Visual Studio (.Net) 中,我将创建一个新的解决方案并添加一个“类库”项目和多个“控制台应用程序”项目,并使它们依赖于类库。我在使用 Eclipse/Java 重新创建相同的设置时遇到问题。我猜想 Java 中 .Net 类库的等价物是 JAR 文件。但是,我还没有找到如何在 Eclipse 中创建 JAR 文件项目(我可以将项目导出到 JAR,但这是一个手动步骤;我喜欢自动进行)并从多个“正常”引用此 JAR 项目“Java 项目。

我希望我已经解释清楚了。有人可以透露一些信息吗?

I'm a .Net developer, but for my current project I have to create some Java code. I did some Java coding in the past (I even learned OOP using Java), but am new to Eclipse, which I have to use.

I have to create a few Java console applications that share common functionality. I want to bundle that common functionality into one library (JAR file) and use that file from the command line programs. When I change the library, all dependent console applications also have to be rebuilt.

In Visual Studio (.Net) I would create a new solution and add one "Class Library" project and multiple "Console Application" projects and make them dependent on the Class Library. I'm having trouble recreating the same setup using Eclipse/Java. I guess the Java equivalent of a .Net Class Library is a JAR file. However, I haven't yet found out how to create a JAR file project in Eclipse (I can export a project to a JAR, but that's a manual step; I like this to go automatically) and reference this JAR project from multiple "normal" Java projects.

I hope I've explained myself clearly. Can anybody shed some light?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

魔法少女 2024-08-15 12:20:30

在 Eclipse 中,您可以按照与 VS 中相同的方式进行操作:

  1. 为每个要共享功能的类库 (JAR) 创建一个独立的项目,
  2. 为每个控制台应用程序创建一个项目。在此项目属性窗口中,通过选择您需要的项目使其依赖于其他类库项目

对于自动部署,您可以使用 ANT 任务来进行生成所有文件所需的所有自动化处理。

In eclipse you can proceed the same way you do in VS:

  1. Create an independent project for each class library (JAR) you want to share functionality with
  2. Create a project for each console application. On this project properties window, make it dependent on the other class library projects by selecting the projects you need

For automatic deployment, you can have an ANT task to make all the automated processing you need to generate all the files.

我最亲爱的 2024-08-15 12:20:30

嗯,我不知道是否有一个“自动”功能可以从您的项目创建 JAR 文件。今天我使用的是 Rational Application Developer(与 eclipse 非常相似),但我也使用过 Eclipse 和 Netbeans,但我不记得那个功能了。

也许您可以创建一个键盘快捷键(阅读手册..);)

顺便说一句,您不能将项目“添加到库中”。我认为恰恰相反。我的意思是,您从项目中引用库,而不是从库中引用项目。您需要做的是:

  • 创建您的库并将其导出到 jar 中。
  • 然后创建第二个项目并将该 jar 添加到该项目中。
  • 创建更多项目并执行相同操作。
  • 如果更改库,则只需更换 jar 即可。

希望这对

PD 有帮助:看来巴勃罗知道他在说什么。我只是一个菜鸟程序员。阅读他的解决方案..

Well, i don't know if there is an "automatic" function which can creates the JAR file from your project. Today I'm using Rational Application Developer (very similar to eclipse), but I've used Eclipse and Netbeans too, and i can't remember that feature.

Maybe you can create a keyboard shorcut (read manual..) ;)

By the way, you can't "add a project" to a library. I think it's the other way round. I mean, you reference library from projects, not projects from libraries. What you have to do is:

  • Create your library and export it to a jar.
  • Then create a second project an add that jar to this project.
  • Create more projects and do the same..
  • If you change your library, you just have to replace the jar.

Hope this helps

PD: Seems that Pablo knows what he talks about. I'm just a noob programmer. Read his solution..

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