The LogCat issue I described the other day caused a secondary problem: the auto-suggest feature in Eclipse was disabled! Well, to be fair I think I received a pop-up message about it, but who reads those anyway? So I accepted the message, and sadly, auto-suggest was gone.
To get it back, go to: Preferences > Java > Editor > Content Assist > Advanced. Make sure "Java Proposals" are enabled.
Monday, May 9, 2011
Friday, May 6, 2011
LogCat output is empty
I am using SpringSource Tool Suite which is a souped-up version of Eclipse (it comes with all kinds of plugins pre-installed as well as embedded servlet engines). The Android SDK comes with Log4J packaged, and the log output is shown in a window known as "LogCat". If this view isn't currently open, go to: Window > Show View > Other... > Android > LogCat
So.... For a few days, LogCat was producing output as expected. Then, it just went silent. Even restarting STS didn't bring back my beautiful logs. It turns out, whether coincidentally or otherwise, the MyLyn plugin causes some interaction as postulated in this post.
I did verify, on Mac OS X, that removing all JARs beginning with "org.eclipse.mylyn" causes LogCat to resume normally.
So.... For a few days, LogCat was producing output as expected. Then, it just went silent. Even restarting STS didn't bring back my beautiful logs. It turns out, whether coincidentally or otherwise, the MyLyn plugin causes some interaction as postulated in this post.
I did verify, on Mac OS X, that removing all JARs beginning with "org.eclipse.mylyn" causes LogCat to resume normally.
Thursday, May 5, 2011
Finding a Maven Repository
When you define a dependency in pom.xml, you are telling your compiler where to go get JARs from in the Maven archive. This way, you don't need to maintain your libraries and if they are updated, you simply change the version number in your pom.xml file.
If you know what dependency you need, for example, Apache Commons/IO, browse to a Maven mirror such as:
If you know what dependency you need, for example, Apache Commons/IO, browse to a Maven mirror such as:
http://mirrors.ibiblio.org/pub/mirrors/maven2/when you navigate down to:
http://mirrors.ibiblio.org/pub/mirrors/maven2/commons-io/commons-io/The first and second directories represent the Group ID and the Artifact ID. For example:
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.0.1</version>
</dependency>
In the above example, the reuse of "commons-io" makes it unclear, but the canonical form is:http://mirrors.ibiblio.org/pub/mirrors/maven2/groupId/artifactId/
Wednesday, April 27, 2011
Creating a JSON-RPC service using Maven, Eclipse, and Tomcat
Oddly, there are very few resources for creating JSON-RPC services implemented using Java. JSON-RPC is a nice way for heterogeneous servers to communicate using a lightweight protocol. Because of the hierarchical nature of JSON plus its readiness for easy conversion to native domain objects, one would expect it to be a POJO by now.
However, that is not the case, and implementation requires download of third-party libraries such as jsonrpc4j. The site suggests that you create a Maven project to link to their JARs, write a couple of classes, and you magically have a JSON-RPC service. I beg to differ.
Setup
First, you need to create a Maven project, which is a macro available in SpringSource Tool Suite. Select File > New > Project... > Maven Project. Most importantly, you get a pom.xml and a /src/main directory with this macro. The Apache Web site specifies that directories in a Maven project are specified by convention. Therefore, to conform to Maven convention, you need to add a java/ directory under /src/main.
If you are a newbie to Spring, simply following the instructions in the site are not enough. In addition, you must add:
to your web.xml. In addition, the XML file containing the properties should be named remoting-servlet.xml. Again, this is according to Spring convention.
You will need to add the following line to your interface:
and you may need to fiddle with pom.xml a little bit (I had to force Maven to use Java 1.6). In the meantime, Eclipse will likely display syntax errors but you may need to ignore them.
Compiling
The first time you attempt to compile using Maven, you should create a Run Configuration. To get the Base Directory, Browse the Workspace and select the project name. Under Goals, enter "eclipse:eclipse". Run the project once. If it succeeds, the only thing you've done is to force Eclipse to load the JARs declared in pom.xml. The syntax checker should be accurate from this point on.
Change the Goals to "clean install". As long as you don't declare new JARs, you should not need to change your Run Configuration again. Select this configuration to build your WAR file.
Deploying
Assuming you have a Tomcat instance available to you (I installed one on Ubuntu using "sudo apt-get install tomcat6"). Copy the WAR file to /var/lib/tomcat6/webapps/.
Testing
Because this is a JSON-RPC service, the most appropriate way to test is to use the following cURL command:
where test.json may look like:
If it works, you are supposed to get a JSON response back, representing the deserialized Java object.
However, it didn't work for me. Yet.
However, that is not the case, and implementation requires download of third-party libraries such as jsonrpc4j. The site suggests that you create a Maven project to link to their JARs, write a couple of classes, and you magically have a JSON-RPC service. I beg to differ.
Setup
First, you need to create a Maven project, which is a macro available in SpringSource Tool Suite. Select File > New > Project... > Maven Project. Most importantly, you get a pom.xml and a /src/main directory with this macro. The Apache Web site specifies that directories in a Maven project are specified by convention. Therefore, to conform to Maven convention, you need to add a java/ directory under /src/main.
If you are a newbie to Spring, simply following the instructions in the site are not enough. In addition, you must add:
<servlet>
<servlet-name>remoting</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>remoting</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
to your web.xml. In addition, the XML file containing the properties should be named remoting-servlet.xml. Again, this is according to Spring convention.
You will need to add the following line to your interface:
import com.googlecode.jsonrpc4j.JsonRpcParamName;
and you may need to fiddle with pom.xml a little bit (I had to force Maven to use Java 1.6). In the meantime, Eclipse will likely display syntax errors but you may need to ignore them.
Compiling
The first time you attempt to compile using Maven, you should create a Run Configuration. To get the Base Directory, Browse the Workspace and select the project name. Under Goals, enter "eclipse:eclipse". Run the project once. If it succeeds, the only thing you've done is to force Eclipse to load the JARs declared in pom.xml. The syntax checker should be accurate from this point on.
Change the Goals to "clean install". As long as you don't declare new JARs, you should not need to change your Run Configuration again. Select this configuration to build your WAR file.
Deploying
Assuming you have a Tomcat instance available to you (I installed one on Ubuntu using "sudo apt-get install tomcat6"). Copy the WAR file to /var/lib/tomcat6/webapps/.
Testing
Because this is a JSON-RPC service, the most appropriate way to test is to use the following cURL command:
curl -v http://localhost:8080/projname/myServlet -d @test.json
where test.json may look like:
{
"jsonrpc": "2.0",
"method": "createUser",
"params":[
{"firstName": "Dean"}
],
"id": "0"
}
If it works, you are supposed to get a JSON response back, representing the deserialized Java object.
However, it didn't work for me. Yet.
Saturday, February 12, 2011
Access denied for user 'root'@'client machine name' (using password: YES)
I encounter this error frequently both at work and on the occasional home project. While attempting to connect to a MySQL server using say, MySQL Workbench, I get the following:
To resolve this, there are three specific things you need to do. Please keep in mind that I'm a developer so please refer to a sys admin for more sophisticated solutions.
and tested the installation using
In MySQL Workbench (I have 5.2.31 for Mac OS X), create a "New Connection" to "Start Querying", and provide the connection credentials (IP address of the MySQL server, username "root", and root password. You will likely see the error message described by the title of this blog.
A simple test from your client computer is:
You should see something meaningful but cryptic. If you see "connection refused", then you will need to do step 6 above because it means the port has been disallowed by default (or your sys admin).
Access denied for user 'root'@'client machine name' (using password: YES)
To resolve this, there are three specific things you need to do. Please keep in mind that I'm a developer so please refer to a sys admin for more sophisticated solutions.
- Make sure MySQL is listening for incoming connections and that port 3306 is open
- Grant (remote) user privileges to your MySQL server
sudo apt-get install mysql-server mysql-client
and tested the installation using
mysql -u root -p show databases;
In MySQL Workbench (I have 5.2.31 for Mac OS X), create a "New Connection" to "Start Querying", and provide the connection credentials (IP address of the MySQL server, username "root", and root password. You will likely see the error message described by the title of this blog.
Make sure MySQL is listening for incoming connections and that port 3306 is open
Perform steps 1 through 4 as described in this blog. I found that step 5 isn't necessary if you're just playing around and want to administer your own instance using the tools in Workbench. Also, steps 6 and 7 aren't necessary because the default Ubuntu installation allows connections on all ports by default (!!!)A simple test from your client computer is:
telnet [server ip address] 3306
You should see something meaningful but cryptic. If you see "connection refused", then you will need to do step 6 above because it means the port has been disallowed by default (or your sys admin).
Grant (remote) user privileges to your MySQL server
Execute the following SQL query:GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' IDENTIFIED BY 'some_pass' WITH GRANT OPTION;
Sunday, December 19, 2010
Using Cisco VPN on Snow Leopard
This is a great blog on setting up your VPN (Cisco IPsec only) on your Snow Leopard machine. Crazy, but neither Mac OS nor Cisco appear to have a supported standalone client.
Thursday, November 4, 2010
Synchronizing Tables in a MySQL Cluster
I created a table in a MySQL cluster but did not fully understand the way a Master-Master configuration operates. I still don't. However, it didn't take long to determine that I needed to create the table in each node of the cluster only to find out that data doesn't get synchronized automatically. Grr.
A friendly DBA informed me that I needed to do this when creating the table:
A friendly DBA informed me that I needed to do this when creating the table:
create table tbl_name (i INT) ENGINE=NDBCLUSTER;which specifies that this table is to be managed by the cluster. If the table has already been created (as was my case), this can be added after-the-fact:
ALTER TABLE tbl_name ENGINE=NDBCLUSTER; FLUSH TABLES;
Subscribe to:
Posts (Atom)