As one that seldom finds himself having to run Java Applications from a Unix Bash Script, I thought it would be helpful to share the appropriate commands i use to execute the code and to notify the user of success or failure. For reference the folder structure I use is:
where the lib folder contains all necessary jar files to run the application, and the config folder contains any properties or configuration files passed as run time arguments
Writing the script
- Specify the script is a bash script
- Define SUCCESS and FAILURE variables
- Define the appdirectory
- Define the lib folder variable
- Define the classpath variable. This is a : seperated list of jars needed by the application
CP=${LIB}abc.jar:${LIB}xyz.jar
- Define java home
APP_JAVA_HOME=/usr/jdk/instances/jdk1.5.0
- Execute the Application with any arguments and java settings
${APP_JAVA_HOME}/bin/java -ms256m -cp "${CP}"
com.mdibtz.TestApp "${APP_HOME}/config/config.properties"
- Test for Failure
if [ $? -ne 0 ]
then
exit ${FAILURE}
fi
- Success Logic if needed
Complete Script
#!/bin/bash
FAILURE=1
SUCCESS=0
APP_HOME=`pwd`
LIB=${APP_HOME}/lib/
CP=${LIB}activation-1.1.jar:${LIB}mail-1.4.jar
APP_JAVA_HOME=/usr/jdk/instances/jdk1.5.0
${APP_JAVA_HOME}/bin/java -ms256m -mx768m -cp "${CP}"
com.mdbitz.TestApp "${APP_HOME}/config/config.properties"
if [ $? -ne 0 ]
then
echo "AppFailed during run"
exit ${FAILURE}
fi
echo "App successfully run"
exit ${SUCCESS}
bash, java application, run java on unix, Unix
When transferring files between Windows and Unix you may find that on occasions your file has been modified and that ^M characters exist at end of lines. This problem is caused when files are transferred to the server as Binary. However if you change the type to ASCII then you will find that the ^M characters are not added. If however you find the file has ^M characters then Unix provides a handy dos2unix command to strip the unwanted ^M characters. For full reference unix2dos is also provided to format the file back.
dos2unix usage:
dos2unix <file> <output_file>
dos2unix, unix2dos, ^M
Want to add Search Capabilities to your website and don’t know where to start? Then Google AJAX Search API might be for you. The AJAX Search API provided by Google enables you to embed a search box into your web pages and display the results in your webpage in your own desired format and style. The perhaps nicest thing about utilizing the API is that it is free and does not require an account unlike Google’s Site Search that costs a minimum of $100 a year. However if you do sign up then if errors are encountered while retrieving your search results Google has the ability to notify you so that the issue can be resolved.
To get started Google provides documentation, examples, and even a code playground that has multiple examples that you can customize in place to view the results.
Google Search API, Search AJAX API, Search API
On today’s websites it is good practice to utilize a contact form instead of a mailto link. However you will find the occasions when you find the need to add a contact reference that does not require a form. In this cases you will find that you may want to set a predefined subject or even some body text. Below is a quick overview of how you can set these elements of the email from the mailto link.
General Format
The mailto format is similar to a website url in that you define the recipients followed by query parameters containing additional properties. Below is a quick format example:
mailto:address1,address2?prop1=value1&prop2=value2
Properties
| Recipients |
comma seperated list following mailto:
|
| Copy To or CC Recipients |
cc=emailaddress |
| Blind Copy To or BCC Recipients |
bcc=emailaddress |
| Subject |
subject=text here |
| Body |
body=Email message |
MailTo
UPDATE: Current Release details and download available here
Harvest Users may or may not be familiar with the Harvest API that can be used to access and manipulate timesheets, clients, projects, tasks, and more. Since Harvests creation they have been integrating with other 3rd party applications and to communicate information across channels they created the Harvest API.
Harvest users can use this same API to utilize information in their Harvest account in their own applications. Currently their is an open-sourced Harvest Ruby wrapper that can be from github. But as I prefer to utilize PHP I have created a PHP Wrapper Library for the Harvest API. Currently the API requires cURL support and can be utilized to obtain information from your harvest account but not modification of data. Over the next few months I will be expanding this to include the rest of the functionality of the API.
Example Usage
- Require the HarvestAPI main class
require_once( dirname(__FILE__) . '/HarvestAPI.php' );
- Register the Auto Loader
spl_autoload_register(array('HarvestAPI', 'autoload') );
- Set Account & User information
$api = new HarvestAPI();
$api->setUser( "user@email.com" );
$api->setPassword( "password" );
$api->setAccount( "account" );
- Query the API for desired information
$result = $api->getClient( 1----- );
$result = $api->getProjects();
- Check if request was successfull
if( $result->isSuccess() ) {
...
}
- If successful use the information
$project = $result->data;
echo "Name: " . $project->name;
echo "Id: " . $project->id;
echo "Active: " . $project->active;
Contact
Currently the library is in its first phase so you may encounter some bugs, or issues If you do so please contact me with the details. Also if you find that you need a particular feature of the Harvest API that is currently not supported please also let me know so I can know where to focus my development efforts. I hope that you will find this useful and if you do feel free to leave a comment.
Download
Resources
API Wrapper, Harvest, Harvest API, PHP Library