how to get version from jar file in jenkins
<p>I created a job in jenkins with maven for my java project. My jar name is 
artifactId-version.jar and I am deploying this jar to artifactory server. I 
have 5 to 6 jar files like this which are deployed to artifact.</p>

<p>My build command is </p>

<pre><code>clean install -Dversion=$BUILD_NUMBER -Denv=r -DskipITs
</code></pre>

<p>so that my jar is like example-r-23.jar and under execute shell I have written as </p>

<pre><code>echo $BUILD_NUMBER &gt; src/sonarCharts/latest.txt 
</code></pre>

<p>and sending this file to Artifactory. I am using curl command to read the
value in latest.txt file and downloading jar file.I am downloading them from 
my code through shell script (using wget command  like wget --user  --
password  <a href="http://artifactory/example-1.0.jar" rel="nofollow">http://artifactory/example-1.0.jar</a>). </p>

<p>This process repeats for every release. Once i deliver my code to production, 
i am changing this version to 2.0 and now jar file will be like example-
2.0.jar and deploying it to artifact.I need to change my script file every 
time jar version is changed.</p>

<pre><code>&lt;artifactId&gt;rabbitMQHandler&lt;/artifactId&gt;
&lt;version&gt;1.0&lt;/version&gt;
&lt;name&gt;rabbitMQHandler&lt;/name&gt;
&lt;url&gt;http://maven.apache.org&lt;/url&gt;
</code></pre>

<p>I followed one procedure by overwriting the version with Build number and 
passing it from command line as </p>

<pre><code>mvn clean install -Dversion=$BUILD_NUMBER --- to build
and i am sending this BUILD_NUMBER to one txt file as
echo $BUILD_NUMBER &gt; latest.txt --- sending this to artifactory
</code></pre>

<p>and placing that file in artifactory. I am reading that txt file through shell<br>
script using curl and i am using that number in wget command.
I feel my way of doing is not correct and is there any other way of doing it.</p>