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"
    }
    
8
  • 1
    in case there is no API maybe parse somehow from here? archive.apache.org/dist/tomcat/tomcat-8
    – Ta Mu
    Feb 4, 2018 at 15:35
  • Thank you @PeterMuryshkin That could be an option indeed. I will do some tests.
    – 030
    Feb 4, 2018 at 15:36
  • There's a generic GitHub Release REST API: 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. Feb 4, 2018 at 17:45
  • @DanCornilescu Thank you for the suggestion. I have added the output to the question.
    – 030
    Feb 4, 2018 at 17:54
  • 1
    I would like to always create a new package and later decide whether we will use it.
    – 030
    Feb 4, 2018 at 19:59

5 Answers 5

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/

1
  • 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, 2023 at 15:09
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.

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
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

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.