So aatk's answer applies the sidecar pattern to solve the issue, by running the configtxgen on the side of the actual application. However you can do this from within the application itself.
A channel configuration transaction that is generated with configtxgen
is a file containing a protobuf of the common.Envelope message. There is support for protobuf in Java, and the Envelope message has been compiled to Java thanks to the Fabric Java SDK. We can piggyback on the SDK to create the objects and get the ByteArray to create the ChannelConfiguration object that will be used to create a channel. This method doesn't require a configtx.yaml
file at all, so you will need to keep track of organizations and their MSP IDs in the app.