开发者

New to java libraries - what to include in a jar file

开发者 https://www.devze.com 2023-04-01 01:34 出处:网络
I have an Android project which included a class with a file copy method. Out of interest I thought I\'d extract t开发者_Python百科his into a (non-android, just plain java) project of its own, as it\'

I have an Android project which included a class with a file copy method. Out of interest I thought I'd extract t开发者_Python百科his into a (non-android, just plain java) project of its own, as it's something that other projects could make use of.

I then thought I'd take a look at creating a jar from this new project, so other project could just have the jar in a 'lib' folder and reference it as a library, rather than me having to import the project in eclipse etc.

My question is, what should I be including in the jar file when I go through the jar export wizard in eclipse? It seems to work if I just include the *.class file but what if my project contained more than a single file, and had multiple packages etc. Would I need the .classpath and .project for example?

Thanks, Barry


You can include things that are needed at runtime.

For example:

  • The .class files contain the compiled code; this is needed at runtime.
  • You may also need to include other resources, such as images.
  • Sometimes you may find it handy to include a custom META-INF/MANIFEST.MF.
  • Sometimes it's useful to include a dynamically linked, native library (e.g., a Windows DLL), but to use it you'll usually need to extract it first to a temporary location.
  • Sometimes additional resources are zipped into a jar, such as API documentation for a library.

The .project and .classpath files are not used at runtime. They do not need to be included in the jar file.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号