forked from verhas/jScriptBasic
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.html
More file actions
176 lines (139 loc) · 11.5 KB
/
Copy pathinstall.html
File metadata and controls
176 lines (139 loc) · 11.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<!--
| Generated by Apache Maven Doxia at Jan 17, 2013
| Rendered using Apache Maven Fluido Skin 1.2.1
-->
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>jScriptBasic - jScriptBasic Project Documentation</title>
<link rel="stylesheet" href="./css/apache-maven-fluido.min.css" />
<link rel="stylesheet" href="./css/site.css" />
<link rel="stylesheet" href="./css/print.css" media="print" />
<script type="text/javascript" src="./js/apache-maven-fluido.min.js"></script>
<meta name="author" content="Peter Verhas" />
<meta name="Date-Creation-yyyymmdd" content="20120811" />
<meta name="Date-Revision-yyyymmdd" content="20130117" />
<meta http-equiv="Content-Language" content="en" />
</head>
<body class="topBarDisabled">
<div class="container-fluid">
<div id="banner">
<div class="pull-left">
<a href="http://scriptbasic.com" id="bannerLeft">
<img src="" alt="ScriptBasic for Java"/>
</a>
</div>
<div class="pull-right"> </div>
<div class="clear"><hr/></div>
</div>
<div id="breadcrumbs">
<ul class="breadcrumb">
<li id="publishDate">Last Published: 2013-01-17</li>
<li class="divider">|</li> <li id="projectVersion">Version: 1.0.4-SNAPSHOT</li>
<li class="pull-right"> <a href="http://scriptbasic.com" class="externalLink" title="ScriptBasic">ScriptBasic</a>
</li>
</ul>
</div>
<div class="row-fluid">
<div id="leftColumn" class="span3">
<div class="well sidebar-nav">
<h3>Documentation for SB4J</h3>
<ul>
<li class="none">
<a href="intro.html" title="Introduction">Introduction</a>
</li>
<li class="none">
<a href="name.html" title="Name of the game">Name of the game</a>
</li>
<li class="none">
<a href="design.html" title="History and Design Goals">History and Design Goals</a>
</li>
<li class="none">
<a href="basic.html" title="Basic Language Implemented">Basic Language Implemented</a>
</li>
<li class="none">
<strong>Installation</strong>
</li>
<li class="none">
<a href="advanced/index.html" title="Embedding API">Embedding API</a>
</li>
<li class="none">
<a href="configure.html" title="Configuration">Configuration</a>
</li>
</ul>
<h3>Project Documentation</h3>
<ul>
<li class="collapsed">
<a href="project-info.html" title="Project Information">Project Information</a>
</li>
<li class="collapsed">
<a href="project-reports.html" title="Project Reports">Project Reports</a>
</li>
</ul>
<hr class="divider" />
<div id="poweredBy">
<script type="text/javascript" src="https://apis.google.com/js/plusone.js"></script>
<div class="g-plusone" data-href="http://www.scriptbasic.com" data-size="tall" ></div>
<div class="clear"></div>
<div class="clear"></div>
<div class="clear"></div>
<a href="http://maven.apache.org/" title="Built by Maven" class="poweredBy">
<img class="poweredBy" alt="Built by Maven" src="./images/logos/maven-feather.png" />
</a>
</div>
</div>
</div>
<div id="bodyColumn" class="span9" >
<div class="section"><h2>Installing ScriptBasic for Java<a name="Installing_ScriptBasic_for_Java"></a></h2><p>There are two different uses of ScriptBasic for Java. The simpler one when you just want to start some BASIC program from the command line. The binary package of ScriptBasic is a Java JAR file that contains an appropriately configured main class that can be executed. The other use is when you want to invoke BASIC scripts from some application and you want to use ScriptBasic for Java as an embedded script language interpreter.</p><div class="section"><h3>Command line use<a name="Command_line_use"></a></h3><div class="section"><h4>SHORT<a name="SHORT"></a></h4><p>Just start the jar file using java.</p></div><div class="section"><h4> LONG<a name="aLONG"></a></h4><p>Check that the Java runtime environment (JRE) is installed on your system. To do that you can execute the command</p><div><pre>java -version</pre></div><p>and you should get some output like</p><div><pre>java version "1.7.0_04"
Java(TM) SE Runtime Environment (build 1.7.0_04-b21)
Java HotSpot(TM) 64-Bit Server VM (build 23.0-b21, mixed mode)</pre></div><p>The version of the build number may be different but make sure that the java version you use is 1.7 or later. SB4J requires java 7.</p><p>Locate the SB4J JAR file and the BASIC program you want to execute. Make sure that the BASIC program is in a file that has the extension <tt>sb</tt> or <tt>bas</tt>. Execute the following command line</p><div><pre>java -jar jscriptbasic-x.y.z.jar myProgram.sb</pre></div><p>where <tt>x.y.z</tt> is the version of the interpreter and is part of the file name of the jar file in the distribution. For the hello world example on the development server I execute</p><div><pre>java -jar target/jscriptbasic-1.0.0-SNAPSHOT.jar src/test/basic/hello.sb</pre></div><p>which will print <tt>hello</tt>.</p></div></div><div class="section"><h3>Embedded use<a name="Embedded_use"></a></h3><div class="section"><h4>SHORT<a name="SHORT"></a></h4><p>Place the JAR file on the classpath and use the JSR-223 standard interface to invoke ScriptBasic or use the ScriptBasic for Java native interface.</p></div><div class="section"><h4>LONG<a name="LONG"></a></h4><p>Place the JAR file on the classpath and use the native interface</p><div class="source"><pre class="prettyprint"> EngineApi engine = new Engine();
engine.eval("print \"hello world\"");
</pre></div><p>to evaluate some JavaScript. <a href="./advanced/nativeapi.html">... more on the native api</a>. </p><p>SB4J is compliant with the <a class="externalLink" href="http://www.jcp.org/en/jsr/detail?id=223">JSR-223</a> standard. If you use this interface to integrate ScriptBasic into your application you need know know anything that is specific to jScriptBasic. All you have to do it copy the JAR file to a location so that the Java class loader will find it. After that start up your application and the JRE will load ScriptBasic automatically using the standard <a class="externalLink" href="http://docs.oracle.com/javase/7/docs/api/java/util/ServiceLoader.html">ServiceLoader</a> interface.</p><p>To get a fast track to integrate jScriptBasic into an application you can have a look at the source code that implements the command line version of the interpreter and embeds the interpreter into a 'main' class.</p><p>The code is in the package <tt>com.scriptbasic.main</tt> and the class is <tt>CommandLine</tt>. The important part is:</p><div class="source"><pre class="prettyprint"> ScriptEngineManager sem = new ScriptEngineManager();
ScriptEngine se = sem.getEngineByExtension(extension);
if (se != null) {
ScriptContext context = se.getContext();
PrintWriter outWriter = new PrintWriter(System.out);
context.setWriter(outWriter);
PrintWriter errorWriter = new PrintWriter(System.err);
context.setErrorWriter(errorWriter);
context.setReader(new InputStreamReader(System.in));
Reader reader = new FileReader(basicProgramFileName);
try {
se.eval(reader, context);
} catch (ScriptException sce) {
Exception cause = (Exception) sce.getCause();
if (cause == null) {
cause = sce;
}
if (cause.getMessage() != null) {
System.err.println("ERROR: " + cause.getMessage());
} else {
throw sce;
}
}
outWriter.flush();
errorWriter.flush();
} else {
System.err
.println("ERROR: There is no suitable interpreter for that file.");
}
</pre></div><p>The code creates a new <tt>javax.script.ScriptEngineManager</tt> that manages the loading and the location of the interpreter. The command line version of ScriptBasic for Java asks the script engine manager to create an interpreter based on the file name extension. As a side effect you can also execute JavaScript programs from the command line using the jScriptBasic JAR. The JavaScript interpreter is included in the JRE since the version 1.7</p><p>The following few lines set the standard and error input and output for the program and finally the script is executed. At the end the output is flushed and closed so that the characters that were printed by the BASIC program are sent out to the console.</p><p>To have the interpreter on the command line you can manually copy the JAR file to the classpath, or you can add the JAR file to the build process. If you use maven use the following dependency:</p><div><pre><dependency>
<groupId>com.scriptbasic</groupId>
<artifactId>jscriptbasic</artifactId>
<version>1.0.0</version>
</dependency></pre></div><p>At the moment the latest release is <tt>1.0.0-SNAPSHOT</tt>. For the actual state of the different releases have a look at the page <a href="./releases.html">releases</a>.</p><p>Starting on the <a href="./advanced/jsr223tutorial.html">page</a> you will find a detailed tutorial on how to embed ScriptBasic for Java using the JSR223 standard interface.</p></div></div><div class="section"><h3>Advanced<a name="Advanced"></a></h3><p>The advanced use of ScriptBasic for Java invoking the special functionalities that are not available through the JSR223 standard interface are detailed in a series of separate <a href="./advanced/index.html">pages here</a>.</p></div></div>
</div>
</div>
<hr/>
<footer>
<div class="container-fluid">
<div class="row span16">Copyright © 2013
<a href="http://www.verhas.com">Verhas and Verhas Software Craftsmen</a>.
All Rights Reserved.
</div>
</div>
</footer>
</body>
</html>