Deploy Java applications on Mac

Posted September 25, 2009 by Thierry WASYL
Categories: General, Tips

Tags: , , , ,

Hello,

You need to deploy Java applications on Mac? Take a look at : http://thierry.wasylczenko.free.fr/?p=108

Enjoy.

Deal with workspaces and shortcuts in Eclipse

Posted September 12, 2009 by Thierry WASYL
Categories: Eclipse, Tips

Tags: , , , ,

A brand new post here : http://thierry.wasylczenko.free.fr/?p=90

Enjoy :)

Maximize a JFrame

Posted July 24, 2009 by Thierry WASYL
Categories: Code example, Swing, Tips

Tags: , , ,

Hello,

A brand new post available here : http://thierry.wasylczenko.free.fr/?p=70

See You.

JAI : how to solve vendorName == null exception

Posted July 24, 2009 by Thierry WASYL
Categories: General, Tips

Tags: , , , ,

A brand new post available here : http://thierry.wasylczenko.free.fr/?p=66

See You.

Blog migration

Posted July 24, 2009 by Thierry WASYL
Categories: News

Tags:

Hello everyone,

I’m currently moving my blog to my website where You can also see my WebCV. Indeed, I needed a plugin to highlight the source code I posted. So, You can find it out at http://thierry.wasylczenko.free.fr

Be welcome there.

Sincerely,

Thierry

Virtual hosting on Glassfish

Posted June 27, 2009 by Thierry WASYL
Categories: Glassfish

Tags: , , , ,

Hi everyone,

I’ve been looking how to change the URL of a website I’m developping in JEE. You probably have noticed that the URL of the project You’re developping is something like : http://localhost:8080/theContextPathOfYourProject.
I’m currently developping my application with NetBeans and Glassfish V2 and I would like to change this URL with something more simple, like http://www.mysite.com/

So I checked out and a nice feature of Glassfish could be used : Virtual Hosting.
This article will show You how to do that, in the easiest way possible. So let’s go.

First of all, You’ll need to have a JEE application. With this application, You can change its context-path to something simple. For example, my application is named jacc so I changed its context-path to jacc. Do this is pretty simple.
In NetBeans, open the Projects window, right-click on Your application and choose Properties. In the new window, go to Run and change the context-path, as shown below :
Image 2

After that, we’re going to work in the Administration console of Glassfish. So if Glassfish isn’t started yet, do it and go to the admin console.

Step 1:
We will create a virtual server. So let’s go to Configuration, HTTP Service and Virtual Servers. You should be there :
Image 4

Click on the New… button. Give an id (for example jacc), the hosts (which corresponds to the address You’ll enter in Your browser to access Your website : I want jacc.com). Hit the OK button. We’ll create a listener and then, go back here.

Step 2 :
Here we will create a listener. This listener will listen requests on a given port. The default port Glassfish is listen to is 8080. If You don’t want to run Your app on  another port, You can go to step 3. Otherwise, let’s go.
We’re going to create a listener for the port 8282. On the left of the admin console, click on Configuration, then HTTP Service and HTTP Listeners. You should be there :

Image 3

Right, click on the New… button. Give Your listener a name such as http-listener-3, the network address (in our case, for localhost, we enter 0.0.0.0), the listening port (8282 as we said) and the default virtual server, created before. So in the list You should see jacc. If not, restart Glassfish and restart this step. Hit Next and the Finish.

Step 3:
Then go back to the virtul servers list and click on the one You’ve created before. And in the text field for the HTTP Listners, enter the name of the listener You’ve created before. For me http-listener-3.
Then, in the list of Default Web Module, You will choose Your web application. Mine is called jAcc-war. So I select it. With that, You won’t need to type the context path of Your application in the URL :)
Ok, should be nice. Now, we have to indicates Glassfish our web application will run on our brand new virtual server.

Step 4:
So, go to Applications, Web Applications and select Your application. Mine is jAcc-war. Then select Your virtual server in the list like this :
Image 5

So now, restart Your Glassfish. Then we’re going to work somewhere else…

Step 5:
When You type the hosts address You defined in the creation of Your virtual server (jacc.com for me) in the address bar of Your browser, it shouldn’t go to the right place… So You have to tell Your computer that this host is Your computer. So find a file named hosts in Your system. In Unix based OS, it should be in /etc/. On Windows system : C:\WINDOWS\system32\drivers\etc. Edit this file and add a line like this :
127.0.0.1    jacc.com

Well, now it should work :) So in Your brower, You should type the URL You wanted and the port on which Your virtual server listens. So for me jacc.com:8282
So it is more convenient, isn’t it? :)
So now You know how to deploy virtual servers using Glassfish.
Enjoy :)

Eclipse Galileo

Posted June 25, 2009 by Thierry WASYL
Categories: Eclipse, News, Tips

Tags: ,

Hello everyone,

The latest version of Eclipse is out :) Codename : Galileo. So be sure to grab it on : http://www.eclipse.org/
If You’re on Mac OS X : Leopard, You will prefer the Cocoa version of the IDE :)

Then, let me give You a little tip : if You’re on Mac OS X, and even if You’ve setted up the JDK 1.6 by default, Eclipse won’t recognize it, and will still use the JDK 1.5. So to change that, go to the Preferences of Eclipse and then to Java, Installed JREs. You should be there :

Image 1

So click on the Add button. In the new window, select MacOS X VM as JRE type. Click next and now enter something like this in the JRE Home text field : /System/Library/Frameworks/JavaVM.framework/Versions/1.6.0/Home
Right, You’ve done the most tough part of it :)
Enter an explicit name like JRE 1.6 for example and hit the Finish button. Now You just have to select the new JRE in the list.
Now under the Installed JREs node, select Your execution environment as shown bellow :

Image 2

Well, it will soon be ok :) Just setup the compiler now. Go under Java, Compiler and select 1.6 in the list, as shown bellow :

Image 3

That’s all :)
Enjoy.

Main creation shortcut in NetBeans

Posted June 23, 2009 by Thierry WASYL
Categories: NetBeans, Tips

Tags: , , , ,

Hello everyone,

Maybe You used Eclipse some days (and still use it ;) ) and appreciate the way You can create the main method. In Your class, You enter “main” and then press Ctrl+Space and it generates the body of Your main method.
Using NetBeans, it isn’t available by default. But some times ago, I found a way to do it in the similar way that Eclipse does :) So let’s see how.

You have to create a code template, but don’t be affraid, it’s really simple. First go to the preferences of NetBeans, then in the “Editor” part and click on the tab “Code templates”. You should be there :

Image 1

Then click on “New”. In the window, type the text You have to write. It’s Your shortcut :) For the main method generation, type “main” :) It’s not original but instinctive :)
In the list, Your new abbreviation is selected. In the text area called “Expended Text”, enter this :

public static void main(String[] args) {
${cursor}
}

You’ve successfully created a main template :)
Now in Your class, just type “main” and press the Tab button, and Your main body will be created :)
It’s nice, it’s simple, it’s Java :)
Enjoy

Create Your own Filter in JSF

Posted June 22, 2009 by Thierry WASYL
Categories: Code example

Tags: , , , , , ,

You may have to restrict access to some pages of your website in JSF and redirect the user to a specific page. For example, if the user is not logged in, he can not access the admin page, and You would like to redirect him to the login page. To do so, You can create Your own filters, and guess what : it’s not tough :)
Let’s see some example.

First of all, You have to implements javax.servlet.Filter. So far away, just create the class, and You’ll have to define three methods : init(),  doFilter() and destroy(). So here we go :

Filter example

Once we have our filter, we have to set it up :) So we do it now.
So go to your web.xml file, and first set the filter markup :
Image 4

Give a name to your filter, and indicates  the class that represents Your filter, typically the class You’ve created and which implements Filter.
And then, You have to indicates on which request this filter is applied to :
Image 5
Note that we use the same name (case sensitive) that we used in the “declaration” of our filter.

It’s done :) Nothing more, nothing less. Feel free to customize this example by defining your rules of restriction :)
Enjoy :)

Java update on Mac

Posted June 16, 2009 by Thierry WASYL
Categories: Code example, News

Tags: , , ,

Hello everyone,

June, 15th 2009 : Apple released an update for Java on Mac for Mac OS X Tiger and Leopard : http://bit.ly/3NRDS.
This update brings more reliability, security and compatibility with Java SE 6 and previous version. But the thing I appreciate is the availability of the skin Nimbus (released with the Java 1.6 update 10 on others platforms) on Mac OS :)
I like this brand new skin Sun made some month ago. So now, You can set this skin up for your Java application.
If You don’t know how to do that, look at this, it’s pretty simple:)

For example, set the skin, directly in the main method, before creating any Swing component (JFrame, JWindow…)

try {

// Try to set the Nimbus look’n'feel
// You have to do it in a try block, in case the skin isn’t found
UIManager.setLookAndFeel(“com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel”);

} catch (ClassNotFoundException ex) {
} catch (InstantiationException ex) {
} catch (IllegalAccessException ex) {
} catch (UnsupportedLookAndFeelException ex) {
} finally {

// Start your GUI. If the skin isn’t found, the default one is used

}