SBT and Netbeans Terminal Emulator..

One of the new features that came bundled with Netbeans 6.9 is the terminal emulator. This provides a shell scripting interface for Netbeans users. This has been very useful especially with running build tools like maven from the terminal emulator without having to navigate out of the IDE.

To access this feature, go to ‘Window > Output > Terminal. For more on the Netbeans Terminal Emulator click here

SBT (simple build tool) appears to be one of the raves of the moment, it gradually has grown on me and i am using it in my current project which obviously is Scala based.

At the moment i do not know of any plugin for SBT on the Netbeans platform.

I Initially assumed that having successfully installed SBT on my computer that it would be easily accessible from the terminal emulator. But ‘Lo and Behold’ the Netbeans terminal emulator was not aware of SBT‘s location.

In order to get SBT running in the terminal emulator the following commands would be appropriate, especially for MAC or Unix based PCs and already have SBT running. If you don’t have SBT running already click here to set it up.



sudo echo "java -XX:+CMSClassUnloadingEnabled -XX:MaxPermSize=256m -Xmx512M -Xss2M -jar /include/here/path/to/the/sbt-launcher.jar \"\$@\"" | sudo tee /usr/bin/sbt #please don't forget to change the /include/here/path/to/the/sbt-launcher.jar to the relevant path on your system that points to the sbt launcher jar file.

whoami # this would tell you the current user if you already know the name skip this

cd /usr/bin # navigate to the /usr/bin folder

sudo chown username sbt # change owner to the required username on sbt. Also remember to change the username here  to the relevant one on you want to use
or alternatively

sudo chmod u+x sbt # this will give the required operation permission to the user

After this has been done navigate back to your Netbeans IDE’s terminal emulator and type sbt to enjoy it’s goodness within the Netbeans IDE.

CIAO for now..

Persisting many to many Relationship (JPA and Spring Strategy)

This post is inspired by the “Netbeans Generate Entity Class From Database” feature which literally spits out vanilla JPA Entity classes for you while you have some coffee. For many to many relationship types Netbeans reads and generates an JPA Entity class for the join table and an extra class which holds the Primary key values for the two tables involved in a many to many relationship. This class is annotated with the @Embeddable JPA annotation. This i found very cool.

In this post i would like to show how to persist data from the respective tables to the join table.

The database create statement for the chosen table goes as follows:

create table Author (author_id int(10) not null auto_increment, name varchar(55) not null, email varchar(55) not null, primary key (author_id));
create table Book (book_id int(10) not null auto_increment, name varchar(55) not null, publisher varchar(55) not null, primary key (book_id));
create table Author_Book (author_id int(10) not null, book_id int(10) not null, primary key (author_id, book_id));
alter table Author_Book add index FKAuthor_Boo670752 (author_id), add constraint FKAuthor_Boo670752 foreign key (author_id) references Author (author_id);
alter table Author_Book add index FKAuthor_Boo981679 (book_id), add constraint FKAuthor_Boo981679 foreign key (book_id) references Book (book_id);

Netbeans generates the following for you.. No skin pain :)

Class Author Entity

@Entity
@Table(name = "Author")
@NamedQueries({
    @NamedQuery(name = "Author.findAll", query = "SELECT a FROM Author a"),
    @NamedQuery(name = "Author.findByAuthorId", query = "SELECT a FROM Author a WHERE a.authorId = :authorId"),
    @NamedQuery(name = "Author.findByName", query = "SELECT a FROM Author a WHERE a.name = :name"),
    @NamedQuery(name = "Author.findByEmail", query = "SELECT a FROM Author a WHERE a.email = :email")})
public class Author implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "author_id")
    private Integer authorId;
    @Basic(optional = false)
    @Column(name = "name")
    private String name;
    @Basic(optional = false)
    @Column(name = "email")
    private String email;

    public Author() {
    }

    public Author(Integer authorId) {
        this.authorId = authorId;
    }

    public Author(Integer authorId, String name, String email) {
        this.authorId = authorId;
        this.name = name;
        this.email = email;
    }

    public Integer getAuthorId() {
        return authorId;
    }

    public void setAuthorId(Integer authorId) {
        this.authorId = authorId;
    }

    public String getName() {
        return name;
    }

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

    public String getEmail() {
        return email;
    }

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

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (authorId != null ? authorId.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Author)) {
            return false;
        }
        Author other = (Author) object;
        if ((this.authorId == null && other.authorId != null) || (this.authorId != null && !this.authorId.equals(other.authorId))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "com.testing.jsf.Author[authorId=" + authorId + "]";
    }

}

Class For Book Entity..

@Entity
@Table(name = "Book")
@NamedQueries({
    @NamedQuery(name = "Book.findAll", query = "SELECT b FROM Book b"),
    @NamedQuery(name = "Book.findByBookId", query = "SELECT b FROM Book b WHERE b.bookId = :bookId"),
    @NamedQuery(name = "Book.findByName", query = "SELECT b FROM Book b WHERE b.name = :name"),
    @NamedQuery(name = "Book.findByPublisher", query = "SELECT b FROM Book b WHERE b.publisher = :publisher")})
public class Book implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "book_id")
    private Integer bookId;
    @Basic(optional = false)
    @Column(name = "name")
    private String name;
    @Basic(optional = false)
    @Column(name = "publisher")
    private String publisher;

    public Book() {
    }

    public Book(Integer bookId) {
        this.bookId = bookId;
    }

    public Book(Integer bookId, String name, String publisher) {
        this.bookId = bookId;
        this.name = name;
        this.publisher = publisher;
    }

    public Integer getBookId() {
        return bookId;
    }

    public void setBookId(Integer bookId) {
        this.bookId = bookId;
    }

    public String getName() {
        return name;
    }

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

    public String getPublisher() {
        return publisher;
    }

    public void setPublisher(String publisher) {
        this.publisher = publisher;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (bookId != null ? bookId.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Book)) {
            return false;
        }
        Book other = (Book) object;
        if ((this.bookId == null && other.bookId != null) || (this.bookId != null && !this.bookId.equals(other.bookId))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "com.testing.jsf.Book[bookId=" + bookId + "]";
    }

}

Class for the join Table Author_Book

@Entity
@Table(name = "Author_Book")
@NamedQueries({
    @NamedQuery(name = "AuthorBook.findAll", query = "SELECT a FROM AuthorBook a"),
    @NamedQuery(name = "AuthorBook.findByAuthorId", query = "SELECT a FROM AuthorBook a WHERE a.authorBookPK.authorId = :authorId"),
    @NamedQuery(name = "AuthorBook.findByBookId", query = "SELECT a FROM AuthorBook a WHERE a.authorBookPK.bookId = :bookId")})
public class AuthorBook implements Serializable {
    private static final long serialVersionUID = 1L;
    @EmbeddedId
    protected AuthorBookPK authorBookPK;

    public AuthorBook() {
    }

    public AuthorBook(AuthorBookPK authorBookPK) {
        this.authorBookPK = authorBookPK;
    }

    public AuthorBook(int authorId, int bookId) {
        this.authorBookPK = new AuthorBookPK(authorId, bookId);
    }

    public AuthorBookPK getAuthorBookPK() {
        return authorBookPK;
    }

    public void setAuthorBookPK(AuthorBookPK authorBookPK) {
        this.authorBookPK = authorBookPK;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (authorBookPK != null ? authorBookPK.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof AuthorBook)) {
            return false;
        }
        AuthorBook other = (AuthorBook) object;
        if ((this.authorBookPK == null && other.authorBookPK != null) || (this.authorBookPK != null && !this.authorBookPK.equals(other.authorBookPK))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "com.testing.jsf.AuthorBook[authorBookPK=" + authorBookPK + "]";
    }

}

Below we have the class that holds the primary key values of the participating tables, also generated for you by netbeans:

@Embeddable
public class AuthorBookPK implements Serializable {
    @Basic(optional = false)
    @Column(name = "author_id")
    private int authorId;
    @Basic(optional = false)
    @Column(name = "book_id")
    private int bookId;

    public AuthorBookPK() {
    }

    public AuthorBookPK(int authorId, int bookId) {
        this.authorId = authorId;
        this.bookId = bookId;
    }

    public int getAuthorId() {
        return authorId;
    }

    public void setAuthorId(int authorId) {
        this.authorId = authorId;
    }

    public int getBookId() {
        return bookId;
    }

    public void setBookId(int bookId) {
        this.bookId = bookId;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (int) authorId;
        hash += (int) bookId;
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof AuthorBookPK)) {
            return false;
        }
        AuthorBookPK other = (AuthorBookPK) object;
        if (this.authorId != other.authorId) {
            return false;
        }
        if (this.bookId != other.bookId) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "com.testing.jsf.AuthorBookPK[authorId=" + authorId + ", bookId=" + bookId + "]";
    }

}

At this point in order to persist, we require a component, service and repository (DAO) objects to do this.
For the view component, what ever is your web framework of choice, be it jsf, spring mvc, gwt or wicket, etc all you need to do is inject the service and call the respective method for saving that you have defined in your service object. the below is based on JSF.

Note: at this point you need to persist both sides of the divide at the same time (the join table entity in this case AuthorBook and anyone of the participating sides). For the AuthorBook Entity you instantiate the constructor for the join table entity class that accepts the ids of the participating table (for this example this is achieved by passing to the constructor the get method for retrieving the ids for the participating tables for the join table.) Like this

authorBookService.save(new AuthorBook(book.getBookId(), author.getAuthorId())); 

The code for this goes as follows:

@Component
@Scope("request")
public class ComponentBean implements Serializable {

    private AuthorBook authorbook = new AuthorBook();
    private Author author = new Author();
    private Book book = new Book();
    private AuthorService authorSerivce;
    private AuthorBookService authorbookSerivce;

    @Autowired
    public ComponentBean(AuthorService authorSerivce, AuthorBookService authorbookSerivce) {
        this.authorSerivce = authorSerivce;
        this.authorbookSerivce = authorbookSerivce;
    }

    public Author getAuthor() {
        return author;
    }

    public void setAuthor(Author author) {
        this.author = author;
    }
public void setAuthorbook(AuthorBook authorbook) {
        this.authorbook = authorbook;
    }
 public AuthorBook getAuthorbook() {
 return authorbook;
 }

 public void setBook(Book book) {
 this.book = book;
 }
public Book getBook() {
        return book;
    }
public void save(ActionEvent actionEvent) {
 authorService.save(author);
 authorBookService.save(new AuthorBook(book.getBookId(), author.getAuthorId())); // you instantiate the constructor for the join table entity  class and pass it the get method for retrieving the ids for the participating tables for the join table

 }
}

Service interface to define the the save operation:

public interface AuthorBookService {

public void save(AuthorBook authorBook);
}

Next the implementation for the AuthorBookService Service Interface:


@Service("authorBookService")
public AuthorBookServiceImpl implements AuthorBookService  {
private AuthorBookDAO authorbookdao;
@Autowired
public ModelServiceImpl(AuthorBookDAO authorbookdao) {
        this. authorbookdao = authorbookdao;
    }
    @Transactional
    public void save(AuthorBook authorBook) {
        authorbookdao.persist(AuthorBook authorBook);
    }
}

The Data Access object interface:

public interface AuthorBookDAO {

public void persist(AuthorBook authorBook);
}

The Data Access object implementation proper:

@Repository
public class AuthorBookDAOImpl implements ModelDAO {

    @PersistenceContext
    protected EntityManager entityMgr;

    public EntityManager getEntityMgr() {
        return entityMgr;
    }

    public void setEntityMgr(EntityManager entityMgr) {
        this.entityMgr = entityMgr;
    }

    public void persist(AuthorBook authorBook) {

      this.entityMgr.persist(authorBook)

    }
}

Note: the service and repository for Author and Book will follow the same pattern. See the my previous blog post for more hints.. Ciao for now..

Populating JSF Combo Box with Database values. (or drop down list)…

I am presently working on my AISD project, and i am using jsf(primefaces) spring and jpa to build the system. i would like to commend the efforts of the brains behind jsf 2.0 and primefaces (1.* and 2.*) :) in particular for making the life of java web devs much easier. I remember back in the days the first versions of jsf were simply nightmares, which lead my cohorts and i  to move to frameworks like wicket :) .

This blog post seeks to show how to populate a jsf Combo box with values from a database table and also you would notice that the implementation for this case includes both jsf 1.* and jsf 2.*. I assume some familiarity with spring jpa and jsf.

Most relational database records have a primary key to uniquely identify it. This key appears on other tables as foreign keys. In my application i needed to display one or more of the attributes of a record from a table on a form and persist its unique identifier .

Below i provide some sample code that gives some hint on how this can be achieved using plain old java objects..

First lets paint the screen.. For JSF 1.*:


<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.prime.com.tr/ui">
<head>
<p:resources />
</head>
<body>
<h:form prependId="false" styleClass="cmxform">
<fieldset>
  <legend> </legend>
<p:panel id="panel" header="Combo Box Example">
<h:panelGrid columns="2"  columnClasses="label,value" styleClass="grid">
<h:outputLabel for="cb" value="comboItem" />
<h:selectOneMenu id="selectOneCb" value="#{pageBean.model.modelid}">
<f:selectItem itemLabel="Select Model" itemValue="" />
<f:selectItems value="#{pageBean.myModelValues}" />
</h:selectOneMenu>
</h:panelGrid>
</p:panel>
</fieldset>
</h:form>
</body>
</html>

For JSF 2.* this is even easier (thanks to Çağatay Çivici the primefaces lead for pointing this out to me :) ):


<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.prime.com.tr/ui">
<head>
<p:resources />
</head>
<body>
<h:form prependId="false" styleClass="cmxform">
<fieldset>
  <legend> </legend>
<p:panel id="panel" header="Combo Box Example">
<h:panelGrid columns="2"  columnClasses="label,value" styleClass="grid">
<h:outputLabel for="cb" value="comboItem" />
<h:selectOneMenu id="selectOneCb" value="#{pageBean.model.modelid}">
<f:selectItem itemLabel="Select Model" itemValue="" />
<f:selectItems value="#{pageBean.mlist}" var="model" itemLabel="#{model.modelvalue}" itemValue="#{model.modelId}"/>
</h:selectOneMenu>
</h:panelGrid>
</p:panel>
</fieldset>
</h:form>
</body>
</html>

Next lets define the backing page bean… For JSF 1.* this is ok :

@Component("pageBean")
@Scope("request")
public class PageBean implements Serializable {
private model = new Model();
private ModelService modelService;
private Map<String, String> myModelValues = new HashMap<String, String>();
private List<Model> mList;
public PageBean(){
}

 @Autowired
public PageBean(ModelService modelService){
this. modelService = modelService;
        mList = modelService.findAll();
        for (Model m : mList) {
            myModelValues.put(m.getmyModelValue(), m.getmyModelId());
     }
}
public Map<String, String> getMyModelValues() {
return myModelValues;
    }
public void setMyModelValues(Map<String, String> myModelValues) {
this.myModelValues= myModelValues;
 }
public Model getModel() {
return model;
}
public void setModel(Model model) {
this.model = model;
}
}

For JSF 2.* it is even better => You don’t need  use a Map or Hash Map as the case may be above (thanks to Çağatay Çivici the primefaces lead for pointing this out ):

@Component("pageBean")
@Scope("request")
public class PageBean implements Serializable {
private model = new Model();
private ModelService modelService;
private List<Model> list;
public PageBean(){
}

@Autowired
public PageBean(ModelService modelService){
        this. modelService = modelService;
        list = modelService.findAll();
}

public List<Model> getList() {
	return list;
}
public Model getModel() {
return model;
}
public void setModel(Model model) {
this.model = model;
}
}

Below is a service interface to define the the findAll method:

public interface ModelService {

public List< Model> findAll();
}

Next the implementation for the Model Service Interface:


@Service("modelService")
public ModelServiceImpl implements ModelService  {
private ModelDAO modeldao;
@Autowired
public ModelServiceImpl(ModelDAO modeldao) {
        this. modeldao = modeldao;
    }
    @Transactional(readOnly = true)
    public List<Model> findAll() {
        return modeldao.findAll();
    }
}

The Data Access object interface:

public interface ModelDAO {

public List< Model> findAll();
}

The Data Access object implementation proper:

@Repository
public class ModelDAOImpl implements ModelDAO {

    @PersistenceContext
    protected EntityManager entityMgr;

    public EntityManager getEntityMgr() {
        return entityMgr;
    }

    public void setEntityMgr(EntityManager entityMgr) {
        this.entityMgr = entityMgr;
    }

    public List<Model> findAll() {
        Query query = entityMgr.createNamedQuery("Model.findAll");
        return query.getResultList();
    }
}

Finally lets define the jpa model object:

@Entity
@Table(name = "MODEL")
@NamedQuery(name = "Model.findAll", query = "SELECT m FROM Model m") // this query returns distinct values from the database.
public class Model implements Serializable {

    @Id
    @Basic(optional = false)
    @Column(name = "MODEL_ID")
    private String modelId;
    @Basic(optional = false)
    @Column(name = "MODEL_VALUE")
private String modelValue;
 public Model() {
    }
 public Model(String modelId, String modelValue) {
this.modelId = modelId;
this.model = modelValue;
}
 public String getModelId() {
        return modelId;
    }

    public void setModelId(String modelId) {
        this.modelId = modelId;
    }

    public String getModelValue() {
        return modelValue;
    }

    public void setModelValue(String modelValue) {
        this. modelValue = modelValue;
    }
    }

The code above steps through it all… Ciao for now..

Using the Wicket Framework to Update style tag.

In this post, Wicket Framework is used to update the embedded style tag.

An already working sample can be found here.

Let’s begin by configuring the web application (i.e. web.xml)


<web-app xmlns="http://java.sun.com/xml/ns/j2ee" xsi="http://www.w3.org/2001/XMLSchema-instance" schemalocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" version="2.4">

<display-name>CSS and Wicket</display-name>
<filter>
<filter-name>css_wicket</filter-name>
<filter-class>org.apache.wicket.protocol.http.WicketFilter</filter-class>
<init-param>
<param-name>applicationClassName</param-name>
<param-value>com.jw.ike.pages.CssApplication</param-value>
</init-param>
</filter>

<filter-mapping>
<filter-name>css_wicket</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>

</web-app>

 

The wicket application class go as follows:


public class CssApplication extends WebApplication {

public CssApplication() {
}

public Class getHomePage() {
return CssDemo.class;
}

}

The getHomePage() method returns this Page:

public class CssDemo extends WebPage implements Serializable {
	private String uStyle;

	public CssDemo() {
		add(new Label("style"));
		add(new CssForm("addform"));

	}

	public CssDemo(String userStyle) {
		this.uStyle = userStyle;
		this.add(new Label("style", new PropertyModel(this, "uStyle")));
add(new CssForm("addform"));

	}

}

And the accompanying HTML web page is:

<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="stylesheet" type="text/css" href="../css/style/style.css">
<title>Wicket Updating Style Sheet</title>
<style type="text/css" wicket:id="style"></style>
</head>
<body>

<div id="bmain">
<form wicket:id="addform">
<h2>Update Style Sheet...</h2>

<span>Select Pre-Defined CSS Rules </span>

<select wicket:id="combo">

</select>

<textarea id="ta" wicket:id="txta" rows="20" cols="60"> rich text </textarea>

<input id="btn" type="submit" value="::Post Style Sheet::"></form>
<a href="http://wicket.apache.org/" >
<img id="logo" alt="Wicket" src="../images/wicket-logo.png" border="0" width='111' height="155"/></a>

</div>

<div id="side">

<h1>Change Me @!#%.</h1>

 </div>
</body>
</html>

And then the Form Class:


public class CssForm extends Form {

private String style1 = "Choose a style";
private String style2 = "h1{ font-size: 4.0em; font-family: Mistral; color: #dc512b; border:10px solid #bb342d; background-color: #098762;text-align: center;}";
private String style3 = "h1{ font-size: 5.0em; font-family: Comic Sans MS; color: #0066CC; border:10px solid #330066; background-color: green;text-align: center;}";
private String style4 = "h1{ font-size: 6.0em; font-family: Curlz MT; color: #CCFFFF; border:10px solid #445698; background-color: #6666CC;text-align: center;}";

private static String css;
private List cssList;
private String selectedCss = style1;
private DropDownChoice dropDownMenu;
private TextArea textArea;

public CssForm(String componentid) {
super(componentid);

cssList = Arrays.asList(new String[]{style1, style2, style3, style4});

dropDownMenu = new DropDownChoice("combo", new PropertyModel(this, "selectedCss"),
     cssList) {

 @Override
 protected void onSelectionChanged(Object newSelection) {

     textArea.setModelObject(newSelection);

 }

 @Override
 protected boolean wantOnSelectionChangedNotifications() {

     return true;
 }

};
add(dropDownMenu);

textArea = new TextArea("txta", new PropertyModel(this, "css"));

add(textArea);

}

@Override
protected void onSubmit() {
String definedCssRule =  textArea.getModelObject().toString();
definedCssRule = "\n\n\n" + definedCssRule + "\n\n\n";
setResponsePage(new CssDemo(definedCssRule));
textArea.setModelObject(null);
}
}

The External Style Sheet :


body {
	background-image: url("../images/cl.jpg");
	background-repeat: no-repeat;
}

h1 {
	font-size: 4.5em;
	color: #4088b8;
	margin: -300px 0 0 0;
	position: relative;
	left: -20px;
	top: 10px;
	position: relative
}

h2 {
	color: #4088b8;
}

span {
	font-size: 1.0em;
	color: #4088b8;
	padding:0 33px 0 2px;
}

#logo {
	position: relative;
	left: 0px;
	top: 50px;
	z-index: 1;
}
select {

	position: relative;
	left: 0px;
	bottom: 2px;
	width: 230px;
}

#jw {
	position: relative;
	left: 900px;
	top: -50px;
	z-index: 1;
}

#bmain {
	width: 510px;
	margin: 10px 0 0 0;
	position: inherit;
}

#side {
	float: right;
	width: 600px;
	margin: -150px 0 0 0;
	padding: 1px 0 0 0;
}

#ta {
	padding: 0 20px 0 0;
}

#btn {
	background-color: #4088b8;
	border-color: 4088b8;
	color: white;
	position: relative;
	left: 180px;
	top: 50px;
}

 

Google App Engine Support for Netbeans 6.7.1 & 6.8 Now Available..

This link has it all, for the “Google App Engine” Netbeans Plugin for 6.7.1 and 6.8

or you could…. just do the following quickly:

  • Click Tools on your Netbeans menu, then click Plugins and then select Settings tab
  • Click Add button and type ‘Google App Engine’ as tag for this Update center and any URL below into URL text field. Click to OK button.
  • For NetBeans 6.7.1: http://kenai.com/downloads/nbappengine/1.0_NetBeans671/updates.xml
  • For NetBeans 6.8 : http://kenai.com/downloads/nbappengine/Latest_NetBeans68/updates.xml
  • Move to Available Plugins tab and select Google App Engine modules (server, configuration, deployment, editor hints)
  • Finally, Click the Install button

2002 – Can’t connect to local MySQL server through socket ‘/var/mysql/mysql.sock’

Today, i stopped being a fan of MAMP for integrating PHP Apache and MYSQL, and i decided to setup Apache, MYSQL and PHP stack on my MAC OS X 10.5.7 (leopard) the good old way…


But, i encountered this error: 2002 – Can’t connect to local MySQL server through socket ‘/var/mysql/mysql.sock’ (2).

Wow… i then discovered funny enough, that MYSQL instance was running perfectly and i was able to connect MYSQL
via the MYSQL Admin GUI tool.

I made a lucky guess asserting, that the PHP config file may be missing some info, Hmmm…

Well the solution goes as follows:

I searched for “mysql.lock” and i discovered that the MYSQL Socket file was located in “/tmp/mysql.lock.

Also, in the my PHP.ini file the value formysql.default_socket” was entirely empty “”.

ehhhh… Run this command in Terminal to view hidden files “defaults write com.apple.finder AppleShowAllFiles TRUE” and then followed by “killall Finder”.

Then Go to “private/etc/PHP.ini”. (note: private is a hidden folder).

If prior to this, in “private/etc/ “folder, the PHP.ini file does not exist copy and paste it there first.

Now open the PHP.ini file with say BBedit or TextWrangler.

Use command + F to find “mysql.default_socket” and paste “/tmp/mysql.sock” as it’s new value.

Finally restart your Apache web server with Terminal using “sudo apachectl graceful”.

After restart, PHP will be able to make connection calls to MYSQL with no further a do or hassle.

undefined method ‘scaffold’ for blogcontroller:class

If you get this “undefined method ‘scaffold’ for blogcontroller:class” in your rails application, when you run your application on your browser most likely you were trying out the Netbeans RubyWeblog Example to solve, follow the steps below:

1. Delete the rubyweblog project from the netbeans project Window. (Also check and make sure you delete “rubyweblog project” from it’s physical location on your hard drive and drop any database previously created in relation to the Netbeans RubyWeblog Example).

2. Create a rubyweblog_development database, as described below i.e if already have skip to 3.
Open a command window.
If it has not already been started, start the MySQL database server.
Type the following command to create the development database and press Enter.
mysqladmin -u root -p create rubyweblog_development
Note: If the root user does not have a required password, omit the -p argument

3. In the NetBeans IDE, choose File > New Project. Select Ruby in the Categories field and Ruby on Rails Application in the Projects field. Click Next. Type rubyweblog in the Project Name field. Accept all the other default settings. Click Finish to create the new project. The IDE creates the project directory with the same name as your project.

4. In the editing area, edit the database.yml by providing the password in the development configuration. Save and close the database.yml file.

5. Next For rails 2.0 aplications you generate the model, controller, migrate version and views with the following:

a. Navigate to your rubyweblog application via commandline Start > Run then type cmd and press enter. i assume your rubyweblog is located at C:\apps\rubyweblog.

b.Within blog project, right click on your Model folder, click “Generate” and select “Resource” from the menu.You can then place your attributes in the parameters field or alternatively type the following “ruby script\generate scaffold post title:string” in the command line and hit enter, This action generates the model, controller, migrate version and views for you.

6.In the Projects window, right-click the rubyweblog node and choose Migrate Database > To Current Version.This action updates the the database to include the posts table. The Output window indicates when the migration is complete.

7. Under the Configuration node, open routes.rb. Find the line:

# map.connect ”, :controller => “welcome”

Edit the line by removing the comment sign (#) using crtl+/ and changing welcome to posts. Expand the Public node, right-click index.html and choose Delete.

Choose File > Save All.
Click the Run Main Project button in the toolbar.

This action starts the WEBrick server, which is part of the Ruby on Rails framework, and launches the web browser. Following is the first page of the application.

Finally continue the Netbeans RubyWeblog Example “Doing More: Adding Another Field”.

Configuring IIS For NetBeans PHP Plugin

To install the PHP plugin and create an IIS web server profile:

1. Check if the PHP plugin is already installed: choose Tools > Plugins and switch to the Installed tab.
2. If PHP is not on the list of installed plugins, switch to the Available Plugins tab, select the PHP option in the list, and click the Install button.
3. In the NetBeans IDE main screen, switch to the Services tab, which shows a tree of available databases and web server profiles.
4. Position the cursor on the Web Servers node and from the context menu choose Add Web Server. The Add New Web Server Record dialog box opens.
5. In the Connection Name text field, enter the name of the web server profile(in this case enter “IIS ADMIN”) and from the Server Type drop-down list, choose one of the connection types:
* Local Web Server with file access. This option assumes that you have a web server installed on your local computer. Every time you run your PHP project, the IDE copies your source files to a specified directory under the web server document root.
* Remote Web Server with FTP access. This option allows you to deploy your PHP files to a remote web server via FTP.
Note: In the development environment using a local web server is recommended. Find how to configure FTP access here.
6. Click Next and choose the Manual Configuration option.
7. In the Apache config file Location text box, Leave it Blank.
8. Click Next.
9. In the Base Directory text field, enter the subfolder of the Document Root where your PHP files will be copied(for IIS ‘C:\Inetpub\wwwroot’ is the path to IIS root, now create a folder there and use that folder name only in the Base Directory text field with no path pointing to it just the name of the wwwroot subfolder you just created.).
10. Click Next.
11. For the Document Root Browse to ‘C:\Inetpub\wwwroot’ or any sub folders as you wish.
12. Click Finish.

For More information.. On the Netbeans PHP Plugin Click here