lunedì 11 aprile 2016

How to make SQL tables case insensitive in Ubuntu

Open terminal and edit /etc/mysql/my.cnf
sudo nano /etc/mysql/my.cnf
Underneath the [mysqld] section.add:
lower_case_table_names = 1
Restart mysql
sudo /etc/init.d/mysql restart
Then check it here:
mysqladmin -u root -p variables

domenica 10 aprile 2016

Linux 101: how to set a static IP on Ubuntu 15

First, discover which is the gateway you have to refer to by calling:
$ ip route show
This will show you something like this:
default via ip.gateway.address.something dev eth0

Now, edit sudo nano /etc/network/interfaces with the following:
auto lo eth0
iface lo inet loopback
iface eth0 inet static
        address xxx.xxx.xxx.xxx(enter your ip here)
        netmask xxx.xxx.xxx.xxx
        gateway xxx.xxx.xxx.xxx(enter gateway ip here,usually the address of the router)
        dns-nameservers 8.8.8.8

Finally, restart the network interface as follows:
systemctl restart ifup@eth0
and check that everything is fine by calling
ifconfig

Finally, ping google.com :)

giovedì 24 marzo 2016

How to move a web project from Glassfish to Tomcat?

Today I stumbled upon a web project that was configured for Glassfish instead of Tomcat. Since I am very fond of Tomcat, which integrates perfectly with my Eclipse IDE, I did not want to change my forma mentis and tools just to comply with the former configuration.

Unfortunately, when I tried to launch the project, it was not reading properly static resources (e.g., CSS files), since Glassfish has an XML configuration file (which is a substitute of the plain old web.xml file) in which you specify the context root of your project, i.e.:

http://localhost:8080/context-root/the-page-you-want

Tomcat is configured so as to use as context root the name of the project. So, how to fix this?
A solution can be found here, and is applied as follows:

  1. Project -> Properties -> Web Project Settings
  2. Modify the context root with the name you want and confirm
  3. Stop Tomcat
  4. Clean the Tomcat server by right-clicking on the server itself and selecting Clean
  5. Restart the server
  6. Confirm that you want to change the context root
...and you are done!

venerdì 11 marzo 2016

Use JPA with Maven projects in Eclipse

Want to build your own metamodel in Eclipse?

Prerequisite: use EclipseLink
Add the following to your pom.xml file:


        <dependency>
            <groupId>org.eclipse.persistence</groupId>
            <artifactId>eclipselink</artifactId>
            <version>2.5.1</version>
            <scope>provided</scope>
        </dependency>

First step: Modify your pom.xml file
The pom.xml file has to be modified to include the following plugin:

            <plugin>
                <groupId>org.bsc.maven</groupId>
                <artifactId>maven-processor-plugin</artifactId>
                <version>2.2.4</version>
                <executions>
                    <execution>
                        <id>process</id>
                        <goals>
                            <goal>process</goal>
                        </goals>
                        <phase>generate-sources</phase>
                        <configuration>
                            <processors>
                                <processor>org.eclipse.persistence.internal.jpa.modelgen.CanonicalModelProcessor</processor>
                            </processors>
                            <outputDirectory>${project.build.directory}/generated-sources/meta-model</outputDirectory>
                        </configuration>
                    </execution>
                </executions>
                <dependencies>
                    
                    <dependency>
                        <groupId>org.eclipse.persistence</groupId>
                        <artifactId>org.eclipse.persistence.jpa.modelgen.processor</artifactId>
                        <version>2.6.1</version>
                    </dependency>
                </dependencies>
            </plugin>

Second step: add the Generated-sources folder
Then, open the project properties and move to Java Build Path. In the "Source" tab, select "Add folder" and then add "target/generated-sources".
Build the project.

Third step: compile
Finally, again in project properties, select the JPA menu, select EclipseLink as a platform, allow Discover annotated classes automatically, and then press Apply. From this point on, the generated-sources folder should contain your compiled metamodel.

lunedì 29 febbraio 2016

What is a model? A nice definition

Eric Evans, during this talk about Domain-Driven Design (DDD), defines nicely a model as

a system of abstractions that describes selected aspects of a domain and can be used to solve problems related to that domain

mercoledì 10 febbraio 2016

CPM tutorial

You can find a nice and practical guide to the Critical Path Method here.

JPA in Eclipse: drop database at each test

If you want to drop your database at each test launch, open the file persistence.xml (under JPA) and modify the following line:

 <property name="javax.persistence.schema-generation.database.action" value="create"/>

to become as follows:

 <property name="javax.persistence.schema-generation.database.action" value="drop-and-create"/>