Pages

Sunday, September 29, 2013

java.lang.NoSuchMethodError: antlr.collections.AST.getLine()

After adding Velocity to my Spring Web Application, I'm getting this error:


29.09.2013 22:44:26  WARN (AbstractMessageListenerContainer.java:696) - Execution of JMS message listener failed, and no ErrorHandler has been set.
java.lang.NoSuchMethodError: antlr.collections.AST.getLine()I

...

The error is due by the conflicts between two differents version of "antlr". You need to exclude the version from velocity-tool.

So add the following exclusion to the velocity-tools maven dependency.


  <dependency>
            <groupId>org.apache.velocity</groupId>
            <artifactId>velocity-tools</artifactId>
            <version>2.0</version>
            <exclusions>
                <exclusion>
                    <artifactId>antlr</artifactId>
                    <groupId>antlr</groupId>
                </exclusion>
            </exclusions>
   </dependency>

Wednesday, September 25, 2013

Tar following symlinks

Hi!

Suppose that we have to tar gzip a directory that contains two symlinks.

ROOT_DIRECTORY
     SYMLINK_A
     SYMLINK_B



SYMLINK_A
     FILE_A
     FILE_B

SYMLINK_B
     FILE_C
     FILE_D



If you use the usual command tar -zcvf ROOT_DIRECTORY.tgz ROOT_DIRECTORY

You will get an archive that contains two symbolic links.

ROOT_DIRECTORY
     SYMLINK_A
     SYMLINK_B



If you want to include the content of symbolic links, you need to add a "h" just after the "c",

The command is tar -zchvf ROOT_DIRECTORY.tgz ROOT_DIRECTORY

You will get the directory including all the files under the ROOT_DIRECTORY

ROOT_DIRECTORY
     SYMLINK_A
          FILE_A
          FILE_B

     SYMLINK_B
          FILE_C
          FILE_D


Thursday, September 19, 2013

Nice Grep tool for Windows - grepWin

Hi!

I've found a great tool to do greps in Windows.




Please have a look at https://code.google.com/p/grepwin/

Thursday, September 12, 2013

Ruby Application Server - Installation notes for Nginx and Passenger

Hi!

Here's how to install Passenger and Nginx. You will get a very fast Ruby application server.

Compile nginx :
tar -xzvf nginx-1.3.14.tar.gz
cd nginx-1.3.14
./configure --prefix=/etc/nginx --with-http_ssl_module

cd /etc/init.d/
ln -snf /etc/nginx/sbin/nginx

Compile passenger :

cd /usr/local/ruby/bin
./passenger-install-nginx-module

 1. Yes: download, compile and install Nginx for me. (recommended)
    The easiest way to get started. A stock Nginx 1.0.6 with Passenger
    support, but with no other additional third party modules, will be
    installed for you to a directory of your choice.

 2. No: I want to customize my Nginx installation. (for advanced users)
    Choose this if you want to compile Nginx with more third party modules
    besides Passenger, or if you need to pass additional options to Nginx's
    'configure' script. This installer will  1) ask you for the location of
    the Nginx source code,  2) run the 'configure' script according to your
    instructions, and  3) run 'make install'.

Whichever you choose, if you already have an existing Nginx configuration file,
then it will be preserved.

Enter your choice (1 or 2) or press Ctrl-C to abort: 2

The next step is to point passenger to the source directory. Is this example, the source is in my home folder so it’s -> /home/xxx/nginx-1.3.14.

Than point the installation of nginx to /etc/nginx

Passenger is now installed. Here’s what your nginx config should look like this:
____________________________________________
worker_processes  2;

error_log  logs/error.log  debug;

#pid        logs/nginx.pid;

events {
    worker_connections  2000;
}

http {
    passenger_root /usr/local/ruby-1.8.7-p352/lib/ruby/gems/1.8/gems/passenger-3.0.9;
    passenger_ruby /usr/local/ruby-1.8.7-p352/bin/ruby;
    passenger_max_pool_size 3;

    include       mime.types;
    default_type  application/octet-stream;

    sendfile        on;
    #tcp_nopush     on;

    keepalive_timeout  65;

  server {
     listen 8666;
     server_name localhost;
    
     root /data/opt/local/ruby/myapp/public/;   # <--- be sure to point to 'public'!
     passenger_enabled on;
     passenger_use_global_queue on;

     auth_basic "myapp Access"; # <--- For password auth
     auth_basic_user_file /home/myapp/passwd;
    
   }

     #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
}
______________________________________________________
Start:
/etc/init.d/nginx

Stop :
/etc/init.d/nginx -s stop

Tuesday, September 10, 2013

JPA / Hibernate - On Delete Set NULL

It's impossible to configure a ON DELETE SET NULL with JPA / Hibernate.

To achieve this, you could define a @PreRemove method that specify the fields to set NULL.

Here's an example:

...

/**
 * The persistent class for the user database table.
 */
@Entity
@Table(name = "`user`")
public class User implements Serializable {
    private static final long serialVersionUID = 1L;

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(unique = true, nullable = false)
    private Long id;

    @Column(length = 255)
    private String address;

    @Column(length = 255)
    private String city;

    @Column(nullable = false, length = 2)
    private String country;

    @Column(nullable = false, length = 255)
    private String email;

    @Column(name = "is_active", nullable = false)
    private Boolean isActive;

    @Column(nullable = false, length = 255)
    private String name;

    @Column(nullable = false, length = 40)
    private String password;

    @Column(length = 15)
    private String phone;

    @Column(name = "postal_code", length = 7)
    private String postalCode;

    @Column(nullable = false, length = 2)
    private String province;

    @Column(length = 1)
    private String role;

    @ManyToMany
    @JoinTable(
            schema = "stratageme_ca",
            name = "favourite_product"
            , joinColumns = {
            @JoinColumn(name = "user_id", nullable = false)
    }
            , inverseJoinColumns = {
            @JoinColumn(name = "product_id", nullable = false)
    }
    )
    private List<Product> products;

    @OneToMany(mappedBy = "user")
    private List<PurchaseOrder> purchaseOrders;

    @OneToOne(mappedBy = "user")
    private SavedCart savedCart;

    @OneToMany(mappedBy = "specialist")
    private List<Store> storesSpecialist;


    @OneToMany(mappedBy = "director")
    private List<Store> storesDirector;

    @OneToMany(mappedBy = "vp")
    private List<Store> storesVp;

    @OneToMany(mappedBy = "conseiller")
    private List<Store> storesConseiller;

    @OneToMany(mappedBy = "user")
    private List<Territory> territories;

    @ManyToOne
    @JoinColumn(name = "all_under_banner_id")
    private Banner banner;

    @ManyToOne
    @JoinColumn(name = "title_id")
    private Title title;

    public User() {
    }

    public Long getId() {
        return this.id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getAddress() {
        return this.address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public String getCity() {
        return this.city;
    }

    public void setCity(String city) {
        this.city = city;
    }

    public String getCountry() {
        return this.country;
    }

    public void setCountry(String country) {
        this.country = country;
    }

    public String getEmail() {
        return this.email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public Boolean getIsActive() {
        return this.isActive;
    }

    public void setIsActive(Boolean isActive) {
        this.isActive = isActive;
    }

    public String getName() {
        return this.name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getPassword() {
        return this.password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getPhone() {
        return this.phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    public String getPostalCode() {
        return this.postalCode;
    }

    public void setPostalCode(String postalCode) {
        this.postalCode = postalCode;
    }

    public String getProvince() {
        return this.province;
    }

    public void setProvince(String province) {
        this.province = province;
    }

    public String getRole() {
        return this.role;
    }

    public void setRole(String role) {
        this.role = role;
    }

    public List<Product> getProducts() {
        return this.products;
    }

    public void setProducts(List<Product> products) {
        this.products = products;
    }

    public List<PurchaseOrder> getPurchaseOrders() {
        return this.purchaseOrders;
    }

    public void setPurchaseOrders(List<PurchaseOrder> purchaseOrders) {
        this.purchaseOrders = purchaseOrders;
    }

    public SavedCart getSavedCart() {
        return this.savedCart;
    }

    public void setSavedCart(SavedCart savedCart) {
        this.savedCart = savedCart;
    }


    public List<Store> getStoresSpecialist() {
        return storesSpecialist;
    }

    public void setStoresSpecialist(List<Store> storesSpecialist) {
        this.storesSpecialist = storesSpecialist;
    }

    public List<Store> getStoresDirector() {
        return storesDirector;
    }

    public void setStoresDirector(List<Store> storesDirector) {
        this.storesDirector = storesDirector;
    }

    public List<Store> getStoresVp() {
        return storesVp;
    }

    public void setStoresVp(List<Store> storesVp) {
        this.storesVp = storesVp;
    }

    public List<Store> getStoresConseiller() {
        return storesConseiller;
    }

    public void setStoresConseiller(List<Store> storesConseiller) {
        this.storesConseiller = storesConseiller;
    }

    public List<Territory> getTerritories() {
        return this.territories;
    }

    public void setTerritories(List<Territory> territories) {
        this.territories = territories;
    }

    public Banner getBanner() {
        return this.banner;
    }

    public void setBanner(Banner banner) {
        this.banner = banner;
    }

    public Title getTitle() {
        return this.title;
    }

    public void setTitle(Title title) {
        this.title = title;
    }


    /**
     * Pre Remove to set ON DELETE SET NULL
     */
    @PreRemove
    public void preRemove(){
        for(Store s : storesConseiller){
            s.setConseiller(null);
        }

        for(Store s : storesSpecialist){
            s.setSpecialist(null);
        }

        for(Store s : storesDirector){
            s.setDirector(null);
        }

        for(Store s : storesVp){
            s.setVp(null);
        }

    }


}

Monday, September 9, 2013

Linux - find file in specific directory

If you want to search for all files under a specific directory and remove them, you could use the following command:

find . -type f -wholename '*/DIRECTORY/*' -exec rm -rf {} \;

Where DIRECTORY is the name of your directory.

For example, you will be able to find all theses files


/home/toto/test/DIRECTORY/toto.txt
/home/toto/test1/DIRECTORY/tata.txt
/home/toto/test2/DIRECTORY/titi.txt

You must execute the command from /home/toto

Friday, September 6, 2013

Eclipse / SVN - Attempted to lock an already-locked dir

After an Eclipse crash, impossible to commit / update files. I'm getting this error

org.apache.subversion.javahl.ClientException: Attempted to lock an already-locked dir
svn: Working copy 'D:\XXX' locked.
svn: 'D:\XXX' is already locked.



In Eclipse- Right Click- Team / Refresh Cleanup