Showing posts with label java. Show all posts
Showing posts with label java. Show all posts

Tuesday, 29 April 2014

Netbeans: There and back again - a tale of frustration, anger and returning to grace

(previously titled: Bye Eclipse the preventor of development, hello Netbeans...)

As always this is mainly for my future self as reference, as I don't seemed to have learned from the same experience that I had previously:(

Don't try to manually add dependencies to the tomcat classpath.

I lost the battle against eclipse + tomcat/tomee + maven

The fact that it works to add your main war dependency to the classpath with the maven library this time, does not mean it will work if you add more. I found that eclipse get's completely confused and this causes problems for things that insist that you may only have one copy of any class in your classpath, eg. slf4j, openejb's faces implementation etc.


Anyways, I'm fed up, fueclipse ┌∩┐(◣_◢)┌∩┐  

Until now I didn't really want to switch to netbeans because it doesn't support my favourite version control system (bazaar) and limited lombok support and I didn't really want to re-learn things/qwirks I spent years learning in eclipse like keyboard shortcuts, configuration, classpath settings etc.
Anyways eclipse makes me so mad sometimes and I think the camel's back has finally been broken. I tried to switch previously but had trouble getting my stuff to work quickly, I think I'm more patient/desperate this time..

Some stuff I've figured out with Netbeans so far - i.e a cryptic Netbeans guide for ex-Eclipse-users (please vote on the bugs I link to!):

  • you can use a use the eclipse keyboard shortcut profile, so for now I don't have to re-learn shortcuts and keep some productivity.
  • maven multi module support works beautifully
  • mvn install happens when you do a netbeans build!
  • Reload POM, seems to be needed sometimes like the "Maven -> update project"
  • adding a tomee server is simple http://tomee.apache.org/tomee-and-netbeans.html
  • you can collapse all, by right-clicking in the white space next to  the file tree (eclipse has a handy everpresent button for that)
  • Netbeans seem a lot snappier than eclipse!
  • Committing with Git works better in Netbeans, because it allows you to modify the files while you are typing your commit message (eg. for fixing typos). I would have like to not manually click to see every file, maybe a open all button would help. I still love the qbazaar/bazaar-explorer's commit gui which give you the whole list of changes in one huge scrollable panel - saves a lot of clicks and navigations. For now I just look at the colordiff in the commandline to approximate that behaviour :(
    • One thing I miss with the Git commit ui in Netbeans, is to be able to push at the same time - Eclipse has a button `Commit and Push`. 
    • It would also have been nice to get some floating/fading notification if the commit/push went well. If you don't watch the statusbar and spot the progressbar disappear you have no indication if it worked..
  • Console scrolling works more intuitively and seemlessly: if you scrolled to the bottom it will keep on scrolling as more output comes out, but if you scroll up it stops auto-scrolling. In eclipse you have to click a checkbox to make the choice between auto-scrolling and not.
  • Project groups seems to work nicely and you can use the Cool Editor Actions plugin to quickly switch between them.
  • Dragging panels around seems to work a bit better than in Eclipse. Eg. sticking an editor in the console tabsheet.
  • It does have bazaar plugin ?! It looks similar to the eclipse qbazaar plugin - it is a thin wrapper around qt frontends for the bazaar commands - very nice!
  • Running more than one instance. I figured out you have to specify a --userdir for the second one and that it can't be the same as your main user dir. I tried to symlink it but that didn't work, so I made a little script that copies it:
    VERSION=8.0
    A=$HOME/.netbeans/${VERSION}
    B=${A}_B
    rm -rf ${B}
    cp -a ${A} ${B}
    /opt/netbeans-${VERSION}/bin/netbeans --userdir ${B} &
    
  • ALT+3 to copy project or file path
Things I miss so far (maybe I'm missing something):
  • Control clicking on a maven artifact reference in a pom file would jump to the relevant pom file.
  • File manager doesn't remember recent locations :( so every time I look for my tomee server, or projects I need to navigate from home :( It would have been better to use the native linux file chooser. My current workaround is the Quick File Chooser - plugin : "file chooser optimized for keyboard-only users. Performs GNU Readline-style filename completion when you press Tab. Shows available completions in a list for quick reference, similar to Emacs. Also includes a persistent list of recently used directories for extra speed." (it works in Netbeans8 if you download v7.4 manually and install it)
  • After installing some plugins and making some configurations it refused start up again. Then I accidentally purged ~/.netbeans :( and it worked again. This happend again so I logged a bug and figured out what triggers it. Back to work now finally, damnit!
  • Searching in the output console is a bit frustrating but CTRL+F and the CTRL+N seems to work ok now.
  • There is no auto-closing of editors. In eclipse you can tell it to close old editors after you have a certain amount open. It gets messy if netbeans keeps like every single file you clicked open - I go through hundreds. I found sort of a workaround in Window->Documents where you can order by last used, then select the bottom bunch and then close them in one go..
  • mylyn is also missed - it helps you focus by hiding some of the project clutter a bit from you while you are working.. Project groups seem to be the closest workable alternative.
  • I like eclipse's run infrastructure better. eg. you can easily run whatever you ran previously (but there are some run shortcuts, so I may get used to it) Found it : ALT+r p
  • Junit test compare in eclipse you can show you a nice diff when assertEquals(String,String) fails..
  • In eclipse you can click on stack trace elements in the console and it would open the file, in netbeans it seems to be a manual proccess :(
  • Test Runner chops off exceptions :(
  • Java Stack Trace console (where you can past any stacktrace and get links)
  • Efficient dependency hierarchy to figure out maven dependency hell

http://www.wikivs.com/wiki/Eclipse_vs_Netbeans

I've been with eclipse since at least 2006.
Living with eclipse is like living with an abusive husband, sure you get a black eye from time to time, but you are so dependant that you end up staying. It caused me numerous sleepless nights and missed deadlines :( not to mention it literally driving me insane. t(-.-)

Back to Eclipse!

After that whole laborious move the development cycle in netbeans was just insanely long for my project setup (a couple of layers of war dependenices/overlays which each need to be built for deploying every small change). I bit the bullet and figured out how to do proper OpenEJB and TomEE embedding so I don't need WTP anymore with its' nasty classpath idiosyncrasies.

Thursday, 7 March 2013

Set zoomlevels for gwt-openlayers and openstreetmap

I tried to make the zoom level bar show the same number of zoom levels as my offline cache and I'm shocked at how little information is out there about this.

The method below is doing the trick for me now:

/**
     * @param options
     * @param minZoomLevel the minimum for this is 3 for open streetmap
     * @param maxZoomLevel
     */
    private static void setZoomLevelRange(LayerOptions options,
        int minZoomLevel, int maxZoomLevel) {
        options.getJSObject().setProperty("zoomOffset", minZoomLevel);

        int len = maxZoomLevel - minZoomLevel + 1;
        double[] resolutions = new double[len];
        double curRes = 78271.51695 / (Math.pow(2, minZoomLevel - 1));
        for (int i = 0; i < len; i++) {
            resolutions[i] = curRes;
            curRes = curRes / 2;
        }

        options.setResolutions(resolutions);
    }


// usage example:
        OSMOptions osmOptions = new OSMOptions();
      
        setZoomLevelRange(osmOptions, 5, 11);
      
        OSM baseTileLayer = new OSM("Mapnik", 
          // for offline tiles:
          GWT.getHostPageBaseURL()
            + "tiles/${z}/${x}/${y}.png", 
          osmOptions);



The keys are:

  1. there is apparently a magic zoom level 1 resolution (I have not found how it is calculated).
  2. you can add higher and lower resolutions by multiplying or dividing them by 2.
  3. it is critical that you set the zoomOffset in accordance to what you use as your  minimum zoom level.

Your welcome and yeah you may copy the code as you want.

References:



Saturday, 1 September 2012

fun with self-signed certs and java and maven again :S

I've been deploying maven artifacts all day and suddenly it stopped working (later I realized that I happen to apt-get update java in between).

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy (default-deploy) on project browser-cookies: Failed to deploy artifacts/metadata: No connector available to access repository xxx.xxx of type default using the available factories WagonRepositoryConnectorFactory -> [Help 1]

[ERROR] For more information about the errors and possible solutions, please read the following articles:

[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

So after googling a bit I though wagon might be the problem again so I added the following to my pom:


...


org.apache.maven.wagon
wagon-ssh
2.2

...


But my problems didn't go away:(
Then I realized that since I just upgraded my java, that my company maven repo's certificate may not be installed anymore..

I tried to install it with the normal way:
java -jar import-ssl.jar server [https://YOURSERVERURL] 

java -jar import-ssl.jar server maven.example.com $JAVA_HOME/jre/lib/security/cacerts

But this resulted in the following error:

Loading KeyStore /usr/lib/jvm/java-7-oracle/jre/lib/security/cacerts...
Setting up SSL...
Opening connection to https://maven.example.com:443...
java.net.UnknownHostException: https://maven.example.com

at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:178)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:391)
at java.net.Socket.connect(Socket.java:579)
at sun.security.ssl.SSLSocketImpl.connect(SSLSocketImpl.java:618)
at sun.security.ssl.SSLSocketImpl.(SSLSocketImpl.java:407)
at sun.security.ssl.SSLSocketFactoryImpl.createSocket(SSLSocketFactoryImpl.java:88)
at com.sonatype.component.ssl.imprt.ImportServerCertificates.doImport(ImportServerCertificates.java:154)
at com.sonatype.component.ssl.imprt.ImportServerCertificates.run(ImportServerCertificates.java:66)
at com.sonatype.component.ssl.imprt.Main.main(Main.java:51)

I was puzzled because this worked fine with java-6-openjdk-amd64,  but not with java-7-oracle. For kicks I tried the IP address and guess what it worked!!!!

java -jar import-ssl.jar server 192.0.2.1 $JAVA_HOME/jre/lib/security/cacerts 

Loading KeyStore /usr/lib/jvm/java-7-oracle/jre/lib/security/cacerts...
Setting up SSL...
Opening connection to 192.0.2.1:443...
Starting SSL handshake...

Some SSL certificates appear to be missing. Adding missing certificates...

Server sent 1 certificate(s):
 1 Subject CN=maven.example.com, O=MyCompany, L=Johannesburg, ST=Gauteng, C=ZA
   Issuer  CN=maven.example.com, O=MyCompany, L=Johannesburg, ST=Gauteng, C=ZA

Added certificate to keystore using alias: '192.0.2.1'


But alas I could still not deploy :'(
I threw my toys out of my cot, took a deep breath, bathed my 19 month old son, came back and realized what my problem was:

I put a nasty safety mechanism into my corporate poms to prevent us from deploying stuff to the wrong repository (eg. deploying private source files to a public repository!). Anyways I now added a BIG glaring message for myself for when this happens again:

 NB!


 NB! REMEMBER TO SPECIFY -Dew.deploy-public TO DEPLOY THIS PUBLICLY OR -Dew.deploy-private TO DEPLOY THIS PRIVATELY


Don't say I didn't try to tell you!!!!?! 

Saturday, 31 October 2009

Project Lombok: Put an End to Java Verbosity

If you're interested in java programming involving lots of beans, this is a crazy cool tool.

Its a combination of a compile-time and a development-time code generator, which has made Java POJO verbosity history.
It uses annotation magic to implement all the repetitive boring bean methods (getters, setters, equals, hashCode, toString)
without them actually cluttering your classes. Thats right it generates invisible code!

Now you have to watch the video at:
http://projectlombok.org/

You can reed this introductory article:
http://www.devx.com/Java/Article/42946/1954

See some other cool examples to look at:
http://projectlombok.org/features/Data.html
http://projectlombok.org/features/Cleanup.html (I was trying to implement this one just a couple of weeks ago)
http://projectlombok.org/features/EqualsAndHashCode.html

I came across lombok while trying to figure out if I can get eclipse to also generate the .equals and .hashCode methods
on new JPA entities like netbeans does. turns out it I don't really need that any more.

Wednesday, 20 May 2009

Hibernate freeze

All of a sunday my hibernate queries started to freeze when I try to run my unit tests at:
SocketInputStream.socketRead0(FileDescriptor, byte[], int, int, int) line: not available [native method]
Turns out I had the table or something locked in Sqldeveloper. I killed that session and everything started to work again.

Wednesday, 12 November 2008

java.net.SocketException: Too many open files

We hit this again on sles today, so I thought I should leave a note here for posterity.
java.io.FileNotFoundException: /home/tcmas/tomcat/5.0.28/work/Catalina/localhost/balancer/SESSIONS.ser (Too many open files)

  1. It might be caused by the small amount of memory available! so increasing that, may fix it.
  2. It may also be the the number of open files limit on linux:
Increase file descriptor limit under Linux to prevent java.net.SocketException: Too many open files

Get current limit:

ulimit -n

cat /proc/sys/fs/file-nr

The default limit is 1024.

Get current number of open file descriptors:

lsof [-p pid] | wc -l

Increase the limit:

Edit /etc/security/limits.conf:

username hard nofile 32768

http://hausheer.osola.com/docs/11