Hi, Im Ji-nun !
I let you know how to create executable "jar" files on CMD(console) on this post
Not on IDE like Eclipse.
In my case, I don't use a developing environment like Eclipse when writing a simple java program,
but I use a simple text editor like Sublime Text.
It will be easy to create "jar" files by IDE, but I try it on CMD(console)
1. Compile your program
I moved files to "C:\Java" for easy to compile.
In my case, Includes that external library "json_simple-1.1.jar" for use JSON.
- Client source for use console
- Client source for use GUI
- Server source for use GUI
I packaged it because I wrote the sources in various ways.
2. Create "jar"
Before create "jar", let's find out about "jar" and "jar's options".
|| jar : Abbreviation of Java Archive. It is the package file format for publish application software or library on Java platform by tie a bunch of Java class files, associative metadata and resources(text, image) together in one file.
(source: Wikipedia-Kor https://ko.wikipedia.org/wiki/JAR_(%ED%8C%8C%EC%9D%BC_%ED%8F%AC%EB%A7%B7)
|| Options :
-c | Create new archive |
-C | Change to designated directory and include next file |
-t | List contents about archive |
-x | Extract named(or all) files in archive |
-u | Update existing archive |
-f | Assign file name of archive |
-v | Generate verbose output for standard output |
-m | Contains evidence from specified proof file |
-0 | Only save and do not use zip compression |
-M | Do not create proof file for the entry |
-i | Generates index information for the specified jar file |
(source: (KOR) http://ra2kstar.tistory.com/125)
I use 4 options c, v, m, f.
>jar -cvmf Manifest.txt Server.jar test\server\*.class json_simple-1.1.jar
[proof file] [file name] [class file] [external library]
Include proof information from designated proof file and named archive file with create new archive.
And make generate detailed information output about standard output.
[Proof file] - You can write anything for this text file.
If you don't have external library, you just write Main-Class: test.server.ServerGUI in Manifest.txt.
The reason of create Manifest file is "main()" function has to specify the position in which class it is in.
I designate files for package, so add "test.server." in front of "ServerGUI".
I create Manifest and specified main class.
Then I got no problems with create "jar" file but I got an error.
-Error occurred about can't find main class
C:\Java>java -jar Server.jar
Server.jar does not have a default Manifest property.
Someone occurred like this error, write main class like "Main-Class: test.server.ServerGUI" and hit the return key for make blank.
(It can't recognize that if there are no blank)
And if you have included external library, you can use "Class-Path: json_simple-1.1.jar" in Manifest.txt file.
Maybe error message is coming to you If you included external library without write "Class-Path"
like this Exception in thread main java.lang.noclassdeffounderror
[File name]
Write what ever you want.
[Class file]
If you want all class files, just write "*.class"
[External library or more add file]
Write file name.
If you progressed right way, you can see those outputs.
3. Execute "jar' file
CMD(명령 프롬포트)에 >java -jar Server.jar를 입력합니다.
Input >java -jar Server.jar on CMD
This post is end here
Thanks for watching. :)
I posting in my own way.
I worry about the breakdown in information delivery and I try to verify and post it surely.
Please let me know by reply or e-mail If there are some incorrect informations or something to fix.
It will really helpful to me.
E-mail : silent_lhr@naver.com
You don't need to sign in for press the heart button.
It helps me for post.