Java/Eclipse 相当于 Visual Studio 控制台应用程序 +类库解决方案
我是一名 .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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在 Eclipse 中,您可以按照与 VS 中相同的方式进行操作:
对于自动部署,您可以使用 ANT 任务来进行生成所有文件所需的所有自动化处理。
In eclipse you can proceed the same way you do in VS:
For automatic deployment, you can have an ANT task to make all the automated processing you need to generate all the files.
嗯,我不知道是否有一个“自动”功能可以从您的项目创建 JAR 文件。今天我使用的是 Rational Application Developer(与 eclipse 非常相似),但我也使用过 Eclipse 和 Netbeans,但我不记得那个功能了。
也许您可以创建一个键盘快捷键(阅读手册..);)
顺便说一句,您不能将项目“添加到库中”。我认为恰恰相反。我的意思是,您从项目中引用库,而不是从库中引用项目。您需要做的是:
希望这对
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:
Hope this helps
PD: Seems that Pablo knows what he talks about. I'm just a noob programmer. Read his solution..