Categories
discuss

How to integrate maven generated vaadin project into eclipse vaadin plugin?

Eclipse Vaadin plugin has cool autobuild feature. Just clicking “restart application” in debug console will bring up to date application version to live.

Unfortunately importing maven generated vaadin project(using m2e) and copy-pasting .project buildCommands and natures from vaadin eclipse plugin generated project does not works.

I’m unnable to “Run on server…”, tomcat does not deploy app for unknown reason. I can see app in wtpapps folder but it still does not deploys.

Answer

You can build your Vaadin app as a regular Java library, by itself (not as a WAR, or anything complicated). Then do two things: Create another project that builds the actual WAR file, and create another project that sets up Jetty for direct execution (google for details on how to get Vaadin operating under Jetty standalone, using Jetty as a library). With that in place you can treat your Vaadin UI like a regular java program (fast, direct restart through the standard debug window), and still have it be a WAR file for deployment.

See this thread for details on how to set up Jetty (look for Launcher).

Categories
discuss

Android – Adding external library to project

I am having a lot of trouble adding the WEKA library to a project I am working on. I have followed several tutorials that explain how to do this including the Android Developers guide:

http://developer.android.com/guide/appendix/faq/commontasks.html#addexternallibrary

and several of the postings on SO.

I have created a folder in my project with the weka.jar file, created a new library (adding the weka.jar file to the library) and included this library in my build path. I have also added the library under the “Order and Export” tab in the project properties.

I have also tried importing the jar file so that the actual contents of the jar are extracted into a directory in my project.

The end result of all of this is that my project is able to build correctly and without error, but when it comes time to run my code on the emulator I get the following exception:

04-10 22:52:21.051: ERROR/dalvikvm(582): Could not find class ‘weka.classifiers.trees.J48’, referenced from method edu.usc.student.composure.classifier.GaitClassifierImpl.

with J48 being the class I reference in my code.

Does anyone have any additional suggestions that I may have overlooked?

Thanks!

Answer

WEKA is not going to work on Android without changes. J48, for example, requires the java.lang.Cloneable interface, which is not available in Android.

What you need to do is check out the WEKA source code from Subversion, add it to your project (removing the JAR file), compile it, and fix all the compile errors. There may be quite a few of these.

Categories
discuss

Call a JavaScript function across browser tabs

I have two browser tabs, tab1 and tab2.

I have a function called execute in tab1, which I would like to call from the page in tab2.

Is that possible and if so how?

Answer

JavaScript can not do cross-tab scripting in the browser (it is a security risk).

If however the second tab was opened from a window.open() call, and the browsers settings were set up such that new popup windows open in a new tab instead — then yes, “tab1” can talk to “tab2”.

The first tab/window is called the opener and thus the new tab can call functions on the opener using this format:

opener.doSomething();

Likewise, the opener can call functions on the new tab/popup, by using the variable it created when creating the popup window.

var myPopup = window.open(url, name, features);
myPopup.doStuffOnPopup();
Categories
discuss

Does it make sense to do “try-finally” without “catch”?

I saw some code like this:

    try
    {
        db.store(mydata);
    }
    finally
    {
        db.cleanup();
    }

I thought try is supposed to have a catch?

Why does this code do it this way?

Answer

This is useful if you want the currently executing method to still throw the exception while allowing resources to be cleaned up appropriately. Below is a concrete example of handling the exception from a calling method.

public void yourOtherMethod() {
    try {
        yourMethod();
    } catch (YourException ex) {
        // handle exception
    }
}    

public void yourMethod() throws YourException {
    try {
        db.store(mydata);
    } finally {
        db.cleanup();
    }
}
Categories
discuss

Filling a byte array in Java

For part of a project I’m working on I am implementing a RTPpacket where I have to fill the header array of byte with RTP header fields.

  //size of the RTP header:
  static int HEADER_SIZE = 12; // bytes

  //Fields that compose the RTP header
  public int Version; // 2 bits
  public int Padding; // 1 bit
  public int Extension; // 1 bit
  public int CC; // 4 bits
  public int Marker; // 1 bit
  public int PayloadType; // 7 bits
  public int SequenceNumber; // 16 bits
  public int TimeStamp; // 32 bits
  public int Ssrc; // 32 bits

  //Bitstream of the RTP header
  public byte[] header = new byte[ HEADER_SIZE ];

This was my approach:

/*      
 * bits 0-1: Version
 * bit    2: Padding 
 * bit    3: Extension
 * bits 4-7: CC
 */
header[0] = new Integer( (Version << 6)|(Padding << 5)|(Extension << 6)|CC ).byteValue();

/* 
 * bit    0: Marker
 * bits 1-7: PayloadType
 */
header[1] = new Integer( (Marker << 7)|PayloadType ).byteValue();

/* SequenceNumber takes 2 bytes = 16 bits */
header[2] = new Integer( SequenceNumber >> 8 ).byteValue();
header[3] = new Integer( SequenceNumber ).byteValue();

/* TimeStamp takes 4 bytes = 32 bits */
for ( int i = 0; i < 4; i++ )
    header[7-i] = new Integer( TimeStamp >> (8*i) ).byteValue();

/* Ssrc takes 4 bytes = 32 bits */
for ( int i = 0; i < 4; i++ )
    header[11-i] = new Integer( Ssrc >> (8*i) ).byteValue();

Any other, maybe ‘better’ ways to do this?

Answer

I think I would use a ByteBuffer

ByteBuffer buf = ByteBuffer.wrap(header);
buf.setOrder(ByteOrder.BIG_ENDIAN);
buf.put((byte)((Version << 6)|(Padding << 5)|(Extension << 6)|CC));
buf.put((byte)((Marker << 7)|PayloadType));
buf.put((short)SequenceNumber);
buf.put(TimeStamp);
buf.put(Ssrc);
Source: stackoverflow
Text is available under the Creative Commons Attribution-ShareAlike License; additional terms may apply. By using this site, you agree to the Privacy Policy, and Copyright Policy. Content is available under CC BY-SA 3.0 unless otherwise noted. The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 © No Copyrights, All Questions are retrived from public domain..