<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>aaron-kelley.net &#187; Java</title>
	<atom:link href="http://aaron-kelley.net/blog/tag/java/feed/" rel="self" type="application/rss+xml" />
	<link>http://aaron-kelley.net</link>
	<description>My little corner of the Internet</description>
	<lastBuildDate>Wed, 01 Sep 2010 23:57:34 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>MySQL, Tomcat 6, and Ubuntu 9.10: Blah</title>
		<link>http://aaron-kelley.net/blog/2010/01/mysql-tomcat-6-and-ubuntu-9-10-blah/</link>
		<comments>http://aaron-kelley.net/blog/2010/01/mysql-tomcat-6-and-ubuntu-9-10-blah/#comments</comments>
		<pubDate>Thu, 21 Jan 2010 22:23:43 +0000</pubDate>
		<dc:creator>Aaron</dc:creator>
				<category><![CDATA[Software]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Ubuntu]]></category>

		<guid isPermaLink="false">http://aaron-kelley.net/?p=684</guid>
		<description><![CDATA[Trying to set up a JSP application on Ubuntu 9.10, using Tomcat 6 and MySQL 5.1 (both from the Ubuntu repositories).  I was getting a curious error when trying to get a connection to the MySQL database from the JDBC DriverManager: SQLException: Communications link failure The last packet sent successfully to the server was 0 [...]]]></description>
			<content:encoded><![CDATA[<p>Trying to set up a JSP application on Ubuntu 9.10, using Tomcat 6 and MySQL 5.1 (both from the Ubuntu repositories).  I was getting a curious error when trying to get a connection to the MySQL database from the JDBC DriverManager:</p>
<blockquote><p>SQLException: Communications link failure<br />
The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.<br />
SQLState: 08S01<br />
VendorError: 0</p></blockquote>
<p>After searching for a while and going through some solutions that didn&#8217;t work for me, I found the answer <a href="http://demoniosypinguinos.wordpress.com/2009/12/01/configurar-tomcat-para-mysql-en-ubuntu-9-10/" target="_blank">here</a>.  I&#8217;m re-posting it because that answer is posted in Spanish.  <img src='http://aaron-kelley.net/wp-includes/images/smilies/icon_razz.gif' alt=':-P' class='wp-smiley' /> </p>
<p>All you have to do is open <tt>/etc/init.d/tomcat6</tt> in your favorite text editor (as root), find the line that looks like <tt>TOMCAT6_SECURITY=yes</tt>, and change it to <tt>TOMCAT6_SECURITY=no</tt>.  Then, restart the Tomcat server (<tt>sudo service tomcat6 restart</tt>).  Ta da!!  MySQL connections are now working.</p>
<p>Now, there&#8217;s probably a better way to do this that doesn&#8217;t involve completely turning off &#8220;<tt>TOMCAT6_SECURITY</tt>,&#8221; but this seems fine for a small test project which is what I&#8217;m working on (it will eventually be deployed on the JBoss server).  I&#8217;ll be sure to update this post if I find it&#8230; or if you know anything, leave a note in the comments below.</p>
]]></content:encoded>
			<wfw:commentRss>http://aaron-kelley.net/blog/2010/01/mysql-tomcat-6-and-ubuntu-9-10-blah/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Java icon appears in system tray, even when you told it not to?</title>
		<link>http://aaron-kelley.net/blog/2008/07/java-icon-appears-in-system-tray-even-when-you-told-it-not-to/</link>
		<comments>http://aaron-kelley.net/blog/2008/07/java-icon-appears-in-system-tray-even-when-you-told-it-not-to/#comments</comments>
		<pubDate>Wed, 16 Jul 2008 18:42:13 +0000</pubDate>
		<dc:creator>Aaron</dc:creator>
				<category><![CDATA[Software]]></category>
		<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://aaron-kelley.net/?p=25</guid>
		<description><![CDATA[Alright, here&#8217;s some Sun Java silliness I ran across a while back and just found the fix for. If you&#8217;re running Java applications on Windows, you may have noticed that Sun likes you to see a Java icon in the system notification area when a Java application is running. You can get rid of it [...]]]></description>
			<content:encoded><![CDATA[<p>Alright, here&#8217;s some Sun Java silliness I ran across a while back and just found the fix for.</p>
<p>If you&#8217;re running Java applications on Windows, you may have noticed that Sun likes you to see a Java icon in the system notification area when a Java application is running.  You can get rid of it by right-clicking on it and selecting &#8220;Hide icon,&#8221; but it&#8217;ll just come back next time.  There&#8217;s an option in the Java control panel to hide the icon&#8230;  But sometimes, in Vista, it shows up even though you&#8217;ve told it to hide.</p>
<p><span id="more-25"></span></p>
<p style="text-align: center;"><img class="size-full wp-image-26 aligncenter" title="Java tray icon" src="http://aaron-kelley.net/wp-content/uploads/2009/07/20080716_java-tray.png" alt="20080716_java-tray" width="537" height="689" /></p>
<p>Here&#8217;s the solution.</p>
<p>Open an <em>elevated</em> command prompt.  Navigate to the Java JRE&#8217;s bin folder&#8230;  at present, on my machine, it is &#8220;<tt>C:\Program Files (x86)\Java\jre1.6.0_07\bin</tt>&#8220;.  Run javacpl.exe.  The Java control panel will open.  If you go check, you&#8217;ll notice that the option to show the icon in the system tray is still checked, even if you unchecked it before&#8230;  It seems that the setting is kept independently for elevated applications and non-elevated applicaitons.</p>
]]></content:encoded>
			<wfw:commentRss>http://aaron-kelley.net/blog/2008/07/java-icon-appears-in-system-tray-even-when-you-told-it-not-to/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Getting Started with JNI and C++ under Windows</title>
		<link>http://aaron-kelley.net/blog/2007/09/getting-started-with-jni-and-c-under-windows/</link>
		<comments>http://aaron-kelley.net/blog/2007/09/getting-started-with-jni-and-c-under-windows/#comments</comments>
		<pubDate>Sun, 02 Sep 2007 01:35:58 +0000</pubDate>
		<dc:creator>Aaron</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Visual Studio]]></category>

		<guid isPermaLink="false">http://aaron-kelley.net/?p=65</guid>
		<description><![CDATA[This is a step-by-step guide to getting started at using JNI with C++ under Windows. JNI is pretty much a method to call C/C++ functions from a Java application. (Actually, calling native code written in other languages, including assembly, is supported as well, but here I am focusing on C++.) This guide should give you [...]]]></description>
			<content:encoded><![CDATA[<p>This is a step-by-step guide to getting started at using <a href="http://en.wikipedia.org/wiki/Java_Native_Interface" target="_blank">JNI</a> with C++ under Windows.</p>
<p><span id="more-65"></span>JNI is pretty much a method to call C/C++ functions from a Java application.  (Actually, calling native code written in other languages, including assembly, is supported as well, but here I am focusing on C++.)  This guide should give you all you need to know to get JNI working quickly.</p>
<p>The JNI documentation for Java 1.6 is located <a href="http://java.sun.com/javase/6/docs/technotes/guides/jni/" target="_blank">here</a>.  The JNI 6.0 Specification is a good place to look, in fact, you&#8217;re going to read some of that to know how to call Java functions from C/C++, which Java types correspond to which C/C++ types, and so on.  What the spec lacks is concrete information on how to get JNI working.  In Chapter 2, they discuss how to name your C function and give some sample code.  I could not get this to work, so I went off looking for better examples elsewhere.</p>
<p>Anyway, here&#8217;s what you do.</p>
<p>First, you must create a Java class with prototypes for the native functions that you want to use.  You declare a function native just by including the keyword &#8216;native&#8217; in its declaration, for instance, &#8216;<tt>static native double f();</tt>&#8216; is a static function that takes no parameters and returns a double.  Note that you just end the function declaration with a semi-colon, you do not write any code for the function here.</p>
<p>This class may contain any other Java code that you like.</p>
<p>Next, you generate a header file using the native function declarations in your Java class.  The JDK includes a program called <tt>javah</tt> that does this for you.  If you have a class named <tt>MyClass</tt>, then open a command prompt and go to the directory containing <tt>MyClass.class</tt> and run the command <tt>javah MyClass</tt>.  This will generate <tt>MyClass.h</tt>.</p>
<p>Now, you must create a <tt>.cpp</tt> file and implement at a minimum all of the functions declared in <tt>MyClass.h</tt>, and compile the results to a DLL.  For information on how to do this with Microsoft Visual C++ 2005 Express Edition, see my <a href="index.php?itemid=8">previous post</a>.  I also have had success using gcc with Cygwin, see below.*  Your <tt>.cpp</tt> file should include the <tt>.h</tt> file that was generated.  You may link this code to whatever other C++ code you like (I am writing a JNI wrapper for an existing C++ library).</p>
<p>Note that when you compile this, it&#8217;s going to be looking for files in the JDK&#8217;s include folder.  You&#8217;ll need to make sure that you add this to your include path.  For instance, for me, I had to add &#8220;C:\Program Files (x86)\Java\jdk1.6.0_02\include&#8221; and &#8220;C:\Program Files (x86)\Java\jdk1.6.0_02\include\win32&#8243; to the include path.  These paths should be similar for you.  (For information in how to do this in Microsoft Visual C++ 2005/2008, see below.**)</p>
<p>Now that you have your DLL, you&#8217;re ready to actually call these functions from Java.  You must load your library from Java.  This is done by calling the <tt>System.loadLibrary()</tt> function in Java.  The line <tt>System.loadLibrary("MyClass");</tt> will try to load <tt>MyClass.dll</tt>, looking for it in the current working directory and all directories in the system path.  (You may also use <tt>System.load();</tt> and provide a full path to the file, using &#8216;/&#8217; instead of &#8216;\&#8217; to mark directories, for example, <tt>System.load("c:/MyClass.dll");</tt>.)</p>
<p>As long as you call <tt>System.loadLibrary()</tt> before you make any native calls, and your DLL is in the right place, <em>and</em> you named all of the native C++ functions correctly (which should be easy, since that&#8217;s done for you in the generated <tt>.h</tt> file), it should be working now.  If you get an UnsatisfiedLinkError exception when you make a native call, check to make sure that your C++ function header matches what was generated in the <tt>.h</tt> file.  If you get it when calling <tt>System.loadLibrary()</tt>, check to make sure that your DLL is in the right place.</p>
<p>* I&#8217;m assuming you&#8217;re already familiar with gcc and Cygwin.  To compile a DLL with gcc running under Cygwin, first use the command <tt>gcc -c MyClass.c</tt> to generate an object file, and then <tt>gcc -mno-cygwin -shared -Wl,--kill-at -o MyClass.dll MyClass.o</tt> to generate the DLL.  The <tt>-mno-cygwin</tt> switch makes sure that the DLL generated is not dependent on the Cygwin runtime (i.e., you won&#8217;t have to have Cygwin installed to run code out of it).  Similar compilation methods should work with g++, I haven&#8217;t tried it yet though.  (<a href="http://forum.java.sun.com/thread.jspa?threadID=708047&amp;messageID=4100932" target="_blank">source</a>)</p>
<p>** In Visual C++ 2005/2008, go to &#8220;Tools -&gt; Options&#8221;, then expand &#8220;Projects and Solutions&#8221; and select &#8220;VC++ Directories.&#8221;  Click on the drop-down menu under &#8220;Show directories for:&#8221; and choose &#8220;Include files.&#8221;  You can add include directories here, I had to add &#8220;C:\Program Files (x86)\Java\jdk1.6.0_02\include&#8221; and &#8220;C:\Program Files (x86)\Java\jdk1.6.0_02\include\win32&#8243;.</p>
]]></content:encoded>
			<wfw:commentRss>http://aaron-kelley.net/blog/2007/09/getting-started-with-jni-and-c-under-windows/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
