Archive for December, 2009

Using Maven in Eclipse

Install Java and Maven

First off, make sure you have a Java JDK installed and that your JAVA_HOME environment variable points to it. You can check by typing “echo %JAVA_HOME%” in Windows or “echo $JAVA_HOME” in Linux. You’ll next want to download and install Maven by following the directions on their website.  Once Maven is installed, you’ll want to create a settings.xml file in your .m2 directory, which is located at ~/.m2 in Linux or C:\Documents and Settings\%USER%\.m2 on Windows.  You can do this by copying the settings.xml file from the directory where Maven in installed to you .m2 directory.

Install m2eclipse

You’ll want to make sure your Eclipse installation is pointint at your JDK.  You can check by going to Window > Preferences > Java > Installed JREs.  You’ll also want to set the -vm flag in your eclipse.ini file which is located at the root of your Eclipse installation.  Here’s what my file looks like:

-showsplash
org.eclipse.platform
--launcher.XXMaxPermSize
256M
-framework
plugins\org.eclipse.osgi_3.4.0.v20080605-1900.jar
-vm
C:\Program Files\Java\jdk1.6.0_11\bin\javaw.exe
-vmargs
-Dosgi.requiredJavaVersion=1.5
-Xms40m
-Xmx512m

Finally, you get to install m2eclipse by opening up Eclipse and selecting Help > Software Updates… > Available Software > Add Site…  Then enter http://m2eclipse.sonatype.org/update/, check the newly added boxes, and press Install.

Create Your First Maven Project

Now for the fun.  You can create a Maven project in Eclipse by selecting New > Project… > Maven > Maven Project.  Check “Create a simple project” on the first screen and hit Next.  Enter the Group Id, Artifact Id, and Name.  For example, “com.benmccann.robot”, “window-robot”, “Window Robot”.  Now, at long last, you can do some actual programming.

Add Dependencies

It won’t be long before you’ll want to add dependancies.  Open the Maven Indexes View by selecting Window > Show View > Other… > Maven > Maven Indexes.  You’ll want to make sure you have the Maven Central Repository, so right-click the view and choose “Add Index”.  Enter http://repo1.maven.org/maven2/ for the Repository URL and hit Retrieve to fill in the Repository Id of central.  Now you can right-click the project and choose Maven > Add Dependancy.  We’ll add jUnit since you’ll probably want it anyway.  Type junit and you should see it populated into the box below.  Use the dropdown at the bottom to set a scope of “test” and hit OK.

,

No Comments

How to start and stop Tomcat from ANT

Filed under: java — Peter Thomas @ 12:04 am

This approach is not based on the Tomcat Ant Tasks or a brute force <exec dir=”${tomcat.home}/bin” executable=”startup.bat”/> kind of approach.

After wading through startup.bat and catalina.bat I figured that they boil down to the following:

<pre><target name="tomcat-start">
    <java jar="${tomcat.home}/bin/bootstrap.jar" fork="true">
        <jvmarg value="-Dcatalina.home=${tomcat.home}"/>
    </java>
</target>

<target name="tomcat-stop">
    <java jar="${tomcat.home}/bin/bootstrap.jar" fork="true">
        <jvmarg value="-Dcatalina.home=${tomcat.home}"/>
        <arg line="stop"/>
    </java>
</target></pre>

You can have in build.properties, something like the following entry:

tomcat.home=E:/peter/opt/apache-tomcat-5.5.12

It works great and in Eclipse and NetBeans the stack traces within the log window hyperlink to the source code just as you would expect. You would normally combine these ant targets with a “war” task. The Tomcat Reload Ant task can also be used to speed up development time.

One of the advantages of this approach is that you can extend it to start Tomcat for remote debugging

<pre><target name="tomcat-start-debug">
    <java jar="${tomcat.home}/bin/bootstrap.jar" fork="true">
        <jvmarg value="-Dcatalina.home=${tomcat.home}"/>
        <jvmarg value="-Xdebug"/>
        <jvmarg
value="-Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=n"/>
    </java>
</target>

,

No Comments

Installing Spring Tool Suite (STS) under Eclipse 3.5 Galileo

Firstly you need to install Eclipse 3.5 Galileo, then once that’s up and running you can use the Spring update site to install the Spring Tool Suite (STS). Follow these simple step-by-step instructions. I’m assuming that you are the only Java developer using this machine.

  1. Go to http://www.eclipse.org/downloads/
  2. Follow the link for Eclipse IDE for Java EE Developers (189 MB) for Windows.
  3. Select a mirror and download the file.
  4. Create a folder called c:\java.
  5. Move the Eclipse archive (eclipse-jee-galileo-win32.zip) into c:\java and extract here.
  6. Folder c:\java\eclipse will be created.
  7. Drag the executable eclipse.exe on to the desktop (or quick launch) and make a shortcut.
  8. The workspace dialogue will pop up and ask you where you would like to keep your workspace. Spaces in file names (or directories) are always a bad idea especially when developing under a Windows environment which is why I don’t accept the default workspace location, so enter c:\java\workspace.

That was easy wasn’t it?. STS is now free so you can just install it from their update site.

  1. Install Eclipse 3.5 Galileo mentioned above.
  2. Open the preferences page Windows->Preferences.
  3. Expand the Install/Update tree on the right hand side and select Available Software Sites.
  4. Highlight all the Enabled sites and click Disable.
  5. Click the Import button and enter http://dist.springsource.com/snapshot/TOOLS/sts-update-sites.xml. Eclipse spots this is a website then downloads and installs the xml. It may take a couple of seconds, but when it finishes click Ok.
  6. From the file menu, go to Help->Install New Software….
  7. Set Work with to AJDT – http://download.eclipse.org/tools/ajdt/35/dev/update. At the time of writing this there were no new updates so skip it and move to the next step.
  8. Set Work with to Mylyn Extras – http://download.eclipse.org/tools/mylyn/update/extras.
  9. Expand Mylyn Integration and check Mylyn Connector: JIRA, Next will become active to click it.
  10. After a bit of rumbling (to work out dependencies which there are none) click Next.
  11. Accept the License agreement and click Finish.
  12. After installation you are asked to restart Eclipse, so click Yes.
  13. Back into the Help->Install New Software….
  14. Set Work with to Spring IDE Update Site – http://dist.springframework.org/snapshot/IDE/nightly.
  15. Select all the components and click Next. More rumbling then click Next again. Accept the license and click Finish.
  16. Back into the Help->Install New Software….
  17. Set Work with to SpringSource dm Server Tools Update Site – http://dist.springsource.com/snapshot/DMS-TOOLS/nightly
  18. Back into the Help->Install New Software….
  19. Set Work with to SpringSource Tool Suite Update Site – http://dist.springsource.com/snapshot/STS/nightly/e3.4

Close down Eclipse and zip up the whole of c:\java\eclipse. Rename it to eclipse-3.5-sts.zip. If there is one thing I have learnt, it’s take a back up of a fixed working installation. Every one and his dog can write eclipse features and plugins. It is easy for one plugin to screw up another, so its really handy to have a “last known good position” to rollback to. Otherwise you may well find that you are going through this whole process again.

Original SpringSource instructions can be found here.

Ref: http://www.bigsoft.co.uk/blog/index.php/2009/07/01/installing-sts-under-eclipse-3-5-galileo

1 Comment

MOSS – Plan for administrative and service accounts

MOSS – Plan for administrative and service accounts

No Comments

Enabling the SharePoint Safe Mode Call Stack, Disabling Custom Errors and Enabiling Compilation Debugging

When developling for SharePoint, I find myself always turning on the call stack and disabiling the custom errors in my development environment. It really does help when trying to debug run-time problems. I know there a few posts out there that describe how to do this, but I figured I would repost it as a reference for myself (which you are welcome to use).

Just remember that I do this in my development environment only. I don’t recommend changing the web.config files in any other environment.

Enabling the Call Stack

Set the value CallStack attribute in the SafeMode element in the web.config file to true.

<pre><?xml version="1.0" encoding="UTF-8" standalone="yes"?>
 <configuration>
  ...
  <SharePoint>
   <SafeMode MaxControls="200"
             CallStack="true"
             DirectFileDependencies="10"
             TotalFileDependencies="50"
             AllowPageLevelTrace="false">
    ...
   </SafeMode>
   ...
 </SharePoint>
 ...
</configuration>

Disabling Custom Errors

Set the value of the mode attribute in the customErrors element to Off.

<pre><?xml version="1.0" encoding="UTF-8" standalone="yes"?>
 <configuration>
  ...
  <system.web>
   ...
   <customErrors mode="Off" />
   ...
  </system.web>
 ...
</configuration></pre>
<strong>Enabiling Compilation Debugging</strong>

Set the value of the debug attribute in the compilation element to true

<pre><pre><?xml version="1.0" encoding="UTF-8" standalone="yes"?>

<configuration>

...

<system.web>

...

<compilation debug="true">

...

</compilation>

...

</system.web>

...

</configuration>

Putting it all together
 

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
 <configuration>
  ...
  <SharePoint>
   <SafeMode MaxControls="200"
             CallStack="true"
             DirectFileDependencies="10"
             TotalFileDependencies="50"
             AllowPageLevelTrace="false">
    ...
   </SafeMode>
   ...
 </SharePoint>
 <system.web>
   ...
   <customErrors mode="Off" />
   ...
   <compilation debug="true">
    ...
   </compilation>
   ...
  </system.web>
 ...
</configuration>

No Comments

科學園影相… 忙裏偷閒…

難得今日天氣算好… 去影相喇…

去左科學園影, 靚+近…

個陣時係個度做都無咁靚…

去新城巿諗住食tea, 但係連m 記都無位…

入左科學園先算…

去我以前成日去既canteen… 好彩有開jei…

食完野就去影相… 不過有D影得唔好… 要再努力…

No Comments

dear fiona

你係咪有乜野唔開心啊
有唔開心記住要話我知
我乜野都會同你分享架

No Comments