Archive

Posts Tagged ‘java flex’

Java and Flex Setup Tips

December 19th, 2008
Comments Off

I have put together fairly extensive instructions on setting up a complete development environment for flex, java and ant. You can read about after the jump.

Jump to Tips on Flex, Java, Tomcat, Ant, Mac OS X and Windows.

OVERVIEW

1) I like to install all the development tools under a common apps directory so they are easier to access from the command line. (i.e. apps on Unix systems or c:apps on Windows). Also there can be problems when accessing the Flex SDK from a directory with spaces in the path.

2) Environment variables on Unix systems (i.e. Mac OS X or Linux) are set with the export NAME=value. For example:

export JAVA_HOME=/apps/jdk1.6.0_04

Here is sample script that sets up all the necessary envrionment variables.

You can set the environment variables for the current window by running the following command:

. ./setjava.sh

FLEX SDK SETUP

The Flex SDK is only needed if your a building the project from the command line. On windows be sure there are no spaces in the path where flex is installed. This will break the build! We are currently using Flex SDK 3.

There are two ways you can set it up:

1) Download it from Adobe.

2) Use the Flex SDK that comes with Flex Builder.

After you have setup the Flex SDK you need to set the FLEX_HOME environment variable:

FLEX_HOME=c:appsflex_sdk_300477

or FLEX_HOME=/apps/flex_sdk_300477

JAVA TIPS

Anvil has been developed with Java 1.6 and is compatabile with 1.5 with some small changes.

When you install the JDK be sure to do a custom setup, so you can install in another directory other than the default which is c:progam files. I recommend using apps for everything.

After installing Java be sure to:

1) Set the JAVA_HOME environment variable to the home directory of java.

2) Add the Java bin directory to the FIRST of the PATH environment variable. There is often several versions of Java on your machine, so it needs to be at the first of the PATH environment variable.

3) From the command line test to be sure the right version of Java is running with the following commands:

a. java –version — This should return Java 1.6

b. on cygwin or Linux you can also run which java to be sure it was installed in the right directory.

SETTING UP TOMCAT

Installing Tomcat is as simple as unzipping it. Be sure to use Tomcat 5 or Later.

See the notes below about using the Tomcat server bundled with Adobe BlazeDS.

1) Download the Tomcat Core zip or tar file.

2) Unzip it into your apps directory (or the directory where you are putting all of your development tools).

3) Set the CATALINA_HOME environment variable to the home directory of where tomcat is. Catalina is just another name for tomcat.

4) To make Tomcat easier to run add the tomcat bin directory to the PATH environment variable. i.e.

export PATH=$PATH:$CATALINA_HOME/bin

or on Windows – %CATALINA_HOME%bin

5) You should now be able to go to the command line and run either:

Linux / Mac OS X varieties – <a href=”http://catalina.sh/”>catalina.sh</a> version

Windows – catalina.bat version

6) To run the Tomcat manager application you need to add an administrative user:

Under the tomcat home directory is a conf directory. In there modify the tomcat-users.xml file.

Add the following line to the file:

&lt;user username=”admin” password=”admin” roles=”manager,tomcat,role1″/&gt;

7) Sometimes when you run Tomcat you will get a conflict with the port it listens on. By default this is port 8080. On Blaze DS the port is changed to 8400. To change this modify the server.xml file in the conf directory.

Modify the line that starts with:

&lt;Connector port=”8080″ Also modify the shutdown port:

&lt;Server port=”8005″ shutdown=”SHUTDOWN”&gt;

Start tomcat from the command line by running:

Linux / Unix vareties – <a href=”http://catalina.sh/”>catalina.sh</a> run

Windows – catalina.bat run

9) You can also start tomcat in a new window by running <a href=”http://catalina.sh/”>catalina.sh</a> start. Tomcat will output the log file to the catalina.out file in the logs directory.

10) To connect to the tomcat manager use the URL:

<a href=”http://localhost:8080/manager/html”>http://localhost:8080/manager/html</a>

Adobe BlazeDS comes with a bundled Tomcat Server. Some things should be noted when using it with Anvil.

1) Under the Blaze DS Tomcat directory is a lib directory. Under there is an activemq4.1.1 directory. The libraries in this directory conflict with the anvil libraries. So this directory either needs to be deleted or moved out of the tomcat directory.

2) BlazeDS Tomcat runs on port 8400 so the URL is localhost:8400

3) Be sure to set the catalina home environment variable to the BlazeDS Tomcat Server, i.e. CATALINA_HOME= C:appsblazeds_b1_121307tomcat

SETTING UP ANT

Installing Ant is as easy as unzipping it. Ant is only needed if you want to build from the source

1) Download Ant and unzip it. It is recommended to put it in the apps directory.

2) Set the ANT_HOME environment variable, i.e. ANT_HOME= C:appsapache-ant-1.7.0

3) Add the ant bin to the PATH environment variable, i.e. %ANT_HOME%bin or $ANT_HOMEbin

4) You should now be able to test ant by running ant -version

JAVA ON MAC OS X TIPS

The latest Mac OS X now has Java 1.6 included, but it is not enabled by default.

2) Java on the Mac OS X is installed into the directory:

/System/Library/Frameworks/JavaVM.framework/Versions

From there you need to specify the version you want to use.

3) The Java binaries are in the Commands directory, instead of the usual bin directory. This breaks a lot of scripts. A simple fix is to cd to the Java home directory and run:

sudo ln -s Commands bin

sudo causes the command to be run with root permissions. ln -s creates a soft link from Commands to bin.

You can then modify the <a href=”http://setup.sh/”>setup.sh</a> script to point to the version of Java you want. Here is my file.

WINDOWS SETUP TIPS

The first tip for setting up Windows would be simply don’t! Move to another platform such as Ubuntu or Mac OS X if at all possible, it makes development so much easier!

1) Setting environment variables on Windows:

a. Right click on my computer or go to control panel and select system.

b. On the dialog box select the advance tab and then select environment variables.

c. Add a new environment variable

d. For example on my machine JAVA_HOME= C:appsjdk1.5.0_07

e. You can reference other environment variables using %NAME%. For example to add the Java bin directory related to the JAVA_HOME environment variable to PATH, you would add – %JAVA_HOME%bin to the FIRST of the PATH environment variable.

2) For Windows I recommend using Cygwin which provides a Linux-Like environment.

a. Download Cygwin and run the installer.

b. When you install cygwin you can change the view in the upper right from packages to full. Some optional packages that are worth installing are:

Subversion

OpenSSH

Ryan Knight flex