In the office I have 2 computers. 1st is with Windows with 2 monitors. Second is with Ubuntu with it's separate monitor, keyboard and mouse. To free some space on the desk I got rid of the 2nd keyboard and mouse using a free tool called Synergy. You can use one terminal to control multiple machines and move to mouse cursor from one monitor to another.
As for now Windows version has got a nice gui. You just configure the monitors layout and start the server. Linux version has to be configured manually.
On linux all you need is to edit /etc/synergy.conf
and start the synergy client:
synergyc [SERVER HOST NAME]
You might have to update /etc/hosts file if you can't translate your server's host name.
More details about Ubuntu configuration: SynergyHowto for Ubuntu
I haven't tried QuickSynergy.
Wednesday, 23 March 2011
Customise the build using maven profiles and copy-resources plugin
Problem: Need to use different properties per environment.
CopyResourcesTest.java
Project structure:
Program always reads properties from /app.properties that is in src/main/resources. The dafault content of that file is:
my.value=default
There are 2 other files in the resources folder: src/main/resources/custom/app.properties and src/main/resources/prod/app.properties containing:
my.value=custom
and
my.value=prod
Depending on the environment we want to build for different app.properties should be included in the package. To achieve that we will use maven profiles.
Here is the pom.xml for our project.
There are 2 profiles defined: prod and custom. Building with each of them will package the application with corresponding properties.
Here are the test results:
Normally in the output package we only need 1 properties file. To do that we exclude the src/main/resources/configs from the resources, so the target folder looks like this:
CopyResourcesTest.java
package com.irenty;
import java.io.InputStream;
import java.util.Properties;
import org.junit.Test;
public class CopyResourcesTest {
@Test
public void testHelloWorld() throws Exception {
InputStream propsStream = CopyResourcesTest.class.getResourceAsStream("/app.properties");
Properties properties = new Properties();
properties.load(propsStream);
System.out.println("my.value=" + properties.getProperty("my.value"));
}
}
Project structure:
copy-resources ¦ pom.xml +---src ¦ +---main ¦ ¦ +---resources ¦ ¦ ¦ app.properties ¦ ¦ ¦ ¦ ¦ +---configs ¦ ¦ +---custom ¦ ¦ ¦ app.properties ¦ ¦ ¦ ¦ ¦ +---prod ¦ ¦ app.properties ¦ +---test ¦ +---java ¦ +---com ¦ +---irenty ¦ CopyResourcesTest.java
Program always reads properties from /app.properties that is in src/main/resources. The dafault content of that file is:
my.value=default
There are 2 other files in the resources folder: src/main/resources/custom/app.properties and src/main/resources/prod/app.properties containing:
my.value=custom
and
my.value=prod
Depending on the environment we want to build for different app.properties should be included in the package. To achieve that we will use maven profiles.
Here is the pom.xml for our project.
There are 2 profiles defined: prod and custom. Building with each of them will package the application with corresponding properties.
Here are the test results:
mvn clean install ... ------------------------------------------------------- T E S T S ------------------------------------------------------- Running com.irenty.CopyResourcesTest my.value=default Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.015 sec ...
mvn clean install -Pcustom ... ------------------------------------------------------- T E S T S ------------------------------------------------------- Running com.irenty.CopyResourcesTest my.value=custom Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.016 sec ...
mvn clean install -Pprod ... ------------------------------------------------------- T E S T S ------------------------------------------------------- Running com.irenty.CopyResourcesTest my.value=prod Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.016 sec ...
Normally in the output package we only need 1 properties file. To do that we exclude the src/main/resources/configs from the resources, so the target folder looks like this:
└───target
├───classes
│ app.properties
│
└───test-classes
└───com
└───irenty
CopyResourcesTest.class
Wednesday, 16 March 2011
How to post source code on blogspot
I found the 'how to' there:
http://vivianningyang.blogspot.com/2009/05/how-to-post-source-code-in-blogspotcom.html
I updated my blogspot's template to use the google code prettifier:
http://code.google.com/p/google-code-prettify/
HelloWorldTest.java
http://vivianningyang.blogspot.com/2009/05/how-to-post-source-code-in-blogspotcom.html
I updated my blogspot's template to use the google code prettifier:
http://code.google.com/p/google-code-prettify/
HelloWorldTest.java
package com.irenty;
import org.junit.Test;
public class HelloWorldTest {
@Test
public void testHelloWorld() throws Exception {
System.out.println("Hello World!");
}
}
Connecting from Ubuntu to Windows machine via Cisco Anyconnect SSL VPN
I tried to connect to my office's Windows workstation from my home Ubuntu. It's Ubuntu 10.10 - the Maverick 64bit version. After installing the VPN client I couldn't connect.
An SSL VPN connection attempt produces the following error message:
"Connection attempt has failed due to server certificate problem."
In some cases, this error message is not totally accurate since the problem might be because the AnyConnect client fails to find or open some user-provided libraries it needs to manipulate certificates.
To troubleshoot this call:
strace /opt/cisco/vpn/bin/vpn connect url.com 2>/tmp/debug.txt
You will see errors like:
open("/usr/local/firefox/libnss3.so", O_RDONLY) = -1 ENOENT (No such file or directory)
The easiest solution is to use the libs included in the firefox package:
# Downloaded latest firefox from http://www.mozilla.com/en-US/firefox/
sudo tar -xvjf firefox-3.0.5.tar.bz2 -C /usr/local
The firefox folder will be created in /usr/local. Now link the expected files in /usr/local/firefox:
for lib in libnssutil3.so libplc4.so libplds4.so libnspr4.so libsqlite3.so libnssdbm3.so libfreebl3.so ; do sudo ln -s /usr/local/firefox/$lib /opt/cisco/vpn/lib/$lib ; done
This should solve the VPN connection issue.
Now just connect to your Windows machine with: tsclient
Make sure you use proper RDP version. In my case it was version 5.
An SSL VPN connection attempt produces the following error message:
"Connection attempt has failed due to server certificate problem."
In some cases, this error message is not totally accurate since the problem might be because the AnyConnect client fails to find or open some user-provided libraries it needs to manipulate certificates.
Install the missing libraries, or if the libraries are installed, create symbolic links that point to the location of the libraries in one of the places AnyConnects expects to find the them.
To troubleshoot this call:
strace /opt/cisco/vpn/bin/vpn connect url.com 2>/tmp/debug.txt
You will see errors like:
open("/usr/local/firefox/libnss3.so", O_RDONLY) = -1 ENOENT (No such file or directory)
The easiest solution is to use the libs included in the firefox package:
# Downloaded latest firefox from http://www.mozilla.com/en-US/firefox/
sudo tar -xvjf firefox-3.0.5.tar.bz2 -C /usr/local
The firefox folder will be created in /usr/local. Now link the expected files in /usr/local/firefox:
for lib in libnssutil3.so libplc4.so libplds4.so libnspr4.so libsqlite3.so libnssdbm3.so libfreebl3.so ; do sudo ln -s /usr/local/firefox/$lib /opt/cisco/vpn/lib/$lib ; done
This should solve the VPN connection issue.
Now just connect to your Windows machine with: tsclient
Make sure you use proper RDP version. In my case it was version 5.
Tuesday, 15 March 2011
Java application throws IOException: Too many open files - how to investigate issue in Linux
To investigate this kind of issues under Linux you can monitor the maximum number of open files / file descriptors (FD) for your application's process. It's not a solution to increase the limit of FDs in your system. You should eliminate the root cause of the problem in your application. Look for the unclosed files/connections. You might have missed something. In case of connections
Here are steps:
*** know your java process number
ps aux | grep java
1743
*** know the number of opened files by your process:
lsof -p 1743 | wc -l
975
*** know your file descriptor limit (soft and hard)
ulimit -Sn
ulimit -Hn
*** to display maximum number of open file descriptors:
cat /proc/sys/fs/file-max
***** System-wide File Descriptors (FD) Limits
*** increase the maximum number of open files by setting a new value in kernel variable /proc/sys/fs/file-max as follows (login as the root):
sysctl -w fs.file-max=100000
*** if the limit has to be set after reboot, append: fs.file-max = 100000 to:
vi /etc/sysctl.conf
*** log out and in or call:
# sysctl -p
*** verify:
sysctl fs.file-max
or
cat /proc/sys/fs/file-max
***** User Level FD Limits
*** set user level limits:
vi /etc/security/limits.conf
add:
httpd soft nofile 4096
httpd hard nofile 10240
Subscribe to:
Posts (Atom)
