Create a JAR from your code, using the Builder JA.
Use matlabcontrol, which is a 3rd party automation server:
Use the MatlabControl.java, which allows to run matlab code from java running within the matlab JRE. enter link description here
While the Builder JA is expensive and the options 2 and 3 might get you in truble with future matlab versions, using the matlab CLI is another possibility which probably does not cause any maintenance. For parameters and return, I would use a file. The main disadvantage is a new matlab session starting for each call, which needs some time.