<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	
	>
<channel>
	<title>
	Comments on: Java class access pitfalls	</title>
	<atom:link href="https://undocumentedmatlab.com/articles/java-class-access-pitfalls/feed" rel="self" type="application/rss+xml" />
	<link>https://undocumentedmatlab.com/articles/java-class-access-pitfalls?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=java-class-access-pitfalls</link>
	<description>Professional Matlab consulting, development and training</description>
	<lastBuildDate>Thu, 20 Oct 2016 17:29:42 +0000</lastBuildDate>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.7.3</generator>
	<item>
		<title>
		By: Yair Altman		</title>
		<link>https://undocumentedmatlab.com/articles/java-class-access-pitfalls#comment-391136</link>

		<dc:creator><![CDATA[Yair Altman]]></dc:creator>
		<pubDate>Thu, 20 Oct 2016 17:29:42 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=4881#comment-391136</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://undocumentedmatlab.com/articles/java-class-access-pitfalls#comment-391039&quot;&gt;Amaury Vanvinckenroye&lt;/a&gt;.

@Amaury - this seems to be something specific to the &lt;code&gt;MongoClient&lt;/code&gt; class. You should probably ask about this in the MongoDB forums.]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://undocumentedmatlab.com/articles/java-class-access-pitfalls#comment-391039">Amaury Vanvinckenroye</a>.</p>
<p>@Amaury &#8211; this seems to be something specific to the <code>MongoClient</code> class. You should probably ask about this in the MongoDB forums.</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Amaury Vanvinckenroye		</title>
		<link>https://undocumentedmatlab.com/articles/java-class-access-pitfalls#comment-391039</link>

		<dc:creator><![CDATA[Amaury Vanvinckenroye]]></dc:creator>
		<pubDate>Wed, 19 Oct 2016 11:26:30 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=4881#comment-391039</guid>

					<description><![CDATA[Hi, I&#039;m using some Java classes in a Matlab code and it seems that a specific java class is not loaded, but only at the first run (i.e. at the start of Matlab). Later calls to the java function don&#039;t give any error, even if I &quot;clear all; clear classes; clear java&quot;. Here&#039;s the part of code failing at first run.
&lt;pre lang=&quot;matlab&quot;&gt;
javaaddpath(Obj.MongoDBPath)
import java.util.ArrayList;
import java.lang.String;
import com.mongodb.*;

credentialsList = ArrayList();
credentials = MongoCredential.createCredential(Username, &#039;admin&#039; , password);
credentialsList.add(credentials);
mongoClient = MongoClient(ServerAddress(IP,Port), credentialsList);
&lt;/pre&gt;
The failing java class is ServerAdress and is part of the mongodb package. 
Other java classes run fine immediately.
This error doesn&#039;t occur on all computers, so I&#039;m giving you my specs.
Windows 10 (previously windows 8), Matlab R2013a with Java 1.6.0_17-b04 (also tried with Java 1.8.0_25-b18 when adding it as environment variable).
It worked on a Mac with Matlab R2015b with Java 1.7, but also failed on another Mac with Matlab R2014a and java 1.8.
Thanks in advance]]></description>
			<content:encoded><![CDATA[<p>Hi, I&#8217;m using some Java classes in a Matlab code and it seems that a specific java class is not loaded, but only at the first run (i.e. at the start of Matlab). Later calls to the java function don&#8217;t give any error, even if I &#8220;clear all; clear classes; clear java&#8221;. Here&#8217;s the part of code failing at first run.</p>
<pre lang="matlab">
javaaddpath(Obj.MongoDBPath)
import java.util.ArrayList;
import java.lang.String;
import com.mongodb.*;

credentialsList = ArrayList();
credentials = MongoCredential.createCredential(Username, 'admin' , password);
credentialsList.add(credentials);
mongoClient = MongoClient(ServerAddress(IP,Port), credentialsList);
</pre>
<p>The failing java class is ServerAdress and is part of the mongodb package.<br />
Other java classes run fine immediately.<br />
This error doesn&#8217;t occur on all computers, so I&#8217;m giving you my specs.<br />
Windows 10 (previously windows 8), Matlab R2013a with Java 1.6.0_17-b04 (also tried with Java 1.8.0_25-b18 when adding it as environment variable).<br />
It worked on a Mac with Matlab R2015b with Java 1.7, but also failed on another Mac with Matlab R2014a and java 1.8.<br />
Thanks in advance</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Malcolm Lidierth		</title>
		<link>https://undocumentedmatlab.com/articles/java-class-access-pitfalls#comment-372061</link>

		<dc:creator><![CDATA[Malcolm Lidierth]]></dc:creator>
		<pubDate>Wed, 16 Mar 2016 20:26:33 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=4881#comment-372061</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://undocumentedmatlab.com/articles/java-class-access-pitfalls#comment-372056&quot;&gt;Vincent&lt;/a&gt;.

The class loader will only load one copy of a specific package/class combination.  A newer version will not replace the older one even if you have called javaaddpath (hence the NoSuchFieldError which implies you have created an instance using the old code). This is a Java class loader feature: if you load a jar that has dependencies on other jars (e.g. in a /dist/lib folder), and some of those jars are already loaded,  the already loaded versions will continue to be used.

In general, open source projects with the Apache brand will maintain backwards compatibility - deprecating, but not removing,  old fields/methods. If backwards compatibility is not maintained Apache projects will usually alter the package names so both versions can be used simultaneously. This being the case, replacing the jar file shipped with MATLAB with the newer version should produce no problems. &lt;strong&gt;But, anyone else using your code will need to do that too&lt;/strong&gt;. Buyer beware.]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://undocumentedmatlab.com/articles/java-class-access-pitfalls#comment-372056">Vincent</a>.</p>
<p>The class loader will only load one copy of a specific package/class combination.  A newer version will not replace the older one even if you have called javaaddpath (hence the NoSuchFieldError which implies you have created an instance using the old code). This is a Java class loader feature: if you load a jar that has dependencies on other jars (e.g. in a /dist/lib folder), and some of those jars are already loaded,  the already loaded versions will continue to be used.</p>
<p>In general, open source projects with the Apache brand will maintain backwards compatibility &#8211; deprecating, but not removing,  old fields/methods. If backwards compatibility is not maintained Apache projects will usually alter the package names so both versions can be used simultaneously. This being the case, replacing the jar file shipped with MATLAB with the newer version should produce no problems. <strong>But, anyone else using your code will need to do that too</strong>. Buyer beware.</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Vincent		</title>
		<link>https://undocumentedmatlab.com/articles/java-class-access-pitfalls#comment-372056</link>

		<dc:creator><![CDATA[Vincent]]></dc:creator>
		<pubDate>Wed, 16 Mar 2016 18:38:13 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=4881#comment-372056</guid>

					<description><![CDATA[How about what to do when you get a &quot;&lt;code&gt;java.lang.NoSuchFieldError&lt;/code&gt;&quot; because your java code uses a version of Apache&#039;s httpcore that is newer than the one matlab ships with, and the old one seems to be creating conflicts with the newer one you&#039;ve added to your java path?]]></description>
			<content:encoded><![CDATA[<p>How about what to do when you get a &#8220;<code>java.lang.NoSuchFieldError</code>&#8221; because your java code uses a version of Apache&#8217;s httpcore that is newer than the one matlab ships with, and the old one seems to be creating conflicts with the newer one you&#8217;ve added to your java path?</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Yair Altman		</title>
		<link>https://undocumentedmatlab.com/articles/java-class-access-pitfalls#comment-348751</link>

		<dc:creator><![CDATA[Yair Altman]]></dc:creator>
		<pubDate>Sat, 02 May 2015 17:18:06 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=4881#comment-348751</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://undocumentedmatlab.com/articles/java-class-access-pitfalls#comment-348717&quot;&gt;waldroje21&lt;/a&gt;.

If you wish me to help you debug your specific installation, contact me by mail for a private consulting.]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://undocumentedmatlab.com/articles/java-class-access-pitfalls#comment-348717">waldroje21</a>.</p>
<p>If you wish me to help you debug your specific installation, contact me by mail for a private consulting.</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: waldroje21		</title>
		<link>https://undocumentedmatlab.com/articles/java-class-access-pitfalls#comment-348717</link>

		<dc:creator><![CDATA[waldroje21]]></dc:creator>
		<pubDate>Fri, 01 May 2015 20:21:47 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=4881#comment-348717</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://undocumentedmatlab.com/articles/java-class-access-pitfalls#comment-348707&quot;&gt;Yair Altman&lt;/a&gt;.

in regard to the first... it shows up on the bottom when I type javaclasspath in the workspace, so I assume it can&#039;t be the wrong file, and that path is what i get when i type prefdir... I definitely restarted Matlab.... and I&#039;m using the same exact file string in the Dynamic path, that I use in the javaclasspath.txt, i just copied it straight from terminal. I&#039;ve done this with no problem on 3 other installs, so it&#039;s a bit strange.]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://undocumentedmatlab.com/articles/java-class-access-pitfalls#comment-348707">Yair Altman</a>.</p>
<p>in regard to the first&#8230; it shows up on the bottom when I type javaclasspath in the workspace, so I assume it can&#8217;t be the wrong file, and that path is what i get when i type prefdir&#8230; I definitely restarted Matlab&#8230;. and I&#8217;m using the same exact file string in the Dynamic path, that I use in the javaclasspath.txt, i just copied it straight from terminal. I&#8217;ve done this with no problem on 3 other installs, so it&#8217;s a bit strange.</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Yair Altman		</title>
		<link>https://undocumentedmatlab.com/articles/java-class-access-pitfalls#comment-348707</link>

		<dc:creator><![CDATA[Yair Altman]]></dc:creator>
		<pubDate>Fri, 01 May 2015 15:26:58 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=4881#comment-348707</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://undocumentedmatlab.com/articles/java-class-access-pitfalls#comment-348706&quot;&gt;waldroje21&lt;/a&gt;.

Perhaps one or more of the following happened:

	* you edited the wrong &lt;i&gt;classpath.txt&lt;/i&gt; file
	* you forgot to restart Matlab after editing the &lt;i&gt;classpath.txt&lt;/i&gt; file
	* you mistyped the class&#039;s full path in the file
	* you used a relative path in the file
]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://undocumentedmatlab.com/articles/java-class-access-pitfalls#comment-348706">waldroje21</a>.</p>
<p>Perhaps one or more of the following happened:</p>
<p>	* you edited the wrong <i>classpath.txt</i> file<br />
	* you forgot to restart Matlab after editing the <i>classpath.txt</i> file<br />
	* you mistyped the class&#8217;s full path in the file<br />
	* you used a relative path in the file</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: waldroje21		</title>
		<link>https://undocumentedmatlab.com/articles/java-class-access-pitfalls#comment-348706</link>

		<dc:creator><![CDATA[waldroje21]]></dc:creator>
		<pubDate>Fri, 01 May 2015 15:22:08 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=4881#comment-348706</guid>

					<description><![CDATA[Any idea why a Matlab would recognize a Java class file from the Dynamic path, but not the Static?  I&#039;ve added it to my Static path, and it&#039;s in there... but does not work... when I then add the same path using javaaddpath , it works.]]></description>
			<content:encoded><![CDATA[<p>Any idea why a Matlab would recognize a Java class file from the Dynamic path, but not the Static?  I&#8217;ve added it to my Static path, and it&#8217;s in there&#8230; but does not work&#8230; when I then add the same path using javaaddpath , it works.</p>
]]></content:encoded>
		
			</item>
	</channel>
</rss>
