# How to Set Up the MagTek CMS SDK for Java Demo

#### How to Set Up the Java Library With the 32-bit JRE/JVM

MagTek highly recommends using the 32-bit version of Java when using the PCI PED Java applet, regardless of whether you are using a 32-bit or 64-bit version of Windows.

* Uninstall any existing instances of the 64-bit Java Runtime Environment (JRE) or Java Development Kit (JDK). Leaving them installed can cause runtime failures, as the library may fail to load.
* Download and install the latest version of the 32-bit Java Development Kit (JDK).
* If you opted to manually copy the SDK dependencies from a master development workstation to the target workstation where it will be used, follow these steps:
  * On the master workstation, navigate to the root of the SDK \Library\Java.
  * Open the \x86 subfolder and copy all the files to the target workstation’s C:\Windows\System32 folder for x86 systems, or to the target workstation’s C:\Windows\SysWOW64 folder for x64 systems.
* Connect the device to the workstation using a USB cable. Windows will install the device drivers automatically. Wait for Windows to report the driver installation is complete.
* Launch a Windows command prompt as an Administrator.
* cd to the root of the folders where the SDK is installed.
* Type runsample.bat and press Enter to launch the Java Demo software.

#### How to Set Up the Java Library With the 64-bit JRE/JVM

MagTek highly recommends using the 32-bit version of Java if you intend to use the Java applet, regardless of whether you are using a 32-bit or 64-bit version of Windows.

* Uninstall any existing instances of the 32-bit Java Runtime Environment (JRE) or Java Development Kit (JDK). Leaving them installed can cause runtime failures, as the library may fail to load.
* Download and install the latest version of the 64-bit Java Development Kit (JDK).
* If you opted to manually copy the SDK dependencies from a master development workstation to the target workstation where it will be used, follow these steps:
  * On the master workstation, navigate to the root of the SDK \Library\Java
  * Open the x86 subfolder and copy all the files to the target workstation’s C:\Windows\System32 folder or to the target workstation’s C:\Windows\SysWOW64 folder for x64 systems.
* Connect the device to the workstation using a USB cable. Windows will install the device drivers automatically. Wait for Windows to report the driver installation is complete.
* Launch a Windows command prompt as an Administrator.
* cd to the root of the folders where the SDK is installed.
* Type runsample.bat and press Enter to launch the Java Demo software.

#### How to Set Up the Applet With the 32-bit JRE/JVM

MagTek highly recommends using the 32-bit version of Java when using the Java applet, regardless of whether you are using a 32-bit or 64-bit version of Windows.

To set up the Java applet using the 32-bit version of Java on either a 32-bit or 64-bit version of Windows, follow these steps:

* Follow the steps in section **How to Set Up the Java Library With the 32-bit JRE/JVM**. Having a working JVM, working Java library, working drivers, and working DLLs are prerequisites for using the applet.
* Verify Java is installed and that the Internet Explorer Java plugin is working correctly by using Oracle’s Java applet test page, usually provided as a link or auto-launch at the end of installation.
* On the Windows 7 workstation you will use for development, enable Internet Information Services 7 (IIS) as follows:
  * Log in to a Windows 7 workstation using an administrator account.
  * Launch the Windows Control Panel.
  * Select the Programs and Features item to open the Programs and Features page.
  * On the left side of the page, select the Turn Windows features on or off link to launch the Windows Features window.
  * Turn on the checkboxes for Internet Information Services and Internet Information Services Hostable Web Core.

<figure><img src="/files/uRbGqkt7i4QFtXzdu4ih" alt=""><figcaption></figcaption></figure>

* Press the OK button to launch a progress window. Wait for Windows to install IIS.
* Launch a web browser and navigate to //localhost . Verify the IIS default page appears as shown in **Figure 2-1.**

<figure><img src="/files/DgjCpzrAsn2voOfmRdZ6" alt=""><figcaption></figcaption></figure>

<p align="center">Figure 2-1 IIS Default Page</p>

* If it does not already exist, create a MTPPSCTA folder in C:\inetpub\wwwroot\ . If it does exist, delete its contents.
* On the workstation where the SDK is installed, navigate to the folder where it is installed.
* Open the Sample Code\Java Applet\Object\Signed subfolder.
* Copy the contents of the subfolder to C:\inetpub\wwwroot\MTCMS .
* Open the Sample Code\Java Applet\Object\x85 subfolder.
* Copy the contents of the subfolder to C:\inetpub\wwwroot\MTCMS.

<figure><img src="/files/pNtZH1fVfpamJspLYlBX" alt=""><figcaption></figcaption></figure>

<p align="center">Figure 2-2 - inetpub Structure</p>

* Connect the device to the workstation using a USB cable. Windows will install the device drivers automatically. Wait for Windows to report the driver installation is complete.&#x20;
* Open Internet Explorer as an administrator.
* If you are using a 64-bit version of Windows with IE11, make sure to launch directly in 32-bit mode using the iexplore.exe found in C:\Program Files (x86). Verify you are running in 32-bit mode using the Help>About menu.
* If you are running a 64-bit version of Windows with IE10 or higher, choose the Internet options that enable 32-bit mode / disable Protected Mode for the zone you are accessing. Also turn OFF the checkbox for Enhanced Protected Mode in the Internet Options > Advanced tab.

<figure><img src="/files/xqD6RaLjHX6MX1ywVzIp" alt=""><figcaption></figcaption></figure>

* If you changed the value of the Enable Enhanced Protected Mode checkbox, restart Windows.
* Open Windows Task Manager (Ctrl-Alt-Del > Start Task Manager).&#x20;
* Open the Processes tab and sort by Image Name.&#x20;
* Note the number and location of all iexplore.exe \*32 processes.
* In Internet Explorer, navigate to [http://localhost/MTCMS/magtek-mtcms.html.](http://localhost/MTCMS/magtek-mtcms.html)&#x20;
* In the Windows Task Manager Processes tab, find the new process for the Internet Explorer tab you just opened and make sure it is running in 32-bit mode ( iexplore.exe \*32 instead of iexplore.exe.

<figure><img src="/files/97I0mnSLWWNR4z6NEPxJ" alt=""><figcaption></figcaption></figure>

* Close the Windows Task Manager window.
* Internet Explorer will display a welcome page and will pop up a Do you want to run this application? window. Press the Run button and the Allow button to run the Java applet.

<figure><img src="/files/3nSA7aQEZUhXacZzVmCS" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/ypJWCiifEqAyckZ2NzEF" alt=""><figcaption></figcaption></figure>

* On the welcome page, press the Connect button.&#x20;
* Press the Get Info button. The large text box in the browser will display device information.
* Use the buttons and fields on the welcome page to test the connection to the device.
* After installation on the workstation is complete, future browser sessions do not require the user to launch Internet Explorer as an administrator to use the applet.

#### How to Modify Manifest

The Caller-Allowable-Codebase attribute is used to identify the domains from which JavaScript code can make calls to your RIA without security prompts. Set this attribute to the domain that hosts the JavaScript code. If a call is made from JavaScript code that is not located in a domain specified by the Caller-Allowable-Codebaser attribute, the call is blocked. To specify more than one domain, separate the domains by a space, for example:

```
Caller-Allowable-Codebase: *.yahoo.com *.google.com *.magtek.com *
```

The Application-Library-Allowable-Codebase attribute identifies the locations where your signed RIA is expected to be found. This attribute is used to determine what is listed in the Location field for the security prompt that is shown to users when the JAR file for your RIA is in a different location than the JNLP file or HTML page that starts your RIA. If the files are not in the locations identified, the RIA is blocked. Set this attribute to the domains where the JAR file, JNLP file, and HTML page are located. To specify more than one domain, separate the domains by a space, for example:

```
Application-Library-Allowable-Codebase: *.yahoo.com *.google.com *.magtek.com *
```

For more information regarding the JAR File Manifest Attributes for Security, please visit this website <http://docs.oracle.com/javase/7/docs/technotes/guides/jweb/security/manifest.html>

In order to modify the Manifest file, please follow these steps. You need to do this for: magtek-mtcms-lib.jar.

* Find installation folder by default, the installation folder is: \Sample Code\Java Applet\Object\Unsigned.
* Launch the command prompt and extract the META-INF/MANIFEST.MF from the jar file.&#x20;

```
jar xf magtek-mtcms-lib.jar META-INF/MANIFEST.MF
```

* Open MANIFEST.MF and look for the Caller-Allowable-Codebase and Application-Library-Allowable-Codebase and add your website URL to the list like the example above.&#x20;
* Update the manifest to the jar file.

```
jar umf META-INF/MANIFEST.MF magtek-mtcms-lib.jar
```

#### How to Sign JAR

These instructions provide an overview of obtaining and using Sun Java signing and a digital certificate. Please follow this instruction to sign and verify both MTCMSJavaSample.jar magtek-mtmcms-lib.jar. &#x20;

* Make sure your machine has the latest Java JDK installed.
* Generate a public/private key pair by entering the following command, specifying an alias for your keystore:

```
keytool -genkey -keyalg rsa -alias MyCert
```

* Generate a certificate signing request (CSR) by entering the following command:

```
keytool -certreq -alias MyCert
```

After prompting you to enter the password for your keystore, keytool will generate a CSR.

* Save the certificate received from the Certificate provider as Certname.p7b.
* Import your Digital Certificate by entering the following command:

```
keytool -import -alias MyCert -file Certname.p7b
```

In this string, keytool is requested to import the Digital ID “Certname.cer” into the keystore MyCert.

* Bundle your applet into a Java Application Resource (JAR) file by entering the following command:&#x20;

```
jar cvf C:\MTCMSJavaSample.jar
```

* Sign the files by using jarsigner to sign the JAR file, using the private key you saved in your keystore:

```
jarsigner C:\Magtek-ppscra-applet.jar MyCert 
jarsigner C:\magtek-mtcms-lib.jar MyCert
```

* Verify the output of your signed JAR file by entering the following command:

```
jarsigner -verify -verbose -certs C:\Magtek-ppscra-applet.jar 
jarsigner -verify -verbose -certs C:\magtek-mtcms-lib.jar
```

Please visit this website <https://docs.oracle.com/javase/tutorial/deployment/jar/signing.html> for more information regarding signing JAR files.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://developer.magtek.com/hardware/oem-readers-and-components/oem-readers/odynamo/documentation/programmers-manuals/common-message-structure-mtcms-microsoft-.net-java-applet/how-to-set-up-the-magtek-cms-sdk-for-java-demo.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
