Better way to add custom Java classes to Matlab?
I can create Java classes, compile them into *.class files and may be pack them into *.jar files and place anywhere.
But I don't like editing of javaclasspath.txt, because it is systemwide and located somewhere in Matlab directory.
Also I don't like issuing 'javaaddpath' command and similar, because it will require doing this each time.
I would like to attach some jars or class-files to directory. For example, just put them there. Or I would like to add ajr files or classpath entries with Set Path menu of Matlab GUI.
Fortunately, it is said, that "You can also put the JAR file on the MATLAB path." in manual.
But unfortunately, I can activate this. Adding path entries feature does not see jar files and if I add java classpath entry, it does not work.
Is it possible to add classpath entries to Matlab in my suggested way?
You can place the javaaddpath(...) call in a startup.m file that you create and is placed anywhere on your MATLAB path, such as your default start directory.
You will not need to call javaaddpath each time you launch MATLAB because a startup.m on your path is automatically called every time.
It will not be systemwide unless you happen to place the startup.m in one of the MATLAB system paths.
see doc startup
Another variation is to use the -r flag and specify an m-file to run on launch that can be named anything. You can modify the Windows shortcut to use this flag, or create an alias if using Linux.
Follow the "Specifying Startup Options in the MATLAB Startup File" link from the doc startup page mentioned above for more info.
Using a startup file or function is the proper way to handle it - as explained in the other answer. To see a better way to add jar files dynamically than using javaaddpath, refer to https://stackoverflow.com/a/21489260/2043349.