Create new custom field of type TextField when plugin is installed

I want to configure a new custom field named FIELDNAME of type TextField when my plugin is installed. The functionality of the plugin will then update the content of the new field.

How can I programmatically configure a new custom field from the java code of the plugin?

You can hook into the plugin lifecycle here as documented here:

I would think that a good idea would be to store an AO table with configuration data such as your Custom Field ID. If your config table is empty, search for your customfield. If you can’t find it, create the field and persist the field ID in your AO table. You can use CustomFieldService (Atlassian Jira - Server 8.21.1 API) to create the field programmatically via your event handler in the lifecycle.