The right approach for using MIDI on Linux depends on which version of JACK is in use. The world divides into:

Systems using JACK 1, versions 0.124 or later On these systems, simply start JACK with the -X alsa_midi server argument. To support legacy control applications, the -X seq argument to the ALSA backend of JACK can also be used to get the exact same results.
All others Use a2jmidid to act as a bridge between ALSA MIDI and JACK. Do not use the -X seq or -X raw arguments—the timing and performance of these options is unacceptable.

Using a2jmidid

a2jmidid is an application that bridges between the system MIDI ports and JACK.

First it must be ensured that there is no ALSA sequencer support enabled in JACK. To check that, open QJackCtl's Setup window. Set Settings > MIDI Driver to none. Then uncheck the Misc > Enable ALSA Sequencer support option. Now restart the jack server before going on.

Check for a2jmidid availability

Next, check whether a2jmidid is already installed. After starting the JACK server, go to the command line and type:

a2jmidid -e

If a2jmidid does not exist, install it with the software manager of the Linux distribution in use and try again.

Check available MIDI ports

If JACK is correctly configured for MIDI, then the MIDI ports should appear in qjackctl under Connections > MIDI.

Making it automatic

Once it has been verified that the ports appear in JACK as expected, this can be made to happen whenever JACK is started: