Showing posts with label Configuration. Show all posts
Showing posts with label Configuration. Show all posts

Sunday, June 29, 2014

Maven - Change location of local repository

maven logo
A repository in Maven is used to hold build artifacts and dependencies of varying types. There are strictly only two types of repositories: local and remote. The local repository refers to a copy on your own machine that is a cache of the remote downloads and also contains the temporary build artifacts that have not yet been released. The following post will show how to change the location of the local Maven repository on Windows.


This post assumes that Maven is installed on your computer. If not please check the following post on how to install and configure Maven.

Maven is configured based on a 'settings.xml' file that can be specified at two levels:
  1. User Level: provides configuration for a single user and is typically provided in '${user.home}/.m2/settings.xml'.
  2. Global level: provides configuration for all Maven users on a machine (assuming they're all using the same Maven installation) and it's typically provided in '${maven.home}/conf/settings.xml'.

In this example we will change the local repository location by creating/editing a 'settings.xml' file at user level.

Navigate to [maven_install_dir]/conf and if not already present copy the 'setting.xml' file to the '.m2' directory located in the user home directory (in this example the user is source4code) as shown below.

user home directory

Open the copied 'settings.xml' file and add/update the '<localRepository>' element to point to the new location of the local repository (in this example the location is set to "C:\source4code\local-repo").
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
<!-- localRepository
| The path to the local repository maven will use to store artifacts.
|
| Default: ${user.home}/.m2/repository
<localRepository>/path/to/local/repo</localRepository>
-->
<localRepository>C:\source4code\local-repo</localRepository>

...

</settings>

Next time Maven tries to resolve and download dependencies to the local repository, they will be stored in the newly defined location. The below image shows the result after creating a quickstart Maven project. The artifacts are now downloaded to the 'C:\source4code\local-repo' directory that was configured in the above 'settings.xml'.

maven change local repository location


This concludes configuring the location of the local repository for Maven. If you found this post helpful or have any questions or remarks, please leave a comment.

Saturday, April 26, 2014

Blogger - Setup SyntaxHighlighter

syntaxhighlighter logo
Blogger, the blog-publishing service from Google, does not provide a syntax highlighter out of the box. This means you need to resort to third party solutions in order to have syntax highlighting in your posts. One of those solutions is the awesome syntax highlighter created by Alex Gorbatchev which is called SyntaxHighlighter. The big advantage of this highlighter is that it is purely written in JavaScript and as a result it does not need a server side component and can be easily integrated into blogger. Following tutorial will detail how to setup and use SyntaxHighlighter on your Blogger blog.

SyntaxHighlighter Install

First thing to do is to open the dashboard of your Blogger blog as shown below. On the left hand side find the menu that says Template and click on it.

blogger template

This will open the template page of your blog. Click on the button that says Edit HTML in order to open up the HTML editor as shown below.

blogger edit html

Click anywhere inside the editor window and press CTRL+F. A search box should now appear in the upper right hand corner as shown below. In the search box enter "</head>" (without quotes) and press ENTER.
 
blogger edit html search

The editor window will now jump the end of the HTML header tag where we will add the needed style sheets and JavaScript files. The SyntaxHighlighter configuration consists out of four parts:
  1. The core files
  2. The SyntaxHighlighter theme
  3. The specific brush(es) needed for the blog
  4. The configuration script

1) The core files

The core files consist out of the following JavaScript file and style sheet:
<script src="http://alexgorbatchev.com/pub/sh/current/scripts/shCore.js" type="text/javascript"></script>
<link href="http://alexgorbatchev.com/pub/sh/current/styles/shCore.css" rel="stylesheet" type="text/css"></link>

2) The SyntaxHighlighter theme

There are a number of themes available for SyntaxHighlighter, for the complete list please check following link. The style sheet below is the default theme.
<link href="http://alexgorbatchev.com/pub/sh/current/styles/shThemeDefault.css" rel="stylesheet" type="text/css" />

3) The specific brush(es) needed for the blog

Depending on the structured language that needs to be highlighted, the corresponding brush needs to be imported. For a complete list of all available brushes please check following link. In this example we will add the brushes for 'Java' and 'XML'.
<script src="http://alexgorbatchev.com/pub/sh/current/scripts/shBrushJava.js" type="text/javascript"></scrip>
<script src="http://alexgorbatchev.com/pub/sh/current/scripts/shBrushXml.js" type="text/javascript"></script>
Only add the needed brushes as for each page the brushes are retrieved from alexgorbatchev.com (the SyntaxHighlighter site) as this increases your blog page load times!

4) The configuration script

After all needed dependencies have been added we need to enable a specific mode for Blogger and instruct SyntaxHighlighter to highlight all code blocks found on the web page. This is done by adding a JavaScript snippet as shown below.
<script language="javascript" type="text/javascript">
SyntaxHighlighter.config.bloggerMode = true;
SyntaxHighlighter.all();
</script>


The complete script to be inserted in the Blogger template is shown below. Copy and paste right before the '</head>' tag as shown on the screenshot.
<!-- 'SyntaxHighlighter' additions START -->
<script src="http://alexgorbatchev.com/pub/sh/current/scripts/shCore.js" type="text/javascript"></script>
<link href="http://alexgorbatchev.com/pub/sh/current/styles/shCore.css" rel="stylesheet" type="text/css" />
<link href="http://alexgorbatchev.com/pub/sh/current/styles/shThemeDefault.css" rel="stylesheet" type="text/css" />
<script src="http://alexgorbatchev.com/pub/sh/current/scripts/shBrushJava.js" type="text/javascript"></script>
<script src="http://alexgorbatchev.com/pub/sh/current/scripts/shBrushXml.js" type="text/javascript"></script>

<script language="javascript" type="text/javascript">
SyntaxHighlighter.config.bloggerMode = true;
SyntaxHighlighter.all();
</script>
<!-- 'SyntaxHighlighter' additions END -->

blogger save template

Click the Save template button to save the changes made to your Blogger template. This concludes the setup, in the next section will see how to use SyntaxHighlighter.

SyntaxHighlighter Usage

In order to use SyntaxHighlighter we need to wrap the section to be highlighted with an XML tag called <pre>. This tag has one required parameter called 'brush' which is the same brush that was added in section 3 of the above setup.

For this example we will add a HelloWorld Java class to a <pre> tag with a 'Java' brush and a Hello World XML file to a <pre> tag with a 'XML' brush. Copy the below code and paste it inside a Blogger post as shown.
Make sure all right angle brackets within the <pre> tags are HTML escaped, in other words all "<" (less than character) must be replaced with "&lt;" (without quotes, as highlighted below)!
<pre class="brush: java">
public class HelloWorld {

public static void main(String[] args) {
System.out.println("Hello World!");
}
}
</pre>

<pre class="brush: xml">
&lt;?xml version="1.0" encoding="UTF-8" ?>
&lt;text>Hello World!&lt;/text>
</pre>

blogger syntaxhighlighter syntax

Save and publish the page and the result should look like:
syntaxhighlighter example

SyntaxHighlighter Options

In addition to the mandatory 'brush' parameter, the <pre> tag has a number of optional parameters. For example it is possible to highlight one or more lines to focus the reader's attention by adding the 'highlight' parameter as shown below. The full list of available parameters can be found here.
<pre class="brush: java; highlight: [3,4,5]">
public class HelloWorld {

public static void main(String[] args) {
System.out.println("Hello World!");
}
}
</pre>

The result of above snippet:
syntaxhighlighter highlight example


This concludes setting up SyntaxHighlighter on Blogger. If you found this post helpful or have any questions or remarks, please leave a comment.