Well sometimes I need a cmd right from the directory in the explorer within Windows. Microsoft offered the so called MS Powertoys, which have had a feature called command prompt from here. What that does was just a simple registry entry, which added an entry to the folder context menu. If you want to have such an extension you could easily add the following to your registry:
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Folder\shell\command prompt]
@="Devenv from here"
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Folder\shell\command prompt\command]
@="C:\\bin\\devenv.cmd %L"
(Just paste the lines above into a file with a .reg extension and click on it)
Now you could create a file called C:\bin\devenv.cmd and add you favorite Path extensions or variables. After adding the two entries to your registry you will see a new entry when you right click on a folder "Devenv from here".
All these little things in life They all create this haze There's too many things to get done And I'm running out of days (3Doors Down)
Dieses Blog durchsuchen
Mittwoch, 2. Juni 2010
Dienstag, 20. April 2010
Eclipse Galileo 3.5.1 Index Problems
After a while working with eclipse Galileo SR1 the startup of the IDE slows down. Beside this I frequently got an error like that:
Class file name must end with .class
To fix this I've done the following:
Class file name must end with .class
To fix this I've done the following:
- Close Eclipse
- Delete
/.metadata/.plugins/org.eclipse.jdt.core/*.index - Delete
/.metadata/.plugins/org.eclipse.jdt.core/savedIndexNames.txt - Start Eclipse again
Mittwoch, 17. März 2010
Instantiate a Generic Type in Java
Once you used generics for a while you might stumble upon the following question:
public class MySample {
private T mySample = null;
public MySample() {
mySample = new T(); // well this would be fine, but it doesn't work because the compiler doesn't know the type at this time!
}
}
Ok, fair enough the compiler doesn't know if T is an interface or an object and couldn't instantiate the type. If your T is a class you could solve the question with this:
This should work with the little overhead of specifying the class in the generic and the constructor:
public class MySample
private T mySample = null;
public MySample() {
mySample = new T(); // well this would be fine, but it doesn't work because the compiler doesn't know the type at this time!
}
}
Ok, fair enough the compiler doesn't know if T is an interface or an object and couldn't instantiate the type. If your T is a class you could solve the question with this:
public class MySample {
private T mySample = null;
public MySample(Class _class) {
mySample = _class.newInstance();
}
}
This should work with the little overhead of specifying the class in the generic and the constructor:
MySample sample = new MySample(Whatever.class);
Dienstag, 16. Februar 2010
Java File Format Version
Once you're moving around for a while in Java based environments you might have seen an error like this
If you hit this kind of error than its time to realize that Java byte code might differ between JDK versions :-) You'll find a long list of explanations about the Java Class file format all over in the web (http://en.wikipedia.org/wiki/Class_%28file_format%29).
Here is a list of class file versions and the corresponding JDK
Ok thanks for the list but how do I get the version out of an existing class file?
Answer:
this will print out something like this:
java.lang.UnsupportedClassVersionError: Bad version number in .class file
If you hit this kind of error than its time to realize that Java byte code might differ between JDK versions :-) You'll find a long list of explanations about the Java Class file format all over in the web (http://en.wikipedia.org/wiki/Class_%28file_format%29).
Here is a list of class file versions and the corresponding JDK
J2SE 6.0 = 50 (0x32 hex),
J2SE 5.0 = 49 (0x31 hex),
JDK 1.4 = 48 (0x30 hex),
JDK 1.3 = 47 (0x2F hex),
JDK 1.2 = 46 (0x2E hex),
JDK 1.1 = 45 (0x2D hex).
J2SE 5.0 = 49 (0x31 hex),
JDK 1.4 = 48 (0x30 hex),
JDK 1.3 = 47 (0x2F hex),
JDK 1.2 = 46 (0x2E hex),
JDK 1.1 = 45 (0x2D hex).
Ok thanks for the list but how do I get the version out of an existing class file?
Answer:
javap -v MyClass | more
this will print out something like this:
class MyClass extends java.lang.Object
minor version: 0
major version: 50
....
minor version: 0
major version: 50
Dienstag, 9. Februar 2010
Linklist: Tuning a JVM
Here's a link list of sites I visit during a GC Tuning session.
Tuning Garbage Collection with the 5.0 Java[tm] Virtual Machine
http://java.sun.com/docs/ hotspot/gc5.0/gc_tuning_5.html
Server profiler of my choice :
http://www.yourkit.com/ overview/index.jsp
Big Blue diagnostic Tool:
http://www.ibm.com/ developerworks/java/library/j- ibmtools2/index.html
SUN:
http://java.sun.com/ performance/jvmstat/visualgc. html#VisualGC
HPJMeter:
http://software.hp.com/portal/ swdepot/displayProductInfo.do? productNumber=HPJMETER
White papers and references
http://java.sun.com/ performance/reference/ whitepapers/tuning.html
http://www.sugd.de/sourcetalk_ 2006_presentations/trapp-java- performance.pdf
http://java.sun.com/javase/ technologies/hotspot/ vmoptions.jsp
http://publib.boulder.ibm.com/ infocenter/wasinfo/v6r0/index. jsp?topic=/com.ibm.websphere. express.doc/info/exp/ae/tprf_ tunejvm.html
Tuning Garbage Collection with the 5.0 Java[tm] Virtual Machine
http://java.sun.com/docs/
Server profiler of my choice :
http://www.yourkit.com/
Big Blue diagnostic Tool:
http://www.ibm.com/
SUN:
http://java.sun.com/
HPJMeter:
http://software.hp.com/portal/
White papers and references
http://java.sun.com/
http://www.sugd.de/sourcetalk_
http://java.sun.com/javase/
http://publib.boulder.ibm.com/
Donnerstag, 4. Februar 2010
Mount network share at startup in MacOSx
I run a Buffalo TeraStation NAS server within my environment. To use it within a unix based machine like my IMac I just need to open a Finder and select the share on the server. That'll do the trick for instant access or manual connect. If you want to have your shares mapped before you logon do the following:
1. Create Script, which mounts your shares (see my sample below)
2. Add the script to the LoginHook
sudo defaults write com.apple.loginwindow LoginHook /path/to/script
(I store my script on MacOSX in /Library/Scripts). More infos on the LoginHook.
Note: If you mount a share keep in mind that mounting the share with root privileges will only allow root to use the share. Because of that I used su $1 -c to run the mount as the current logged in user.
1. Create Script, which mounts your shares (see my sample below)
2. Add the script to the LoginHook
sudo defaults write com.apple.loginwindow LoginHook /path/to/script
(I store my script on MacOSX in /Library/Scripts). More infos on the LoginHook.
Note: If you mount a share keep in mind that mounting the share with root privileges will only allow root to use the share. Because of that I used su $1 -c to run the mount as the current logged in user.
Sample mount script for a NAS server with afp protocol for Mac OSX (if your NAS has no afp just change the mount parameter accordingly):
#!/bin/bash
# Information about the NAS access
username=MY_NAS_USER
password=MY_NAS_PASS
hostname=MY_NAS_HOST
# The $1 is within login scripts the current user, which enters MacOsx
loginuser=$1
# Create a mount dir if necessary
save_mkdir() {
if [ ! -d $1 ];
then
su $loginuser -c "mkdir $1"
fi
}
# Create a mount as the current logged in user
do_mount() {
if /sbin/mount|grep -q $1; then
# echo "Mounted"
/sbin/umount $1
fi
save_mkdir $1
su $loginuser -c "/sbin/mount -t afp afp://$username:$password@$hostname/$2 $1"
}
echo "******************************************************"
echo "*** Unmount all network drives from boshuda"
echo "******************************************************"
/sbin/umount /Volumes/pictures
/sbin/umount /Volumes/music
echo "******************************************************"
echo "*** Mount all network drives from boshuda"
echo "******************************************************"
do_mount /Volumes/pictures pictures
do_mount /Volumes/music my_music
Dienstag, 2. Februar 2010
Include the output of a servlet within your jsp
Sometimes its useful to call a servlet and include the output of the servlet within your jsp page. The easiest way to call a servlet from a jsp is the jsp:include tag. Lets assume you have a jsp fragment like this
this will cause a call to the InfoServlet with the parameter name and the value VERSION. The output will be written by the InfoServlet.
HINT:
The calling servlet has to use the same access method to the response as the jsp and should not close the stream. Otherwise the output of your jsp will stop immediately.
So if you don't know just use response.getOutputStream() to write to the response.
...
VERSION: <jsp:include page="/InfoServlet?name=VERSION"></jsp:include>
..
this will cause a call to the InfoServlet with the parameter name and the value VERSION. The output will be written by the InfoServlet.
HINT:
The calling servlet has to use the same access method to the response as the jsp and should not close the stream. Otherwise the output of your jsp will stop immediately.
So if you don't know just use response.getOutputStream() to write to the response.
Abonnieren
Posts (Atom)