Tuesday, October 30, 2012

Copy all text in a Gnome terminal

Shamelessly copied from arsane on superuser.com (Thanks)

Instead of dragging mouse to select all text:

1. Triple click the last line of current terminal(do not release the mouse).
2. Press SHIFT+HOME key which will lead us to the first line.
3. Drag mouse to the first line.
4. Right click , edit->copy.

See http://superuser.com/a/80175.

Apache Felix LinkageError

I was getting java.lang.LinkageError when running Felix. I had a big trouble finding out what the problem really was.

Finally, I found that javax.activation was being loaded by two modules differently (See http://frankkieviet.blogspot.no/2009/03/javalanglinkageerror-loader-constraint.html and http://stackoverflow.com/questions/4270950/compile-time-vs-run-time-dependency-java).

I couldn't exclude javax.activation from any of my modules (tried to explicitly ignore it from my pom.xml files (Maven), but that didn't work).

In the end I discovered that felix automatically loads some packages on startup. This is specified in the org.osgi.framework.system.packages.extra variable in config.properties (In the conf folder).
Just adding javax.activation;version=1.1.1 (The version I wanted) there fixed it.
Now Felix loads the package, and my waring modules fetch it from there instead of trying to load it themselves.

Sources: http://devangelist.blogspot.no/2011/04/osgi-bundle-lifecycles.html,
http://stackoverflow.com/questions/6097279/java-lang-linkageerror-loader-constraint-violation-in-grails-project,
http://fusesource.com/forums/message.jspa?messageID=14613,
http://fusesource.com/forums/thread.jspa?messageID=7682

Play 2 Framework as a Windows Service

I wanted to run Play2 as a Windows Service, but had problems getting it to work with the usual methods (SC.exe) (See http://www.herikstad.net/2012/10/run-as-windows-service.html for others).

Ended up using RunAsSvc from PirmaSoft. Here is how:


1. In command prompt. Go to your project folder. Run play dist. This will create a ZIP file in the dist folder of your project.
3. Unzip the ZIP file in a location of your choice-
4. Download RunAsSvc from http://www.pirmasoft.de/runassvc.php and unzip it in a location of your choice.
5. Run RunAsSvc.exe as an Administrator
 5.1 Choose a Name for your service
 5.2 Choose a Description for your service
 5.3 In "Path to executable" browse to your Java/bin folder (e.g. C:\Program Files\Java\jre7\bin) and choose java.exe
 5.4 In "Parameters" Enter: -Dhttp.port=80 -cp "./lib/*;" play.core.server.NettyServer . (you only need the -Dhttp.port=80 flag if you want to set the port to something other than 9000).
 5.5 Set the working directory to the locations where you unzipped the project ZIP file.
 5.6 Press OK and check that you now can find your service in the Service panel (services.msc) and that you can open your webpage in your browser.

To delete the service, go to "Add/Remove Programs" and find PirmaSoft RunAsSvc - <your service name> and select uninstall.

If the service won't run, check that there is no RUNNING_PID file in the folder where you unzipped the ZIP file.

To see the process in Task Manager: Select "Show processes from all users", it will be a java.exe running as SYSTEM.

Sources:  https://groups.google.com/forum/?fromgroups=#!topic/play-framework/xykhfyVu_Y0,
http://stackoverflow.com/questions/9689793/cant-execute-jar-file-no-main-manifest-attribute,
http://stackoverflow.com/questions/10894615/play-framework-bat-windows-java-process,
http://stackoverflow.com/questions/9941689/how-to-change-http-port-that-play2-is-listening-on

Run as Windows Service

Sometimes you want to be able to run a program in the background, and to keep it running even though you are not logged in. Some programs give you the possibility to set them up as services, here are some ways to install any program as a service:

1. Using SC to install it yourself (sc "MyServiceName" binPath= "C:\myservice\my.exe", note the space after binPath)
2. Using instsrv.exe and srvany.exe
3. More types (For 1,2, and 3: http://www.msfn.org/board/topic/83272-how-to-run-a-program-as-a-service/)
4. Adding the script as a Startup Script in Group Policy (http://techsupt.winbatch.com/ts/T000001048F90.html) (gpedit.msc)
5. Using the nice little tool RunAsSvc from Pirmasoft (http://www.pirmasoft.com/runassvc.php)
6. Using YAJSW (Yet Another Java Service Wrapper) (http://yajsw.sourceforge.net/#mozTocId212903)
7. Using JSW (Java Service Wrapper) (http://wrapper.tanukisoftware.com/doc/english/download.jsp)

Source: http://www.msfn.org/board/topic/83272-how-to-run-a-program-as-a-service/

Wednesday, October 24, 2012

JBoss Wrapper PropertyNotFoundException

After setting up JBoss to be run through a Java Service Wrapper from Tanuki Software (http://wrapper.tanukisoftware.com/doc/english/integrate-simple-nix.html) I got the following exception:

Caused by: javax.el.PropertyNotFoundException: /page.xhtml @20,20 value="#{objectname.fieldname}": Target Unreachable, identifier 'objectname' resolved to null

Turns out this is because the wrapper.conf file field wrapper.app.parameter.2 can't handle the bind address (-b 192.168.1.50) flag if used exactly as in the command line.

To fix, remove the space between the -b and the IP address:
wrapper.app.parameter.2=-b192.168.1.50

Solutions source: https://community.jboss.org/thread/93706

Tuesday, October 2, 2012

Installing xlrd module in Portable Python

Portable Python is a neat project to put python on a USB stick (or wherever) to not have to install it on your machine. xlrd is an excellent Python module for reading Excel files.
To make the xlrd module available in your Portable Python installation (so you can use it in a script using import xlrd) you just have to copy the source files:
1. Install Portable Python to a location of your choice. http://www.portablepython.com/
2. Download xlrd http://pypi.python.org/pypi/xlrd
3. Extract the xlrd tar.gz file
4. Copy the files found in xlrd folder (e.g.xlrd-0.8.0.tar.gz\dist\xlrd-0.8.0.tar\xlrd-0.8.0\xlrd\) to the App\lib directory of the Portable Python installation.
I suggest you create a directory for the files (e.g. Portable Python 2.7.3.1\App\Lib\xlrd).
5. Start using xlrd in scripts run using Portable Python

Source: https://groups.google.com/d/topic/portablepython/IXqu0Y1Hcug/discussion