Java项目环境准备

时间:2017-01-18 05:02:15

标签: java eclipse setup-project

我是项目环境设置的新手。下面是我在eclipse中的项目结构

Project Name
    --> .settings
    --> .bin
    --> lib
    --> resources
    --> src
    --> .classpath
    --> .project

我正在尝试将src文件夹导出为jar。

当我导出到jar时,所有上述文件夹&文件在jar中创建。但我只需将src文件夹转换为。

当我导出到可执行jar时,所有第三方库都作为类文件导出到jar中。是不是。

导出项目的最佳做法是什么?只有src文件夹或一切。

我需要使用jar / runnable jar。我的要求是编写启动/停止bat文件来调用jar并执行java程序。

请指教。提前谢谢。

1 个答案:

答案 0 :(得分:2)

首先了解这些文件夹实际上的作用非常重要。以下是其中几个文件的工作原理。

.settings -> This file records project specific settings and workspace preferences.

.bin      -> folder is usually where the compiled files are copied to.

lib       -> contains external libraries that are used in your project (like Apache Commons)

resources -> the resources like images, text, pdf, audio, video are usually copied here

src       -> the folder where the project's source files are located.

.classpath -> It contains information that the JDT feature needs in order to properly compile the project: the project's source folders, the output folders , and classpath entries.

.project  -> This file is maintained by the core Eclipse platform, and its goal is to describe the project from a generic, plugin-independent Eclipse view. 

所以你可以看到,如果你排除一些文件,如lib,resources,bin等......你的jar文件可能会停止工作。您的jar文件需要编译文件及其依赖项。

例如:所有已编译的.class文件都在bin文件夹中。由于jar中的.class个文件和.java个文件,您的src无效。如果您删除此bin文件夹,则jar可能会停止工作。

此外,您的项目可能正在使用其他人提供的某些外部库。与Apache Commonsgoogle/guava类似,这些通常位于lib文件夹中。因此,您也无法删除此文件夹。

但是,如果您不再期望使用.java代码,则可以排除eclipse创建的文件来管理此项目。请参阅this帖子。

另见:
1. What's in an Eclipse .classpath/.project file?
2. exclude files from jar or war in eclipse

相关问题