1

I am new to project environment setup. Below is my project structure in eclipse

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

I am attempting to export src folder as jar.

When i export to jar, all the above folders & files are created in jar. But i need to convert only src folder as.

Also when i export to executable jar, all the third party libraries are exported as class files in jar. is it right.

What is the best practice to export project. Only src folder or everything.

Which i need to use jar/runnable jar. My requirement is to write start/stop bat file to call jar and execute java program.

Please advice me. Thanks in advance.

deadend
  • 1,286
  • 6
  • 31
  • 52

1 Answers1

2

First it's important to know what these folders actually do. Following are the workings of several of these files.

.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. 

So you can see that if you exclude some of the files like lib, resources, bin etc... Your jar file will probably stop working. Your jar file needs compiled files and their dependencies.

For example: All your compiled .class files are in bin folder. And your jar works because of these .class files and NOT .java files that are in src. If you delete this bin folder then your jar will probably stop working.

Also, your project may be using some external library supplied by someone else. Like Apache Commons or google/guava and these are usually in lib folder. So you can't delete this folder as well.

However, if you no longer expect to use .java code, then you can exclude files that were created by eclipse to manage this project. See this post.

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

Community
  • 1
  • 1
Raman Sahasi
  • 30,180
  • 9
  • 58
  • 71
  • What is the best practice to create jar i mean jar / runnable jar. we can keep third party libraries outside and set it classpath right or we can keep third party lib inside main jar itself. i am struggling. Please advice. – deadend Jan 19 '17 at 07:18
  • 1
    `jar` means `Java Archive`. It bundles everything that your software needs to run. Your files, your dependencies, your resources. So the conventional practice is to keep each and everything inside that jar so that you can just transfer it to client's machine and simply deploy that file. What's the need to keeping libraries outside? If that's something that you really wanna do than there's really no need to create jar, you can simply execute them via command line on client's machine. – Raman Sahasi Jan 19 '17 at 07:55
  • 1
    Noted Raman. if i export this as non runnable jar. then how to write bat file 1. jdk [C:\Program Files (x86)\Java\jdk1.7\bin] 2. myapp.jar [D:\app\main\myapp.jar] Please help me. i am really struggling. – deadend Jan 19 '17 at 07:59
  • If you don't want it as JAR, then once you get the JAR file, you can simply extract it using any archive tool like winzip, 7z. Now you can simply execute them using command line. – Raman Sahasi Jan 19 '17 at 10:02