我怎么能创建.jar文件? [英] How can I create a .jar file?

查看:89
本文介绍了我怎么能创建.jar文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

教程中,我发现了jar文件可以通过以下方式创建:

In the tutorial I found out that jar files can be created in the following way:

jar cf jar-file input-file(s)

但是,目前还不清楚输入文件是什么。是.java文件还是.class文件?从同一页面上的示例我可以假设它应该是.class文件。

However, it was not clear what are the input-file(s). Is that .java files or .class files? From the examples on the same page I can assume that should be .class files.

但是现在还不清楚我应该把哪些.class文件放在那里。编译.java文件后,我有很多.class文件。其中一个原因是我有很多这样的文件:GameWindow $ 2 $ 10class,GameWindow $ 2 $ 7.class等等。我是否应该将所有这些内容都包含在命令行中以创建.jar文件?

But now it is not clear which .class files should I put there. After the compilation of .java files I have a lot of .class files. One of the reason of that is that I have a lot files like that: GameWindow$2$10class, GameWindow$2$7.class and so on. Should I include all of them into the command line for the creation of the .jar file?

要运行我的应用程序,我使用 java Game 。那么,当我创建一个.jar文件时,我只需要使用Game.class文件吗?另一方面,其他类文件对应于应用程序使用的类。

To run my application I use java Game. So, my be I need to use only Game.class file when I create a .jar file? On the other hand other class files corresponds to classes used by the application.

我的软件使用外部库(在编译期间我指定了这些库的.jar文件)。我的应用程序的.jar文件是否能够在不包含已使用库的.jar文件的计算机上运行?

My software use external libraries (during compilation I specify .jar files of these libraries). Will .jar file of my application be able to run on the computer which does not contain the .jar file of used library?

推荐答案


但是,目前尚不清楚输入文件是什么。是.java文件还是.class文件?从同一页面上的示例我可以假设应该是.class文件。

However, it was not clear what are the input-file(s). Is that .java files or .class files? From the examples on the same page I can assume that should be .class files.

是的,您需要包含类文件。

Yes, you need to include the class files.


我有很多这样的文件:GameWindow $ 2 $ 10class,GameWindow $ 2 $ 7.class等等。我是否应该将所有这些文件包含在命令行中以创建.jar文件?

I have a lot files like that: GameWindow$2$10class, GameWindow$2$7.class and so on. Should I include all of them into the command line for the creation of the .jar file?

是的,这些来自内部类;你也需要它们。

Yes, these are from inner classes; you need them as well.


要运行我的应用程序,我使用java Game。那么,当我创建一个.jar文件时,我只需要使用Game.class文件吗?

To run my application I use java Game. So, my be I need to use only Game.class file when I create a .jar file?

不,类游戏将使用其他类,而后者又使用其他类。你需要它们。

No, class Game will use other classes, which in turn use others. You need them all.


我的应用程序的.jar文件能否在不包含.jar文件的计算机上运行二手图书馆?

Will .jar file of my application be able to run on the computer which does not contain the .jar file of used library?

否。

也就是说,手动创建一个JAR这是一个很好的学习经历,但不是你在实践中真正做的事情。

That said, creating a JAR manually is a good learning experience, but not something you'd really do in practice.

你应该考虑自动化你的JAR建设。查看例如Ant: http://ant.apache.org/

You should probably look into automating you JAR building. Check out e.g. Ant: http://ant.apache.org/

这篇关于我怎么能创建.jar文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆