{"id":54,"date":"2016-04-29T18:41:24","date_gmt":"2016-04-29T10:41:24","guid":{"rendered":"http:\/\/www.tastestars.com\/?p=54"},"modified":"2016-04-29T18:44:15","modified_gmt":"2016-04-29T10:44:15","slug":"tip1","status":"publish","type":"post","link":"https:\/\/tastestars.com\/index.php\/2016\/04\/29\/tip1\/","title":{"rendered":"Linux\u8fd0\u884cjava\u7684jar\u6587\u4ef6\u63d0\u793a\u627e\u4e0d\u5230main\u51fd\u6570\u82e5\u5e72\u89e3\u51b3\u65b9\u6cd5"},"content":{"rendered":"<p>\n\t\u5199\u597d\u7684java project\u653e\u5230\u6811\u8393\u6d3e\u4e0a\u8fd0\u884c\u51fa\u73b0\u4e86\u9519\u8bef\uff0c\u663e\u793ano main manifest attribute\u6216\u8005\u663e\u793a\u6ca1\u6709\u627e\u5230main\u7684\u5165\u53e3\u3002\u8fd9\u91cc\u628a\u4e00\u4e9b\u6b65\u9aa4\u548c\u89e3\u51b3\u65b9\u6cd5\u505a\u4e00\u5b9a\u7684\u6574\u7406\u3002\n<\/p>\n<ol>\n<li>\n\t\t\u5199\u597d\u7684JAVA\u5de5\u7a0b\uff0c\u5bfc\u51fa\u6210.jar\u5f62\u5f0f\n\t<\/li>\n<li>\n\t\t\u653e\u5728linux\u7684\u6307\u5b9a\u7684\u6587\u4ef6\u5939\u4e2d\n\t<\/li>\n<li>\n\t\t\u901a\u8fc7\u8fd0\u884c java -jar app.jar \u5f97\u4ee5\u8fd0\u884c\n\t<\/li>\n<\/ol>\n<h3>\n\t\u9047\u5230\u7684\u95ee\u9898\uff1a\u62a5\u9519\uff1a&#8221;no main manifest attribute&#8221;\uff0cor &#8220;Could not find or load main class &#8221;<br \/>\n<\/h3>\n<p>\n\t\u6574\u7406\u7684\u89e3\u51b3\u65b9\u6848\uff1a\n<\/p>\n<ol>\n<li>\n\t\tjava -cp name.jar mainclassname \u8f93\u5165\u6307\u4ee4\n\t<\/li>\n<li>\n\t\t\u5728export\u6210\u4e3ajar\u6587\u4ef6\u7684\u65f6\u5019\uff0c\u5148\u4e0d\u8981\u6025\u7740finish\uff0c\u4e00\u76f4\u70b9next\uff0c\u6709\u4e00\u5904\u662f\u53ef\u4ee5\u586b\u5199main\u5165\u53e3\u7684<br \/>\n<img loading=\"lazy\" decoding=\"async\" data-attachment-id=\"55\" data-permalink=\"https:\/\/tastestars.com\/index.php\/2016\/04\/29\/tip1\/%e6%97%a0%e6%a0%87%e9%a2%98\/\" data-orig-file=\"https:\/\/tastestars.com\/wp-content\/uploads\/2016\/04\/\u65e0\u6807\u9898.jpg\" data-orig-size=\"563,693\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"\u65e0\u6807\u9898\" data-image-description=\"\" data-image-caption=\"\" data-medium-file=\"https:\/\/tastestars.com\/wp-content\/uploads\/2016\/04\/\u65e0\u6807\u9898-244x300.jpg\" data-large-file=\"https:\/\/tastestars.com\/wp-content\/uploads\/2016\/04\/\u65e0\u6807\u9898.jpg\" src=\"http:\/\/www.tastestars.com\/wp-content\/uploads\/2016\/04\/%E6%97%A0%E6%A0%87%E9%A2%98-244x300.jpg\" alt=\"\u65e0\u6807\u9898\" width=\"244\" height=\"300\" class=\"alignnone size-medium wp-image-55\" \/>\n\t<\/li>\n<li>\n\t\t\u5728export\u7684\u65f6\u5019\uff0c\u6709\u4e00\u4e2a\u9009\u9879\u662f\u5bfc\u51fa\u6210\u53ef\u8fd0\u884c\u7684jar\u6587\u4ef6\uff0c\u59d0\u59d0\u6211\u5c31\u662f\u8fd9\u4e48\u7b80\u5355\u7c97\u66b4\u7684\u89e3\u51b3\u7684&#8230;.<br \/>\n<img loading=\"lazy\" decoding=\"async\" data-attachment-id=\"56\" data-permalink=\"https:\/\/tastestars.com\/index.php\/2016\/04\/29\/tip1\/%e6%97%a0%e6%a0%87%e9%a2%982\/\" data-orig-file=\"https:\/\/tastestars.com\/wp-content\/uploads\/2016\/04\/\u65e0\u6807\u98982.png\" data-orig-size=\"525,550\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"\u65e0\u6807\u98982\" data-image-description=\"\" data-image-caption=\"\" data-medium-file=\"https:\/\/tastestars.com\/wp-content\/uploads\/2016\/04\/\u65e0\u6807\u98982-286x300.png\" data-large-file=\"https:\/\/tastestars.com\/wp-content\/uploads\/2016\/04\/\u65e0\u6807\u98982.png\" src=\"http:\/\/www.tastestars.com\/wp-content\/uploads\/2016\/04\/%E6%97%A0%E6%A0%87%E9%A2%982-286x300.png\" alt=\"\u65e0\u6807\u98982\" width=\"286\" height=\"300\" class=\"alignnone size-medium wp-image-56\" \/>\n\t<\/li>\n<li>\n\t\t\u8fd8\u6709\u539f\u56e0\u662fJava\u4eceMANIFEST.MF\u627e\u4e0d\u5230main\u51fd\u6570\u7684\u5165\u53e3\uff0c\u89e3\u51b3\u7684\u65b9\u6848\u662f\uff0c\u627e\u5230META-INF\/MANIFEST.MF\u8fd9\u4e2a\u6587\u4ef6\uff0c\u4e00\u822c\u7b2c\u4e00\u884c\u662f\u7248\u672c\u53f7\uff0c\u4f60\u5728\u6700\u540e\u4e00\u884c\u52a0\u4e0a\uff1aMain-Class: com.mypackage.MyClass\uff0c\u5176\u4e2d\uff0ccom.mypackage.MyClass\u5c31\u662f\u5305\u542b\u7740\u4f60main\u51fd\u6570\u7684\u7c7b\u3002\n\t<\/li>\n<li>\n<p>\n\t\t\t\u5bf9\u4e8eCLI\uff0cMaven\u6216\u8005\u662fAnt\u4e5f\u6709\u5404\u81ea\u7684\u89e3\u51b3\u65b9\u6cd5\n\t\t<\/p>\n<ul>\n<li>\n\t\t\t\tCLI\uff1a\u7528\u8fd9\u6761\u6307\u4ee4\uff1ajar cmvf META-INF\/MANIFEST.MF &lt;new-jar-filename&gt;.jar\n\t\t\t<\/li>\n<li>\n<p>\n\t\t\t\t\tMaven\uff1a\u5728pom.xml\u52a0\u4e0a\n\t\t\t\t<\/p>\n<pre>&lt;build&gt;\r\n      &lt;plugins&gt;\r\n        &lt;plugin&gt;\r\n          &lt;!-- Build an executable JAR --&gt;\r\n          &lt;groupId&gt;org.apache.maven.plugins&lt;\/groupId&gt;\r\n          &lt;artifactId&gt;maven-jar-plugin&lt;\/artifactId&gt;\r\n          &lt;version&gt;2.4&lt;\/version&gt;\r\n          &lt;configuration&gt;\r\n            &lt;archive&gt;\r\n              &lt;manifest&gt;\r\n                &lt;addClasspath&gt;true&lt;\/addClasspath&gt;\r\n                &lt;classpathPrefix&gt;lib\/&lt;\/classpathPrefix&gt;\r\n                &lt;mainClass&gt;com.mypackage.MyClass&lt;\/mainClass&gt;\r\n              &lt;\/manifest&gt;\r\n            &lt;\/archive&gt;\r\n          &lt;\/configuration&gt;\r\n        &lt;\/plugin&gt;\r\n      &lt;\/plugins&gt;\r\n    &lt;\/build&gt;<\/pre>\n<\/li>\n<li>\n<p>\n\t\t\t\t\tAnt:\u52a0\u4e0a\n\t\t\t\t<\/p>\n<pre>&lt;jar destfile=\"build\/main\/checksites.jar\"&gt;\r\n  &lt;fileset dir=\"build\/main\/classes\"\/&gt;\r\n  &lt;zipfileset includes=\"**\/*.class\" src=\"lib\/main\/some.jar\"\/&gt;\r\n  &lt;manifest&gt;\r\n    &lt;attribute name=\"Main-Class\" value=\"com.acme.checksites.Main\"\/&gt;\r\n  &lt;\/manifest&gt;\r\n&lt;\/jar&gt;<\/pre>\n<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<p>\n\t\u5e0c\u671b\u5927\u5bb6\u65e9\u65e5\u89e3\u51b3\u95ee\u9898\u5566\n<\/p>\n<p>\n\tReference:\n<\/p>\n<ul>\n<li>\n\t\thttp:\/\/stackoverflow.com\/questions\/9689793\/cant-execute-jar-file-no-main-manifest-attribute\n\t<\/li>\n<li>\n\t\thttp:\/\/stackoverflow.com\/questions\/19250966\/failing-to-run-jar-file-form-command-line-no-main-manifest-attribute\n\t<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5199\u597d\u7684java project\u653e\u5230\u6811\u8393\u6d3e\u4e0a\u8fd0\u884c\u51fa\u73b0\u4e86\u9519\u8bef\uff0c\u663e\u793ano main manifest attribu [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[10],"tags":[13,12,11],"class_list":["post-54","post","type-post","status-publish","format-standard","hentry","category-solvetheproblem","tag-jar","tag-java","tag-linux"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/s9Hs6X-tip1","_links":{"self":[{"href":"https:\/\/tastestars.com\/index.php\/wp-json\/wp\/v2\/posts\/54","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/tastestars.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/tastestars.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/tastestars.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/tastestars.com\/index.php\/wp-json\/wp\/v2\/comments?post=54"}],"version-history":[{"count":2,"href":"https:\/\/tastestars.com\/index.php\/wp-json\/wp\/v2\/posts\/54\/revisions"}],"predecessor-version":[{"id":58,"href":"https:\/\/tastestars.com\/index.php\/wp-json\/wp\/v2\/posts\/54\/revisions\/58"}],"wp:attachment":[{"href":"https:\/\/tastestars.com\/index.php\/wp-json\/wp\/v2\/media?parent=54"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/tastestars.com\/index.php\/wp-json\/wp\/v2\/categories?post=54"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/tastestars.com\/index.php\/wp-json\/wp\/v2\/tags?post=54"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}