{"id":118114,"date":"2018-09-06T08:39:44","date_gmt":"2018-09-06T00:39:44","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=118114"},"modified":"2018-08-29T09:40:55","modified_gmt":"2018-08-29T01:40:55","slug":"linux-ter-mkrun-jar","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/linux-ter-mkrun-jar.html","title":{"rendered":"\u5982\u4f55\u5728Linux\u7ec8\u7aef\u4e2d\u521b\u5efa\u548c\u6267\u884c.Jar\u6587\u4ef6"},"content":{"rendered":"\n\n\n
\u5bfc\u8bfb<\/td>\n\u5728\u672c\u6587\u4e2d\uff0c\u6211\u4eec\u5c06\u5c55\u793a\u5982\u4f55\u521b\u5efaJava\u5e94\u7528\u7a0b\u5e8f\u5e76\u5c06\u5176\u6346\u7ed1\u5230JAR\u6587\u4ef6\u4e2d\uff0c\u5e76\u6f14\u793a\u5982\u4f55\u4eceLinux\u7ec8\u7aef\u6267\u884c.jar\u6587\u4ef6\u3002<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n
\n

JAR<\/strong>\u00a0\uff08\u00a0Java ARchive<\/strong>\u00a0\uff09\u662f\u4e0e\u5e73\u53f0\u65e0\u5173\u7684\u6587\u4ef6\u683c\u5f0f\uff0c\u7528\u4e8e\u5c06\u8bb8\u591aJava\u7c7b\u6587\u4ef6\u4ee5\u53ca\u5173\u8054\u7684\u5143\u6570\u636e\u548c\u8d44\u6e90\uff08\u5982\u6587\u672c\uff0c\u56fe\u50cf\u7b49\uff09\u805a\u5408\u5230\u5355\u4e2a\u6587\u4ef6\u4e2d\u8fdb\u884c\u5206\u53d1\u3002<\/p>\n

\"\"<\/p>\n<\/div>\n

\n
\n

\u5b83\u5141\u8bb8Java\u8fd0\u884c\u65f6\u5728\u4e00\u4e2a\u5b58\u6863\u6587\u4ef6\u4e2d\u6709\u6548\u5730\u90e8\u7f72\u6574\u4e2a\u5e94\u7528\u7a0b\u5e8f\uff0c\u5e76\u63d0\u4f9b\u8bb8\u591a\u597d\u5904\uff0c\u4f8b\u5982\u5b89\u5168\u6027\uff0c\u53ef\u4ee5\u538b\u7f29\u5176\u5143\u7d20\uff0c\u7f29\u77ed\u4e0b\u8f7d\u65f6\u95f4\uff0c\u5141\u8bb8\u5c01\u88c5\u548c\u7248\u672c\u63a7\u5236\uff0c\u652f\u6301\u53ef\u79fb\u690d\u6027\u3002\u00a0\u5b83\u8fd8\u652f\u6301\u6269\u5c55\u5305\u88c5\u3002<\/p>\n

\u5728\u672c\u6587\u4e2d\uff0c\u6211\u4eec\u5c06\u5c55\u793a\u5982\u4f55\u521b\u5efa\u4e00\u4e2a\u7b80\u5355\u7684Java\u5e94\u7528\u7a0b\u5e8f\u5e76\u5c06\u5176\u6346\u7ed1\u5230\u4e00\u4e2aJAR<\/strong>\u6587\u4ef6\u4e2d\uff0c\u5e76\u6f14\u793a\u5982\u4f55\u4eceLinux\u7ec8\u7aef\u6267\u884c.jar\u6587\u4ef6\u3002<\/p>\n

\u4e3a\u6b64\uff0c\u5fc5\u987b\u5b89\u88c5java\u547d\u4ee4\u884c\u5de5\u5177<\/a>\u6765\u542f\u52a8Java\u5e94\u7528\u7a0b\u5e8f\uff0c\u5e76\u4f7f\u7528-jar\u6807\u5fd7\u6267\u884c\u5c01\u88c5\u5728JAR<\/strong>\u6587\u4ef6\u4e2d\u7684\u7a0b\u5e8f\u3002\u00a0\u4f7f\u7528\u6b64\u6807\u5fd7\u65f6\uff0c\u6307\u5b9a\u7684JAR\u6587\u4ef6\u662f\u6240\u6709\u7528\u6237\u7c7b\u7684\u6e90\uff0c\u5e76\u5ffd\u7565\u5176\u4ed6\u7c7b\u8def\u5f84\u8bbe\u7f6e\u3002<\/p>\n

\u5982\u4f55\u5728Linux\u4e2d\u521b\u5efaJAR\u6587\u4ef6<\/strong><\/div>\n

1.<\/strong>\u9996\u5148\uff0c\u4e3a\u4e00\u4e2a\u540d\u4e3aHowtoingApp<\/strong>\u7684\u5e94\u7528\u7a0b\u5e8f\u7f16\u5199\u4e00\u4e2a\u5e26\u6709main\u65b9\u6cd5\u7684\u7b80\u5355Java\u7c7b\uff0c\u7528\u4e8e\u6f14\u793a\u76ee\u7684\u3002<\/p>\n

$ vim <\/span>HowtoingApp<\/span>.<\/span>java<\/span><\/pre>\n

\u5c06\u4ee5\u4e0b\u4ee3\u7801\u590d\u5236\u5e76\u7c98\u8d34\u5230HowtoingApp.java<\/strong>\u6587\u4ef6\u4e2d\u3002<\/p>\n

public<\/span> class<\/span> HowtoingApp<\/span> {<\/span>\r\npublic<\/span> static<\/span> void<\/span> main<\/span>(<\/span>String<\/span>[]<\/span> args<\/span>){<\/span>\r\nSystem<\/span>.<\/span>out<\/span>.<\/span>println<\/span>(<\/span>\" <\/span>Just executed HowtoingApp!<\/span><\/strong> \"<\/span>);<\/span>\r\n}<\/span>\r\n}<\/span><\/pre>\n

\u4fdd\u5b58\u6587\u4ef6\u5e76\u5173\u95ed\u5b83\u3002<\/p>\n

2.<\/strong>\u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u9700\u8981\u4f7f\u7528javac<\/strong>\u548cjar<\/strong>\u5b9e\u7528\u7a0b\u5e8f\u5c06\u7c7b\u7f16\u8bd1\u5e76\u6253\u5305\u5230JAR<\/strong>\u6587\u4ef6\u4e2d\uff0c\u5982\u56fe\u6240\u793a\u3002<\/p>\n

$ javac <\/span>-<\/span>d <\/span>.<\/span> HowtoingApp<\/span>.<\/span>java\r\n$ ls\r\n$ jar cvf howtoingapp<\/span>.<\/span>jar <\/span>HowtoingApp<\/span>.<\/span>class<\/span>\r\n$ ls<\/span><\/pre>\n

3.<\/strong>\u521b\u5efahowtoingapp.jar\u540e<\/strong>\u00a0\uff0c\u73b0\u5728\u53ef\u4ee5\u4f7f\u7528java<\/strong>\u547d\u4ee4\u6267\u884c\u8be5\u6587\u4ef6\uff0c\u5982\u56fe\u6240\u793a\u3002<\/p>\n

$ java <\/span>-<\/span>jar howtoingapp<\/span>.<\/span>jar\r\n<\/span>no<\/span> main manifest attribute<\/span>,<\/span> in<\/span> howtoingapp<\/span>.<\/span>jar<\/span><\/strong>\r\n<\/pre>\n

\u4ece\u4e0a\u9762\u547d\u4ee4\u7684\u8f93\u51fa\uff0c\u6211\u4eec\u9047\u5230\u4e86\u4e00\u4e2a\u9519\u8bef\u3002\u00a0JVM<\/strong>\u00a0\uff08\u00a0Java\u865a\u62df\u673a<\/strong>\u00a0\uff09\u65e0\u6cd5\u627e\u5230\u6211\u4eec\u7684\u4e3b\u6e05\u5355\u5c5e\u6027<\/strong>\u00a0\uff0c\u56e0\u6b64\u65e0\u6cd5\u627e\u5230\u5305\u542bmain\u65b9\u6cd5\u7684\u4e3b\u7c7b\uff08public static void main\uff08String [] args\uff09\uff09\u3002<\/p>\n

JAR<\/strong>\u6587\u4ef6\u5e94\u8be5\u6709\u4e00\u4e2a\u6e05\u5355\uff0c\u5176\u4e2d\u5305\u542bMain-Class<\/strong>\u5f62\u5f0f\u7684\u4e00\u884c\uff1aclassname<\/strong>\u00a0\uff0c\u5b83\u5b9a\u4e49\u4e86\u5e26\u6709main\u65b9\u6cd5\u7684\u7c7b\uff0c\u8be5\u65b9\u6cd5\u7528\u4f5c\u5e94\u7528\u7a0b\u5e8f\u7684\u8d77\u70b9\u3002<\/p>\n

4.<\/strong>\u8981\u89e3\u51b3\u4e0a\u8ff0\u9519\u8bef\uff0c\u6211\u4eec\u9700\u8981\u66f4\u65b0JAR<\/strong>\u6587\u4ef6\u4ee5\u5305\u542b\u6e05\u5355\u5c5e\u6027<\/strong>\u548c\u4ee3\u7801\u3002\u00a0\u8ba9\u6211\u4eec\u521b\u5efa\u4e00\u4e2aMANIFEST.MF<\/strong>\u6587\u4ef6\u3002<\/p>\n

$ vim MANIFEST<\/span>.<\/span>MF<\/span><\/pre>\n

\u5c06\u4ee5<\/strong>\u4e0b\u884c\u590d\u5236\u5e76\u7c98\u8d34\u5230MANIFEST.MF<\/strong>\u6587\u4ef6\u4e2d\u3002<\/p>\n

Main<\/span>-<\/span>Class<\/span>:<\/span>  HowtoingApp<\/span><\/pre>\n

\u4fdd\u5b58\u6587\u4ef6\uff0c\u00a0\u7136\u540e<\/strong>\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u5c06\u6587\u4ef6MANIFEST.MF<\/strong>\u6dfb\u52a0\u5230howtoingapp.jar<\/strong>\u00a0\u3002<\/p>\n

$ jar cvmf MANIFEST<\/span>.<\/span>MF howtoingapp<\/span>.<\/span>jar <\/span>HowtoingApp<\/span>.<\/span>class<\/span><\/pre>\n

5.<\/strong>\u6700\u540e\uff0c\u5f53\u6211\u4eec\u518d\u6b21\u6267\u884cJAR<\/strong>\u6587\u4ef6\u65f6\uff0c\u5b83\u5e94\u8be5\u4ea7\u751f\u9884\u671f\u7684\u7ed3\u679c\uff0c\u5982\u8f93\u51fa\u4e2d\u6240\u793a\u3002<\/p>\n

$ java <\/span>-<\/span>jar howtoingapp<\/span>.<\/span>jar\r\n<\/span>Just<\/span> executed <\/span>HowtoingApp<\/span>!<\/span><\/strong>\r\n<\/pre>\n

\u6709\u5173\u66f4\u591a\u4fe1\u606f\uff0c\u8bf7\u53c2\u9605java<\/strong>\u00a0\uff0c\u00a0javac<\/strong>\u548cjar<\/strong>\u547d\u4ee4\u624b\u518c\u9875\u3002<\/p>\n

$ man java\r\n$ man javac\r\n$ man jar<\/span><\/pre>\n

\u53c2\u8003<\/strong>\u00a0\uff1a\u00a0JAR\u6587\u4ef6\u4e2d\u7684\u6253\u5305\u7a0b\u5e8f<\/a>\u00a0\u3002<\/p>\n

\u5c31\u8fd9\u6837\uff01\u00a0\u5728\u8fd9\u7bc7\u7b80\u77ed\u7684\u6587\u7ae0\u4e2d\uff0c\u6211\u4eec\u5df2\u7ecf\u89e3\u91ca\u4e86\u5982\u4f55\u521b\u5efa\u4e00\u4e2a\u7b80\u5355\u7684Java\u5e94\u7528\u7a0b\u5e8f\u5e76\u5c06\u5176\u6346\u7ed1\u5230\u4e00\u4e2aJAR\u6587\u4ef6\u4e2d\uff0c\u5e76\u6f14\u793a\u4e86\u5982\u4f55\u4ece\u7ec8\u7aef\u6267\u884c.jar<\/strong>\u6587\u4ef6\u3002\u00a0\u5982\u679c\u60a8\u6709\u4efb\u4f55\u95ee\u9898\u6216\u8865\u5145\u610f\u89c1\u8981\u5206\u4eab\uff0c\u8bf7\u4f7f\u7528\u4e0b\u9762\u7684\u53cd\u9988\u8868\u3002<\/p>\n<\/div>\n<\/div>\n

\n

\u539f\u6587\u6765\u81ea\uff1ahttps:\/\/www.howtoing.com\/create-and-execute-jar-file-in-linux<\/a><\/p>\n

\u672c\u6587\u5730\u5740\uff1ahttps:\/\/lrxjmw.cn\/linux-ter-mkrun-jar.html<\/a>\u7f16\u8f91\uff1a\u502a\u5bb6\u5174\uff0c\u5ba1\u6838\u5458\uff1a\u9004\u589e\u5b9d<\/span><\/p>\n<\/blockquote>\n","protected":false},"excerpt":{"rendered":"

\u5bfc\u8bfb \u5728\u672c\u6587\u4e2d\uff0c\u6211\u4eec\u5c06\u5c55\u793a\u5982\u4f55\u521b\u5efaJava\u5e94\u7528\u7a0b\u5e8f\u5e76\u5c06\u5176\u6346\u7ed1\u5230JAR\u6587\u4ef6\u4e2d\uff0c\u5e76\u6f14\u793a\u5982\u4f55\u4eceLinux\u7ec8\u7aef\u6267\u884c.j […]<\/p>\n","protected":false},"author":362,"featured_media":118127,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-118114","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/118114","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/users\/362"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=118114"}],"version-history":[{"count":8,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/118114\/revisions"}],"predecessor-version":[{"id":118450,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/118114\/revisions\/118450"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/118127"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=118114"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=118114"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=118114"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}