Maven Kullanarak Tüm Bağımlılıkları içeren Java Projesi Nasıl Oluşturulur? maven kaynakları, maven bağımlılığı ve maven kavanozu Eklentileri
Yayınlanan: 2016-11-26
Kurumsal düzeyde Java Projesi üzerinde mi çalışıyorsunuz? Tüm bağımlılıkları güncel tutmak için Maven POM.xml dosyasını mı kullanıyorsunuz? Projenizde src folder , resources folder , lib folder vb. var mı? Peki ya bu projeyi 3. taraf istemciye dağıtmak isterseniz? Başka bağımsız donanım var mı?
Java Projenizin yürütülebilir dosyasını Maven Eklentileri ile oluşturmanın ve oluşturmanın basit bir yolu var. Aşağıdaki örnek Java Projesine bir göz atın.

Hadi başlayalım ve projenin tüm bölümlerini açıklamama izin verin:
-
CrunchifyMavenBuildPluginsbir Maven Projesidir. Java projeniz varsa ve bunu Maven projesine dönüştürmek istiyorsanız, bu öğreticiyi izleyin. - İki klasörümüz var.
srcveresources. -
resourcesklasörünün içinde, yürütülebilir bir kabuk komut dosyası içerenScriptsadlı bir klasörümüz var. -
CrunchifyMain.java, içindemain(String args[])yöntemi bulunan bir ana başlangıç noktasıdır. -
pom.xmldosyasına dahil edilen tüm bağımlılıklarla yürütülebilir .jar projesi oluşturacak Maven Eklentilerini ekleyeceğiz.
Aşama 1
pom.xml dosyanızı açın ve aşağıdakileri <build> altına ekleyin. Not: Aşağıya 3 eklenti ekledim.
-
maven-resources-plugin: Kaynaklar Eklentisi, proje kaynaklarının çıktı dizinine kopyalanmasını yönetir. Ana kaynaklar, ana kaynak koduyla ilişkili kaynaklardır. -
maven-dependency-plugin:Bağımlılık eklentisi, yapıtları manipüle etme yeteneği sağlar. Yapıtları yerel veya uzak depolardan belirli bir konuma kopyalayabilir ve/veya paketten çıkarabilir. -
maven-jar-plugin:Bu eklenti, kavanoz oluşturma ve imzalama yeteneği sağlar.
İşte tam bir pom.xml dosyası. Temelde <build> etiketi ile ilgileneceksiniz.
Lütfen aşağıdaki ihtiyacınıza göre dizin konumunu, dosya adını ve yolunu güncelleyin.
|
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 > |
Adım 2
Project -> Run As -> Maven Build


Aşama 3
“ clean install ” argümanını sağlayın

4. Adım
Sonuç böyle bir şey görmelisiniz.

Adım 5
Şimdi bunun altındaki her şeyi kontrol etmek için /target/Crunchify klasörünü kontrol edin.

Adım-6
Şimdi projenizi aşağıdaki $bash> java -jar Crunchify.jar komutuyla çalıştırın.
Proje oluşturma konusunda herhangi bir sorununuz varsa bana bildirin. Keyifli ve Mutlu Kodlamalar.
