4

If one checks the Tomcat homepage then one could see some versions, but not only the latest. Off course I could parse the website and find the version, but I am looking for a Tomcat API that shows the latest version to prevent that I have to create a script that is error prone.

Why?

I would like to automate the update of our internal tomcat packages. At the moment someone is checking the latest version and create the debian package manually, but I want to see that that is automated.

What has been tried?

  • The github mirror does not show the latest version https://github.com/apache/tomcat/releases
  • The official tomcat html could be parsed, but that does not seem to be the easiest solution
  • curl https://api.github.com/repos/apache/tomcat/releases/latest returns:

    {
      "message": "Not Found",
      "documentation_url": "https://developer.github.com/v3/repos/releases/#get-the-latest-release"
    }
    
030
  • 13,235
  • 16
  • 74
  • 173
  • 1
    in case there is no API maybe parse somehow from here? https://archive.apache.org/dist/tomcat/tomcat-8/ – Ta Mu Feb 04 '18 at 15:35
  • Thank you @PeterMuryshkin That could be an option indeed. I will do some tests. – 030 Feb 04 '18 at 15:36
  • There's a generic GitHub Release REST API: https://developer.github.com/v3/repos/releases/ But I didn't use it, no clue if it can be used for your case. Worth a try maybe. – Dan Cornilescu Feb 04 '18 at 17:45
  • @DanCornilescu Thank you for the suggestion. I have added the output to the question. – 030 Feb 04 '18 at 17:54
  • Why do you always want the latest version? Wouldn't you want to read over the changelog and see if you want to upgrade, whether it will break anything, and whether there are useful new features for you? – Xiong Chiamiov Feb 04 '18 at 19:49
  • 1
    I would like to always create a new package and later decide whether we will use it. – 030 Feb 04 '18 at 19:59
  • @030 Using the GitHub rest API would be the easiest. It looks like the releases page is up to date. They have v9.0.5 listed 19 days ago. The Tomcat official page seems to have v9.0.5 as the latest as well. So it looks like they do keep the mirror up to date. I actually have code for doing this as I use it for parsing the latest version on some other projects. I could share. Is there a reason you see that the GitHub releases page won't work? – BoomShadow Feb 25 '18 at 18:38
  • I am looking for the latest stable version. The releases page contains also unstable versions, e.g. TOMCAT_9_0_0_m27 – 030 Feb 25 '18 at 18:56

5 Answers5

4

Get the latest version of Tomcat:

$ curl -s 'https://api.github.com/repos/apache/tomcat/tags?per_page=1' | jq -r .[].name
9.0.20

Get the latest version of Tomcat 9:

$ curl -s 'https://api.github.com/repos/apache/tomcat/tags?per_page=100' | jq -r '.[] | .name' | sort -V | grep ^9 | tail -n 1
9.0.20

Get the latest version of Tomcat 8.5:

$ curl -s 'https://api.github.com/repos/apache/tomcat/tags?per_page=100' | jq -r '.[] | .name' | sort -V | grep ^8.5 | tail -n 1
8.5.41

Get the latest version of Tomcat 7:

$ curl -s 'https://api.github.com/repos/apache/tomcat/tags?per_page=100' | jq -r '.[] | .name' | sort -V | grep ^7 | tail -n 1
7.0.94

These all currently match the latest versions listed at http://tomcat.apache.org/

bmaupin
  • 155
  • 5
  • Just a note. Github limits the number of tags pr page to 100 and sorts them by name and tomcat has a lot of releases, thus I was able to find tomcat8.5.97 (newest) on page 3. Use the page= parameter to iterate. – Folkmann Dec 14 '23 at 15:09
0

Using Powershell's Invoke-WebRequest cmdlet:

$Links=$(Invoke-WebRequest -Uri 'https://tomcat.apache.org/download-80.cgi' | Select-Object -ExpandProperty Links)
$($Links | Where-Object -Property href -Match '#8.5.[0-9]+').href.substring(1)

Returns:

8.5.54

This command works on Windows/Linux/MACOS

Hames
  • 109
  • 2
0

I created a script to download, unzip, install tomcat 9.0.latest

sample.war and deploy

curl <>/sample/

Here is the information that I assume you're wanting, below:

# PATHS #
# DO NOT END DIRECTORY PATHS WITH \ PLEASE!
$WORKING_DRIVE="C:"
$DOWNLOADS_DIRECTORY="${WORKING_DRIVE}\DOWNLOADS"
$TOMCAT_VERSION_NUMBER="9"
$TOMCAT_SUB_VERSION_NUMBER="0"
$TOMCAT_DIRECTORY="${WORKING_DRIVE}\Tomcat${TOMCAT_VERSION_NUMBER}${TOMCAT_SUB_VERSION_NUMBER}"

Script will automatically download the tomcat file if one is not found in folder

$Links=$(Invoke-WebRequest -Uri "https://tomcat.apache.org/download-${TOMCAT_VERSION_NUMBER}${TOMCAT_SUB_VERSION_NUMBER}.cgi" | Select-Object -ExpandProperty Links) $TOMCAT9_LATEST_VERSION=$($Links | Where-Object -Property href -Match "#${TOMCAT_VERSION_NUMBER}.${TOMCAT_SUB_VERSION_NUMBER}.[0-9]+").href.substring(1) $TOMCAT9_LATEST_ZIP_FILE="apache-tomcat-${TOMCAT9_LATEST_VERSION}-windows-x64.zip" $TOMCAT_DOWNLOAD_URL="https://dlcdn.apache.org/tomcat/tomcat-${TOMCAT_VERSION_NUMBER}/v${TOMCAT9_LATEST_VERSION}/bin/${TOMCAT9_LATEST_ZIP_FILE}" Write-Output "Downloading latest Tomcat ${TOMCAT9_LATEST_VERSION} file:`n${TOMCAT_DOWNLOAD_URL}" Invoke-WebRequest -URI ${TOMCAT_DOWNLOAD_URL} -OutFile "${DOWNLOADS_DIRECTORY}${TOMCAT9_LATEST_ZIP_FILE}"

https://tomcat.apache.org/download-90.cgi

https://dlcdn.apache.org/tomcat/tomcat-9/v9.0.74/bin/apache-tomcat-9.0.74-windows-x64.zip

^ 12MB

#################################

POWERSHELL OUTPUT:

Downloading latest Tomcat 9.0.74 file: https://dlcdn.apache.org/tomcat/tomcat-9/v9.0.74/bin/apache-tomcat-9.0.74-windows-x64.zip

0

Indeed, releases don't appear to have been registered on GitHub, the releases list returned by the REST is empty, most likely explaining the 404 returned for releases/latest:

curl -i https://api.github.com/repos/apache/tomcat/releases
HTTP/1.1 200 OK
...

[

]

There are however tags registered, including some apparently mapping to the 9.0.X versions:

curl -i https://api.github.com/repos/apache/tomcat/tags | & grep '"name"'
    "name": "TONCAT_9_0_0_M23",
    "name": "TOMCAT_9_0_5",
    "name": "TOMCAT_9_0_4",
    "name": "TOMCAT_9_0_3",
    "name": "TOMCAT_9_0_2",
    "name": "TOMCAT_9_0_1",
    "name": "TOMCAT_9_0_0",
    "name": "TOMCAT_9_0_0_m27",
    ...
    "name": "TOMCAT_9_0_0_M6",

Example of a tag info, which might be of use:

  {
    "name": "TOMCAT_9_0_5",
    "zipball_url": "https://api.github.com/repos/apache/tomcat/zipball/TOMCAT_9_0_5",
    "tarball_url": "https://api.github.com/repos/apache/tomcat/tarball/TOMCAT_9_0_5",
    "commit": {
      "sha": "e0fdefed3d9e2a4dbfd36a5a79e75e0eadaa201d",
      "url": "https://api.github.com/repos/apache/tomcat/commits/e0fdefed3d9e2a4dbfd36a5a79e75e0eadaa201d"
    }
  },

But the info doesn't appear consistent with the info on the Tomcat homepage you referenced:

  • the 9.0.5 version isn't listed as released on the homepage
  • only 9.X versions show up, older ones don't

So I'm not sure if this is helpful.

Dan Cornilescu
  • 6,730
  • 2
  • 19
  • 44
0

Today 8.5.49 was returned as a 'stable' version, while it should have been 8.5.47. The following:

URL=https://tomcat.apache.org/download-80.cgi
curl -s $URL  | grep "8\.5\.[0-9]\+</a>" | sed -e 's|.*>\(.*\)<.*|\1|g'

returns:

8.5.47
030
  • 13,235
  • 16
  • 74
  • 173