Learn Shark II from scratch -
Start engine and landing
(Hongyun translation, CYGNET open source workflow group,
2005-4-15
)
Original address: http://shark.objectweb.org/doc/sfs/sharkfromscratch2.html
In this document, I briefly describe the creation of instance code. As before, I don't plan to involve all the topics that are not directly related to this article. First, you have to know how to write, compile and execute the Java program. In addition, you need to have a SHARK run version and can use the management program provided by Shark.
As before, I have installed the following procedures:
MySQL - I use
4.0.16
-NT MySQL Connector - I use mysql-connector-java-
3.0.11
-stable-bin.jar ant 1.6.x - not required, but I offer a build file .... Java - I use Sun J2SDK Version
1.4.2
_04CVS, Winzip, and so on.
After performing the following command, my Shark Build is installed in the C: / Shark directory.
Make -install
The strategy I use is to repeat some classes to demonstrate how to use it in Shark. The interface is a command line outside Main Method. The purpose of this is to let the new user can easily start and comfort the Shark.
file
You can read these files and click on the link to the source code, which is generated by java2html java2html (www.java2html.com). In addition, I have provided the source code and Ant Build files. You can find them here.
Start using Shark
Start using Shark as simple as follows:
Shark.configure (New Properties));
That is to say, first configure Shark (see Shark From Scratch (learn Shark from the head)). So you need to make sure all JAR files are available. The code we build here is not in the Shark directory.
The smallest JAR file collection that can start Shark is (according to my configuration):
C: /shark/lib/sharkkernel-standard.jar c: /shark/lib/sharkclientapi.jar c: /shark/lib/sharkcommonapi.jar c: /shark/lib/sharkinternalnalapi.jar C: / Shark / lib / sharkxpdl -standard.jar c: /shark/lib/sharkinstancePersistence-dods.jar c: /shark/lib/dods-runtime.jar c: /shark/lib/util.jar c: /shark/lib/sharkutilities-dods.jar C: / shark / lib / mysql-connector-java-
3.0.11
-stable-bin.jar c: /shark/lib/sharkrepositoryPersistence-dods.jar c: /shark/lib/sharkscripting-standard.jar c: /shark/lib/sharkutilities-Map.jar C: / Shark / lib / sharkutilities -Misc.jar c: /shark/lib/xerceptimpl.jar c: /shark/lib/xml-apis.jar
Construction instance
Because the amount of code is small, I will listen to it here, let everyone know deeply. Of course, I also provide all source code and a script file, see here. This example can be found in the first package. Run "Ant -P" to see the goal of achieving the situation. If you are not using C: / Shark as your installation directory, you must change the properties value of Shark.dir in your build script file. Our class is called Simple.
Let's take a look at the code before running:
Package first;
Import org.enhydra.shark.shark;
Import java.util.properties;
Import java.io.fileinputstream;
/ **
* Does Nothing More Than Start The Shark Engine.
* /
Public Class Simple
{
Public static void main (string [] args)
{
Try
{
Properties PROPS = New Properties ();
Props.Load (New FileInputStream ("c: //shark/shark.conf"));
System.out.println ("Enginename from Shark.conf Is:" Props.GetProperty ("Enginename"));
// Make Sure Every Instance of Shark That Connects To The Same Database Uses A Different
// Enginename.
Props.SetProperty ("Enginename", "RROSS");
Shark.configure (PrOPS);
}
Catch (Exception E)
{
// it's not Like I am going to revive the thing if it crashes ...
E.PrintStackTrace ();
}
}
}
The code is quite simple, it implements loading the Properties file, providing a different engine name and passes the property object to Shark.
Start your engine
To run it, you can enter "Ant Runfirst" in the DOS command. When executing the command, you have to look at the subsequent output.
C: / dev / sharkfromscratch> Ant Runfirst
Buildfile: build.xml
Runfirst:
[Java] Enginename from Shark.conf Is: Shark
[Java] SharkengineManager -> Shark Engine Is Being Initialized ...
[java] file dodsconf.xml NOTSTS ON PATH: 'DODSCONF' USING DEFAULT INSTED
[Java] Shark -> Initializing of Shark Engine Has Finished
[Java] Shark -> Initializing Lasted 5 [S]
[Java] Shark -> FIRSTENGINE READY WAITING ...
Build Successful
Total Time: 6 seconds
In addition to an exception, others are normal. This exception is "File Dodsconf.xml NOT EXISTS ON PATH: 'DODSCONF' USING DEFAULT INSTED". Ignoring the grammar and spelling errors, that is, the backup of Dodsconf.xml cannot be found. If I make a quick search in the Shark directory, I can see doDSconf.xml does exist. What happened is that the Shark.conf file has a default relative path when you run in a directory containing the build file (I am C: / DEV / SharkFromScratch), Shark can find all configuration files and other information. Patch configuration file
It is not the Shark.conf file on the hard disk, but the editor passes the various properties of the Shark engine when starting. This makes I can better control what will come in, so that I can continue to use "Official" Shark.conf files in the application (such as Runsa.bat, without having to change it often.
Before delivering to Shark, I will load the properties file and pre-consider the Shark installation directory of all the relevant file names in the property.
In Second.SIMPLE, you can see the above. It is not incredible, I have already hilly encode Shark's installation path, which is indeed completed.
Run it, you will get the following output (or very similar)
C: / dev / sharkfromscratch> Ant Runsecond
Buildfile: build.xml
Runsecond:
[java] FIXING UP SHARK Config
[Java] SharkengineManager -> Shark Engine Is Being Initialized ...
[Java] Shark -> Initializing of Shark Engine Has Finished
[Java] Shark -> Initializing Lasted 5 [S]
[Java] Shark -> SecondEngine Ready and Waiting ...
Build Successful
Total Time: 6 seconds
As you can see, Shark is no longer a complaint because of the Dodsconf.xml file. At this point, we launched Shark correctly.
Drilling in depth Shark
Since we can start Shark, let's take a look at what we can get. The third package is our first try to build a program. The Workflow class provides a method called init, this method contains the work we have done so far.
log in
Next, we log in. In fact, what we have to do is to get a SharkConnection object, we call it CONNECT METHOD. This code snippet is from the Login method.
Sharkconnection conn = shark.getinstance (). GetsharkConnection ();
Try
{
Conn.connect (username, password, prons.getproperty ("enginename"), NULL);
}
The fourth parameter of the connection command is 'scope', but I found it without anything in the last check. In the build.xml file provided, use "Runthird", we should change the results below.
C: / dev / sharkfromscratch> ant runthird
Buildfile: build.xml
Runthird:
[Java] Fixing Up Shark Config [Java] SharkenGineManager -> Shark Engine is Being Initialized ...
[Java] Shark -> Initializing of Shark Engine Has Finished
[Java] Shark -> Initializing Lasted 5 [S]
[Java] Shark -> Thirdengine Ready and Waiting ...
Build Successful
Total Time: 6 seconds
You may notice that the system does not provide new information when logging in. This is good because the connection is not empty, and there is no abnormality thrown, so we will continue.
After calling the recreatedb, this new database does not actually have any users, noted that this is important. If you haven't done this, you can run the Shark Swing application (I am c: /shark/runsa.bat here) and log in with the username "admin" and password "endra". This will create an "admin" user. In fact, if you log in to the Swing application with unknown username, it will create a new user according to your username and password you provide.
Classpaths
In the build.xml file provided, all the targets have the same class path, but as you can see, I have already reviewed it in front of you, so that you can determine what files you need at any point. For a specific installation, it is not necessary for all the files generated by Shark, so this will help you tain your Class Path.