You can run Apache Tomcat from inside Eclipse by:
* Window--> Show View --> Server
In the Servers panel that opens up:
* R-click --> New --> Server
* Select the Apache Tomcat Server from List
* Add your WebApp Project
You can now Right Click on the Server and Start/Stop it from inside Eclipse.
Here is a Gotcha:
- The application is run directly from your src folder (i.e. the war file is not actually copied to the /webapps directory of the tomcat install!)
- This is great because it speeds up development - you do not have to keep building the project to test it out on the server
- But REMEMBER to make a copy of all the jar files in the src/WEB-INF/lib directory otherwise TomCat will not find them!
Friday, July 31, 2009
How to maven-ize richfaces
For some reason, richfaces jars are no longer available on the maven repository.
To do it yourself:
- Download richfaces-ui-3.3.1.GA-bin.zip from the JBoss richfaces website
- Unzip it to say C:\Program Files\Richfaces
- Open a command prompt and cd to the /lib directory
You will see 3 jars in the /lib directory
- Give the following commands to load the jars to maven
> mvn install:install-file -DgroupId=org.richfaces -DartifactId=richfaces-impl -Dversion=3.3.1.GA -Dpackaging=jar -Dfile=./richfaces-impl-3.3.1.GA.jar
> mvn install:install-file -DgroupId=org.richfaces -DartifactId=richfaces-ui -Dversion=3.3.1.GA -Dpackaging=jar -Dfile=./richfaces-ui-3.3.1.GA.jar
> mvn install:install-file -DgroupId=org.richfaces -DartifactId=richfaces-api -Dversion=3.3.1.GA -Dpackaging=jar -Dfile=./richfaces-api-3.3.1.GA.jar
You can now reference these libraries in your pom.xml:
<dependency>
<groupId>org.richfaces</groupId>
<artifactId>richfaces-ui</artifactId>
<version>3.3.1.GA</version>
</dependency>
<dependency>
<groupId>org.richfaces</groupId>
<artifactId>richfaces-api</artifactId>
<version>3.3.1.GA</version>
</dependency>
<dependency>
<groupId>org.richfaces</groupId>
<artifactId>richfaces-impl</artifactId>
<version>3.3.1.GA</version>
</dependency>
To do it yourself:
- Download richfaces-ui-3.3.1.GA-bin.zip from the JBoss richfaces website
- Unzip it to say C:\Program Files\Richfaces
- Open a command prompt and cd to the /lib directory
You will see 3 jars in the /lib directory
- Give the following commands to load the jars to maven
> mvn install:install-file -DgroupId=org.richfaces -DartifactId=richfaces-impl -Dversion=3.3.1.GA -Dpackaging=jar -Dfile=./richfaces-impl-3.3.1.GA.jar
> mvn install:install-file -DgroupId=org.richfaces -DartifactId=richfaces-ui -Dversion=3.3.1.GA -Dpackaging=jar -Dfile=./richfaces-ui-3.3.1.GA.jar
> mvn install:install-file -DgroupId=org.richfaces -DartifactId=richfaces-api -Dversion=3.3.1.GA -Dpackaging=jar -Dfile=./richfaces-api-3.3.1.GA.jar
You can now reference these libraries in your pom.xml:
<dependency>
<groupId>org.richfaces</groupId>
<artifactId>richfaces-ui</artifactId>
<version>3.3.1.GA</version>
</dependency>
<dependency>
<groupId>org.richfaces</groupId>
<artifactId>richfaces-api</artifactId>
<version>3.3.1.GA</version>
</dependency>
<dependency>
<groupId>org.richfaces</groupId>
<artifactId>richfaces-impl</artifactId>
<version>3.3.1.GA</version>
</dependency>
Thursday, July 23, 2009
Example: Generating a SHA hash in Java
import java.security.MessageDigest;
...
public String createHashSHA (String someString){
try {
MessageDigest md = MessageDigest.getInstance("SHA");
md.update(someString.getBytes());
byte[] someStringDigest = md.digest();
String someStringHashSHA = new String(someStringDigest);
return someStringHashSHA;
}
catch (Exception e){
...
}
}
...
public String createHashSHA (String someString){
try {
MessageDigest md = MessageDigest.getInstance("SHA");
md.update(someString.getBytes());
byte[] someStringDigest = md.digest();
String someStringHashSHA = new String(someStringDigest);
return someStringHashSHA;
}
catch (Exception e){
...
}
}
Jetty cant find applicationContext.xml
If your web aplication uses Spring, then you probably have an applicationContext.xml. By default, this file is in the /WEB-INF directory. However, for some reason, Jetty looks for it in /WEB-INF/classes. So Jetty gives this "applicationContext.xml file does not exist" error. Putting the file in /WEB-INF/classes seems to resolve this issue.
Note: I had to explode my war to do this. You can use zipitfree (http://www.zipitfast.com/) to explode (uncompress) the war.
Note: I had to explode my war to do this. You can use zipitfree (http://www.zipitfast.com/) to explode (uncompress) the war.
How to install web application in Jetty
To install web application in Jetty, simply copy the your_web_app.war into /webapps directory of Jetty. Jetty will automatically pick it up on restart.
How to install and start Jetty Server
Here is what works for me:
- Download Jetty (I downloaded version 7)
- Unzip it in a directory (I used C:\Program Files\jetty_7.0.x)
- Install a JRE (I installed mine in C:\Program Files\JAVA)
- Open a cygwin command prompt (download cygwin from http://www.cygwin.com/)
- Type:
> cd /cygwin/c/Program Files/jetty_7.0.x
> export JETTY_HOME=/cygwin/c/Program Files/jetty_7.0.x
> export JAVA_HOME=/cygwin/c/Program Files/Java/jre
> java -jar start.jar
This should start Jetty.
To stop it, I just use ctrl-C (jetty will stop gracefully and not just abort)
- Download Jetty (I downloaded version 7)
- Unzip it in a directory (I used C:\Program Files\jetty_7.0.x)
- Install a JRE (I installed mine in C:\Program Files\JAVA)
- Open a cygwin command prompt (download cygwin from http://www.cygwin.com/)
- Type:
> cd /cygwin/c/Program Files/jetty_7.0.x
> export JETTY_HOME=/cygwin/c/Program Files/jetty_7.0.x
> export JAVA_HOME=/cygwin/c/Program Files/Java/jre
> java -jar start.jar
This should start Jetty.
To stop it, I just use ctrl-C (jetty will stop gracefully and not just abort)
MySQL 5.1 - server does not start on Vista
There seems to be some problem staring the MySQL 5.1 server on Vista. It won't start no matter what you do. I went back to version 5.0 and it installed and runs fine.
how to become administrator in Vista
By default, Vista administrator account is "hidden". This post shows how to activate it:
http://www.howtogeek.com/howto/windows-vista/enable-the-hidden-administrator-account-on-windows-vista/
In brief:
- open a "administrator" command prompt (start->programs->accesories->commandprompt : R-cick and choose - run as admin)
- Type: net user administrator /active:yes
- Logout and you will now see admin acount when you log back in (it has no password)
To rehide admin:
- open admin command prompt
- type: net user administrator /active:no
http://www.howtogeek.com/howto/windows-vista/enable-the-hidden-administrator-account-on-windows-vista/
In brief:
- open a "administrator" command prompt (start->programs->accesories->commandprompt : R-cick and choose - run as admin)
- Type: net user administrator /active:yes
- Logout and you will now see admin acount when you log back in (it has no password)
To rehide admin:
- open admin command prompt
- type: net user administrator /active:no
why "localhost" does not resolve
There is a problem accessing localhost on Vista. This post shows the solution to this problem:
http://www.moorlandit.net/index.php/2009/05/accessing-localhost-on-vistawindows-7-96
I am copy-pasting it here:
For some reason in Vista and Windows 7 localhost doesn’t work out of the box. To get it working you have to add this line to the c:\windows\system32\drivers\etc\hosts file:
127.0.0.1 locahost
Now the hosts file is a Windows system file so the only way Windows will allow you to edit the file is if you do it as Administrator. To do this click Start and type CMD in the search box, when Windows shows cmd.exe right-click it and click run as administrator then when the DOS box opens type:
edit c:\windows\system32\drivers\etc\hosts
Then add the 127.0.0.1 localhost line and save and close the file. Then localhost should work as it did in XP.
http://www.moorlandit.net/index.php/2009/05/accessing-localhost-on-vistawindows-7-96
I am copy-pasting it here:
For some reason in Vista and Windows 7 localhost doesn’t work out of the box. To get it working you have to add this line to the c:\windows\system32\drivers\etc\hosts file:
127.0.0.1 locahost
Now the hosts file is a Windows system file so the only way Windows will allow you to edit the file is if you do it as Administrator. To do this click Start and type CMD in the search box, when Windows shows cmd.exe right-click it and click run as administrator then when the DOS box opens type:
edit c:\windows\system32\drivers\etc\hosts
Then add the 127.0.0.1 localhost line and save and close the file. Then localhost should work as it did in XP.
Monday, July 6, 2009
Tapestry5 - How to override elements of standard stylesheet
Create a file styles.css (or any other name of your choice) in your main/webapp directory (where you have all your .tml files)
Enter the styles in this file, for example - to override the color of chenillekit sliding panel, you can make an entry in this file:
DIV.ck_slidingPanelSubject {
background: #CCFF99;
}
Now, in yourpage.java - enter the following property to pull in the sylesheet:
import org.apache.tapestry5.Asset;
@Inject
@Path("context:styles.css")
@Property
private Asset styles;
And in yourpage.tml, pull the stylesheet in your header tag, as follows:
<head>
<link rel="stylesheet" href="${styles}" type="text/css"/>
</head>
Enter the styles in this file, for example - to override the color of chenillekit sliding panel, you can make an entry in this file:
DIV.ck_slidingPanelSubject {
background: #CCFF99;
}
Now, in yourpage.java - enter the following property to pull in the sylesheet:
import org.apache.tapestry5.Asset;
@Inject
@Path("context:styles.css")
@Property
private Asset styles;
And in yourpage.tml, pull the stylesheet in your header tag, as follows:
<head>
<link rel="stylesheet" href="${styles}" type="text/css"/>
</head>
Subscribe to:
Posts (Atom)