كيفية بناء مشروع Java بما في ذلك جميع التبعيات باستخدام Maven؟ الموارد المخضرمة ، والاعتماد المخضرم ، والإضافات المخضرمة
نشرت: 2016-11-26
هل تعمل على مشروع جافا على مستوى المؤسسة؟ هل تستخدم ملف Maven POM.xml
لتحديث كل التبعيات؟ في مشروعك ، هل لديك src folder
resources folder
lib folder
، وما إلى ذلك؟ حسنًا ، ماذا لو كنت تريد نشر هذا المشروع لعميل طرف ثالث؟ أي أجهزة أخرى قائمة بذاتها؟
حسنًا ، هناك طريقة بسيطة لبناء وإنشاء ملف تنفيذي لمشروع Java الخاص بك باستخدام Maven Plugins. ألق نظرة على نموذج Java Project أدناه.

لنبدأ واسمحوا لي أن أشرح جميع أجزاء المشروع:
-
CrunchifyMavenBuildPlugins
هو مشروع مخضرم. إذا كان لديك مشروع Java وأردت تحويله إلى مشروع Maven ، فاتبع هذا البرنامج التعليمي. - لدينا مجلدين.
src
resources.
- داخل مجلد
resources
لدينا مجلد يسمىScripts
والذي يحتوي على ملف نصي شل قابل للتنفيذ. -
CrunchifyMain.java
هي نقطة بداية رئيسية بها طريقةmain(String args[])
بداخلها. -
pom.xml
الذي سنضيف فيه ملحقات Maven التي ستنشئ مشروعًا .jar قابل للتنفيذ مع جميع التبعيات المضمنة.
الخطوة 1
افتح ملف pom.xml
وأضف ما يلي ضمن <build>
. ملاحظة: لقد أضفت 3 ملحقات أدناه.
-
maven-resources-plugin
: يقوم البرنامج المساعد Resources بمعالجة نسخ موارد المشروع إلى دليل المخرجات. الموارد الرئيسية هي الموارد المرتبطة بكود المصدر الرئيسي. -
maven-dependency-plugin:
يوفر ملحق التبعية القدرة على معالجة القطع الأثرية. يمكنه نسخ و / أو تفريغ القطع الأثرية من المستودعات المحلية أو البعيدة إلى موقع محدد. -
maven-jar-plugin:
يوفر هذا البرنامج المساعد القدرة على إنشاء برطمانات وتوقيعها.
هذا ملف pom.xml كامل. سوف تكون مهتمًا بشكل أساسي بعلامة <build>.
يرجى تحديث موقع الدليل واسم الملف والمسار حسب حاجتك أدناه.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 |
< project xmlns = "http://maven.apache.org/POM/4.0.0" xmlns : xsi = "http://www.w3.org/2001/XMLSchema-instance" xsi : schemaLocation = "http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" > < modelVersion > 4.0.0 < / modelVersion > < groupId > CrunchifyMavenBuildPlugins < / groupId > < artifactId > CrunchifyMavenBuildPlugins < / artifactId > < version > 0.0.1 - SNAPSHOT < / version > < name > CrunchifyMavenBuildPlugins < / name > < properties > < project . build . sourceEncoding > UTF - 8 < / project . build . sourceEncoding > < / properties > < dependencies > < dependency > < groupId > log4j < / groupId > < artifactId > log4j < / artifactId > < version > 2.15.0 < / version > < / dependency > < dependency > < groupId > com . googlecode . json - simple < / groupId > < artifactId > json - simple < / artifactId > < version > 1.1 < / version > < / dependency > < dependency > < groupId > axis < / groupId > < artifactId > axis < / artifactId > < version > 1.4 < / version > < / dependency > < dependency > < groupId > commons - beanutils < / groupId > < artifactId > commons - beanutils < / artifactId > < version > 1.8.3 < / version > < / dependency > < dependency > < groupId > commons - collections < / groupId > < artifactId > commons - collections < / artifactId > < version > 3.2.1 < / version > < / dependency > < dependency > < groupId > commons - configuration < / groupId > < artifactId > commons - configuration < / artifactId > < version > 1.10 < / version > < / dependency > < dependency > < groupId > commons - io < / groupId > < artifactId > commons - io < / artifactId > < version > 2.4 < / version > < / dependency > < dependency > < groupId > javax . mail < / groupId > < artifactId > mail < / artifactId > < version > 1.4.7 < / version > < / dependency > < dependency > < groupId > javax . servlet < / groupId > < artifactId > servlet - api < / artifactId > < version > 2.5 < / version > < / dependency > < dependency > < groupId > org . json < / groupId > < artifactId > json < / artifactId > < version > 20140107 < / version > < / dependency > < dependency > < groupId > axis < / groupId > < artifactId > axis - saaj < / artifactId > < version > 1.4 < / version > < / dependency > < dependency > < groupId > wsdl4j < / groupId > < artifactId > wsdl4j < / artifactId > < version > 1.6.3 < / version > < / dependency > < dependency > < groupId > com . google . zxing < / groupId > < artifactId > core < / artifactId > < version > 2.0 < / version > < / dependency > < / dependencies > < build > < pluginManagement > < plugins > < plugin > < groupId > org . apache . maven . plugins < / groupId > < artifactId > maven - compiler - plugin < / artifactId > < version > 2.3.1 < / version > < configuration > < source > 1.7 < / source > < target > 1.7 < / target > < / configuration > < / plugin > < / plugins > < / pluginManagement > < plugins > < plugin > < artifactId > maven - resources - plugin < / artifactId > < version > 2.6 < / version > < executions > < execution > < id > copy - resources < / id > < phase > validate < / phase > < goals > < goal > copy - resources < / goal > < / goals > < configuration > < outputDirectory > $ { basedir } / target / Crunchify < / outputDirectory > < resources > < resource > < directory > resources < / directory > < filtering > true < / filtering > < / resource > < / resources > < / configuration > < / execution > < / executions > < / plugin > < plugin > < groupId > org . apache . maven . plugins < / groupId > < artifactId > maven - dependency - plugin < / artifactId > < executions > < execution > < id > copy - dependencies < / id > < phase > prepare - package < / phase > < goals > < goal > copy - dependencies < / goal > < / goals > < configuration > < outputDirectory > $ { project . build . directory } / Crunchify / lib < / outputDirectory > < overWriteReleases > false < / overWriteReleases > < overWriteSnapshots > false < / overWriteSnapshots > < overWriteIfNewer > true < / overWriteIfNewer > < / configuration > < / execution > < / executions > < / plugin > < plugin > < groupId > org . apache . maven . plugins < / groupId > < artifactId > maven - jar - plugin < / artifactId > < configuration > < archive > < manifest > < addClasspath > true < / addClasspath > < classpathPrefix > lib / < / classpathPrefix > < mainClass > com . crunchify . tutorial . CrunchifyMain < / mainClass > < / manifest > < manifestEntries > < Class - Path > . < / Class - Path > < / manifestEntries > < / archive > < finalName > Crunchify / Crunchify < / finalName > < / configuration > < / plugin > < / plugins > < / build > < / project > |
الخطوة 2
انقر بزر الماوس الأيمن على Project -> Run As -> Maven Build


الخطوه 3
تقديم حجة " clean install
"

الخطوة 4
يجب أن ترى نتيجة شيء من هذا القبيل.

الخطوة 5
تحقق الآن من مجلد المجلد /target/Crunchify
للتحقق من كل شيء تحته.

الخطوة 6
الآن فقط قم بتشغيل مشروعك باستخدام الأمر التالي $bash> java -jar Crunchify.jar
اسمحوا لي أن أعرف إذا كان لديك أي مشكلة في بناء مشروع. استمتع وسعد الترميز.