{"id":1792,"date":"2013-08-20T12:04:46","date_gmt":"2013-08-20T04:04:46","guid":{"rendered":"https:\/\/blog.vimge.com\/?p=1792"},"modified":"2017-08-20T12:53:45","modified_gmt":"2017-08-20T04:53:45","slug":"java-package-jar","status":"publish","type":"post","link":"https:\/\/blog.vimge.com\/archives\/java\/java-package-jar.html","title":{"rendered":"JAVA\u9879\u76ee\u6253\u5305jar\u6587\u4ef6\u6267\u884c"},"content":{"rendered":"

Java\u9879\u76ee\u5f00\u53d1\u5b8c\u540e\u4e00\u822c\u90fd\u9700\u8981\u6253\u5305\u6210Jar\u6587\u4ef6\u5e03\u7f72\u5230\u751f\u4ea7\u73af\u5883\uff0c\u901a\u5e38\u6211\u4eec\u4f7f\u7528Eclipse\u81ea\u5e26\u7684 Export \u529f\u80fd\u5c31\u591f\u7528\u4e86\uff0c\u4eca\u5929\u804a\u804a Export \u51e0\u4e2a\u9009\u9879\u6709\u6bd4\u8f83\u7591\u60d1\u7684\u5730\u65b9\u3002<\/p>\n

\u9f20\u6807\u53f3\u952e\u9009\u62e9\u9879\u76ee\uff0c\u70b9\u51fb Export \u9879\u9009\u62e9Java\u7c7b\u522b\u5c55\u5f00\uff0c\u8fd9\u4e2a\u65f6\u5019\u5f88\u591a\u540c\u5b66\u4f1a\u72af\u96be\uff0c\u8001\u5e08\u6211\u662f\u9009\u62e9 JAR file \u8fd8\u662f\u9009\u62e9 Runnable JAR file \u5462? \u4e24\u4e2a\u9009\u9879\u90fd\u53ef\u4ee5\u751f\u6210JAR\u6587\u4ef6\uff0c\u4f46\u7a0d\u6709\u4e0d\u540c\uff0c\u8fd9\u91cc\u7b80\u5355\u89e3\u91ca\u4e00\u4e0b<\/p>\n

JAR file \u9879\u7b80\u5355\u5730\u5c06\u7f16\u8bd1\u597d\u7684 .class \u6587\u4ef6\u6253\u5305\uff0c\u8fd0\u884c\u7684\u65f6\u5019\u6211\u4eec\u4f7f\u7528 java -cp \u8981\u6267\u884c\u7684\u7c7b\u540d<\/strong><\/span> \u547d\u4ee4\uff0c -cp \u53c2\u6570\u6307\u5b9a\u5305\u540d\u548c\u8981\u6267\u884c\u7684\u7c7b\u540d\uff08\u9700\u8981\u5305\u542b\u5b8c\u6574\u7684\u547d\u4ee4\u7a7a\u95f4\uff09\uff0c\u5982\u679c\u6709\u4f9d\u8d56\u7b2c3\u65b9\u5305\uff0c\u8fd8\u9700\u8981\u5728 -cp \u53c2\u6570\u91cc\u6307\u5b9a\u4f9d\u8d56\u5305\u540d<\/em><\/p>\n

Runnable JAR file \u5219\u5728\u751f\u6210\u7684\u65f6\u5019\u6307\u5b9a\u6267\u884c\u7684\u65f6\u5019\u5148\u6267\u884c\u54ea\u4e2a\u7c7b\uff0c\u8fd0\u884c\u7684\u65f6\u5019\u4f7f\u7528\u547d\u4ee4\u683c\u5f0f \u00a0java -jar \u5305\u540d<\/strong><\/span> \uff0c\u5177\u4f53\u662f\u7531\u4e8eMANIFEST.MF\u6587\u4ef6\u6307\u5b9a\u4e86\u76f8\u5173\u53c2\u6570\uff0c\u6240\u4ee5\u6267\u884c\u7684\u65f6\u5019\u4e0d\u5fc5\u5173\u5fc3\u9996\u5148\u8981\u6267\u884c\u54ea\u4e2a\u7c7b\uff0c\u53e6\u5916\u5728\u5bfc\u51fa\u7684\u65f6\u5019\u53ef\u4ee5\u6307\u5b9a\u8981\u5305\u542b\u7684\u7b2c3\u65b9\u5305\u6587\u4ef6\uff0c\u53ef\u4ee5\u5c06\u7b2c3\u65b9\u5305\u6253\u5305\u5728\u4e00\u8d77\u3002<\/em><\/p><\/blockquote>\n


\n\u6253\u5305\u7b2c3\u65b9\u5305\u7684\u65f6\u5019Eclipse\u63d0\u4f9b\u51e0\u4e2a\u9009\u9879
\nExtract required libraries into generated JAR\uff1a\u5c06\u9700\u8981\u7528\u5230\u7684.class\u6587\u4ef6\u63d0\u53d6\u51fa\u6765
\npackage equired libraries into generated JAR\uff1a\u5c06\u9700\u8981\u7684jara\u5305\u6253\u8fdb\u4e00\u4e2a\u5305\u91cc
\nCopy required libraries into a sub-folder next to the generated jar\uff1a\u5c06\u9700\u8981\u7684\u5e93\u62f7\u8d1d\u5230\u4e00\u4e2a\u5b50\u6587\u4ef6\u5939\u5e76\u653e\u5728\u751f\u6210\u7684 jar \u6587\u4ef6\u65c1\u8fb9<\/p>\n

\u4e00\u822c\u9009\u7b2c1\u9879\u6216\u7b2c2\u9879\u6bd4\u8f83\u65b9\u4fbf\uff0c\u5177\u4f53\u6539\u5929\u518d\u505a\u7814\u7a76<\/p>\n

\u81f3\u6b64\u53ef\u89c1\uff0cJAR file \u901a\u5e38\u9002\u7528\u4e8e\u9879\u76ee\u751f\u6210\u6a21\u5757\u5305\uff0c\u4f9b\u5176\u4ed6\u9879\u76ee\u4f7f\u7528\uff0c\u800c Runnable JAR file \u9002\u7528\u4e8e\u9879\u76ee\u751f\u6210\u5e03\u7f72<\/p>\n

\u53e6\u5916\uff0c\u751f\u6210Runnable JAR file \u7684\u65f6\u5019\u9879\u76ee\u901a\u5e38\u4f1a\u6709\u591a\u4e2a\u5165\u53e3 main \u65b9\u6cd5\uff0c\u800c\u6253\u5305\u7684\u65f6\u5019\u53ea\u80fd\u6307\u5b9a\u4e00\u4e2a\u9ed8\u8ba4\u5165\u53e3\u7c7b\uff0c\u8fd9\u4e2a\u65f6\u5019\u5982\u679c\u6211\u4eec\u8981\u8fd0\u884c\u4e0d\u540c\u7684\u5165\u53e3\u7c7b\u7684\u8bdd\u540c\u6837\u53ef\u4ee5\u4f7f\u7528 java -cp \u547d\u4ee4\u6267\u884c\uff0c\u7a0d\u4e0d\u4e00\u6837\u7684\u5730\u65b9\u662f -cp \u53c2\u6570\u4e3a\u8981\u6267\u884c\u7684\u5305\u540d\uff0c\u53e6\u5916\u9700\u8981\u6307\u5b9a\u8981\u8fd0\u884c\u7684\u5165\u53e3\u5b8c\u6574\u7c7b\u540d\uff0c\u5982\u4e0b<\/p>\n

java -jar hello.jar \u00a0 \u6267\u884c\u9ed8\u8ba4\u5165\u53e3\u7c7b
\njava -cp hello.jar com.clear.activemq2.JMSConsumerListener \u00a0\u6267\u884c\u6307\u5b9a\u5165\u53e3\u7c7b<\/span><\/em><\/p><\/blockquote>\n","protected":false},"excerpt":{"rendered":"

Java\u9879\u76ee\u5f00\u53d1\u5b8c\u540e\u4e00\u822c\u90fd\u9700\u8981\u6253\u5305\u6210Jar\u6587\u4ef6\u5e03\u7f72\u5230\u751f\u4ea7\u73af\u5883\uff0c\u901a\u5e38\u6211\u4eec\u4f7f\u7528Eclipse\u81ea\u5e26\u7684 Export […]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[161],"tags":[163,162,164],"_links":{"self":[{"href":"https:\/\/blog.vimge.com\/wp-json\/wp\/v2\/posts\/1792"}],"collection":[{"href":"https:\/\/blog.vimge.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.vimge.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.vimge.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.vimge.com\/wp-json\/wp\/v2\/comments?post=1792"}],"version-history":[{"count":4,"href":"https:\/\/blog.vimge.com\/wp-json\/wp\/v2\/posts\/1792\/revisions"}],"predecessor-version":[{"id":1796,"href":"https:\/\/blog.vimge.com\/wp-json\/wp\/v2\/posts\/1792\/revisions\/1796"}],"wp:attachment":[{"href":"https:\/\/blog.vimge.com\/wp-json\/wp\/v2\/media?parent=1792"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.vimge.com\/wp-json\/wp\/v2\/categories?post=1792"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.vimge.com\/wp-json\/wp\/v2\/tags?post=1792"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}