PDA

Archiv verlassen und diese Seite im Standarddesign anzeigen : Java-Applet & JARs...


DocEW
2003-11-03, 15:45:54
Hi,

ich habe ein Java-Applet geschrieben, daß mittels nativem Oracle-Treiber auf eine DB zugreift, ein paar Daten holt und ein PDF mit einer kleinen Grafik erstellt. Das Applet besteht daher quasi nur aus einer Textarea für die Statusmeldungen und einem Button zum Schließen.

Soweit so gut, das ganze läuft mit dem Applet-Viewer von Eclipse 1A. Wenn ich allerdings ganz normal eine HTML-Seite erstelle und das Applet einbinde, lädt er sich irgendwie zu Tode... hab mal ein paar Minuten gewartet, aber es kam nix mehr außer der Meldung unten links "Start: Applet nicht initialisiert".

Mein Verdacht ist, daß ich dem Browser irgendwie noch den Ort der benutzten JAR-Dateien (Oracle-Treiber, JFreeChart etc.) mitteilen muß. Ecplipse regelt das bestimmt irgendwie selbständig, wenn die JARs im entsprechenden Projekt eingetragen sind. Könnte das sein? Oder was könnte noch die Fehlerursache sein?

Gruß & besten Dank,

DocEW

Mr. Tweety
2003-11-03, 16:59:49
Hab ein kleines Applet das auf meine mysql Datenbank zugreift.
Das hab ich bei mir in der HTML Datei stehen

<APPLET CODE = "myclass.class" ARCHIVE = "mysql-connector-java-3.0.6-stable-bin.jar, myarchive.jar" WIDTH = "750" HEIGHT = "1120">

ethrandil
2003-11-03, 18:09:25
btw:
Wieso sollte ein _Applet_ auf eine lokale DB zugreifen?
tuts da nicht gleich eine gui-anwendung eher?

DocEW
2003-11-03, 23:34:17
Hehe, gute Frage... :-)
War im Grunde ein Testballon um zu gucken, wie modular ich programmiert habe. Es war zuerst eine Java-Anwendung, dann habe ich angefangen rumzubasteln ...

Eventuell wird's auch ein Servlet, damit die Leute sich es nicht lokal kopieren und dann 1000+1 Versionen rumschwirren. Ach ja, lokal ist die DB übrigens nicht!

DocEW
2003-11-03, 23:35:47
Original geschrieben von Mr. Tweety
Hab ein kleines Applet das auf meine mysql Datenbank zugreift.
Das hab ich bei mir in der HTML Datei stehen

<APPLET CODE = "myclass.class" ARCHIVE = "mysql-connector-java-3.0.6-stable-bin.jar, myarchive.jar" WIDTH = "750" HEIGHT = "1120">
Jau, das klingt doch sehr vernünftig... werde ich nächste Woche mal ausprobieren, wenn ich wieder arbeiten bin! Thnx! :-)

DocEW
2003-11-10, 16:08:02
Hm, also irgendwie klappt das noch nicht ... ist das mit den packages so richtig?


<html>
<body>
<applet code="packagename\BWOspVertriebApplet.class"
archive = "packagename\lib\itext-1.00.jar,
packagename\lib\jcommon-0.8.6.jar,
packagename\lib\jfreechart-0.9.11.jar,
packagename\lib\classes12.zip"
width="1200" height="400" >
</applet>
</body>
</html>

DocEW
2003-11-10, 16:17:40
Es scheint ein anderes Problem zu sein... ich habe mal in die Java-Console geguckt und folgendes gefunden:

java.security.AccessControlException: access denied (java.io.FilePermission ...usw.)

Kann ein Applet zufällilig keine Property-Dateien lesen? Zumindest ist an genau der Stelle die Exception geworfen worden!

ethrandil
2003-11-10, 16:28:40
Ein applet hatr standardmäßig so manche beschränkungen.

Applets laufen in einer 'Sandbox', die manche Dinge verbietet.

Beispielsweise Zugriffe auf lokale Dateien. Erlaubt sind jedoch Zugriffe auf das eigene Verzeichnis, den eigenen Server.
Beispielsweise http://www.domain.de/meinapplet/Xy.class dürfte auf http://www.domain.de/meinapplet/property.info zugreifen!

Näheres müsste man in den docs finden.

Mr. Tweety
2003-11-10, 16:40:11
Du kannst natürlich auch einfach ein Testzertifikat erstellen und das Applet signieren.

So funktionierts.
Ist leider auf English aber hab keine Ahnung wo ich die deutsche Version hingespeichert hab.
Ist schon ziemlich lange her als ich es das letzte mal gebraucht habe.

------------------------------------
These steps describe the creation of a self-signed applet.
This is useful for testing purposes. For use of public reachable applets,
there will be needed a "real" certificate issued by an authority like VeriSign or Thawte. (See step 10 - no user will import and trust a self-signed applet from an unkown developer).

The applet needs to run in the plugin, as only the plugin is platform- and browser-independent. And without this indepence, it makes no sense to use java...

1. Create your code for the applet as usual.
It is not necessary to set any permissions or use security managers in
the code.

2. Install JDK 1.3
Path for use of the following commands: [jdk 1.3 path]\bin\
(commands are keytool, jar, jarsigner)
Password for the keystore is *any* password. Only Sun knows why...
perhaps ;-)

3. Generate key: keytool -genkey -alias tstkey -keyalg rsa
Enter keystore password: *******
What is your first and last name?
[Unknown]: Your Name
What is the name of your organizational unit?
[Unknown]: YourUnit
What is the name of your organization?
[Unknown]: YourOrg
What is the name of your City or Locality?
[Unknown]: YourCity
What is the name of your State or Province?
[Unknown]: YS
What is the two-letter country code for this unit?
[Unknown]: US
Is CN=Your Name, OU=YourUnit, O=YourOrg, L=YourCity, ST=YS, C=US
correct?
[no]: yes (kann auch sein das du "ja" eingeben musst)

(wait...)

Enter key password for tstkey
(RETURN if same as keystore password):

(press [enter])

4. Export key: keytool -export -alias tstkey -file tstcert.crt

Enter keystore password: *******
Certificate stored in file tstcert.crt

5. Create JAR: jar cvf tst.jar tst.class
Add all classes used in your project by typing the classnames in the
same line.

added manifest
adding: tst.class(in = 849) (out= 536)(deflated 36%)

6. Verify JAR: jar tvf tst.jar

Thu Jul 27 12:58:28 GMT+02:00 2000 META-INF/
68 Thu Jul 27 12:58:28 GMT+02:00 2000 META-INF/MANIFEST.MF
849 Thu Jul 27 12:49:04 GMT+02:00 2000 tst.class

7. Sign JAR: jarsigner tst.jar tstkey
Enter Passphrase for keystore: *******

8. Verifiy Signing: jarsigner -verify -verbose -certs tst.jar

130 Thu Jul 27 13:04:12 GMT+02:00 2000 META-INF/MANIFEST.MF
183 Thu Jul 27 13:04:12 GMT+02:00 2000 META-INF/TSTKEY.SF
920 Thu Jul 27 13:04:12 GMT+02:00 2000 META-INF/TSTKEY.RSA
Thu Jul 27 12:58:28 GMT+02:00 2000 META-INF/
smk 849 Thu Jul 27 12:49:04 GMT+02:00 2000 tst.class

X.509, CN=Your Name, OU=YourUnit, O=YourOrg, L=YourCity, ST=YS, C=US
(tstkey)

s = signature was verified
m = entry is listed in manifest
k = at least one certificate was found in keystore
i = at least one certificate was found in identity scope

jar verified.

9. Create HTML-File for use of the Applet by the Sun Plugin 1.3
(recommended to use HTML Converter Version 1.3)

10. Place a link to the .crt file (created in step 4) in the HTML-File.
This .crt file has to be opened by the browser and has to be set to
trusted,
as the root CA for testing is not known to the browser. For use with
"real" certificates, this step should not be necessary.

I needed two long days, to find out these steps. As the documentation at Sun and other Sites is more confusing than clarifying (due to the hundreds of java, plugin and browser versions), i post the steps here. I hope that others may reach the goal in less time ;-)

I'm working on Microsoft platforms and did not test the steps elsewhere.

---------------------------

Das keystore Passwort ist glaub ich leer.
Einfach return drücken.

Einmal muss man laut anleitung "yes" eingeben.
Bei mir ging es nur mit "ja".

HTML-Konverter brauchst am schluss nicht.

Aber wie gesagt ist schon ziemlich lange her als ich es das letzte mal Java angerührt habe.

DocEW
2003-11-10, 16:40:28
@ethrandil

Tja, dann verstehe ich nicht, warum es nicht funktioniert...
Das Applet ist ist in

\irgendeinVerzeichnis\applet

und die Property-Datei in

\irgendeinVerzeichnis\properties

?(

@Mr. Tweety
Oh, ok... hm, muß ich mir mal anschauen, danke!

DocEW
2003-11-10, 16:52:42
Ok, also hiernach

http://java.sun.com/sfaq/#diff

lädt ein Browser ein Applet immer mit dem applet class loader, sodaß tatsächlich das Applet normalerweise keinerlei Dateien lesen kann, selbst wenn es (das Applet) lokal auf der Platte ist. :(

ethrandil
2003-11-10, 16:56:30
Diese Einstellung müsstest du umgehen können, aber damit würdest du allen Applets einiges mehr erlauben als ihnen gut tut.

DocEW
2003-11-10, 17:03:52
Argh... so ein Ärger. Naja, was soll's. Ärgerlich nur der Aufwand. Ich hatte mit dem Applet-Viewer von Eclipse extra vorher getestet, ob ein Applet Dateien lesen kann... naja, das hat halt funktioniert. Anscheinend benutzt der Applet-Viewer nicht diesen applet class loader. :(
Dann mach ich's halt als Servlet - ist eh sinnvoller! =)

P.S.: Vielen Dank noch für eure Hilfe!!!

HellHorse
2003-11-10, 23:17:02
Die andere Möglichkeit ist natülich WebStart (http://java.sun.com/products/javawebstart/). Meiner Meinung nach die bessere Wahl als Applets, wenn es ein "Programm" und nicht webbasierend sein soll.

Das Zeugs muss allerdings auch signiert werden.