# Include java applet in ruby on rails web pages

**URL:** <https://www.ruby-forum.com/t/include-java-applet-in-ruby-on-rails-web-pages/69530>\
**Category:** Rails\
**Created:** [September 21, 2006, 4:44pm UTC](https://www.ruby-forum.com/t/include-java-applet-in-ruby-on-rails-web-pages/69530 "2006-09-21T16:44:15Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [September 21, 2006, 4:44pm UTC](https://www.ruby-forum.com/t/include-java-applet-in-ruby-on-rails-web-pages/69530/1 "2006-09-21T16:44:15Z")

</div>

# Hi, I am new to Ruby on Rails world, and would like to combine the ease of RoR web programming with rich graphics and applications from java applets. Wonder if anyone have tried that before? I am having difficulty to use java applet in my .rhtml view files. I ran a simple test case (files given below) and got error that applet could not be started (notinited) or loading java applet failed. When I ran the web page directly (changing Hello.rhtml to Hello.html), it ran fine. I also noticed that in the log file from rails the applet was loaded twice. Like to find out how to include an applet in a ,rhtml file. Please help. Sincerely, HT Yeh

applet\_controller

class AppletController \< ApplicationController  
def Hello  
end  
end

Hello.rhtml

Hello.java (to compile into Hello.class)

import java.awt._;  
import javax.swing._;

public class Hello extends JApplet  
{  
public void init()  
{  
Container contentPane = getContentPane();  
JLabel label = new JLabel(“Hello”, SwingConstants.CENTER);  
contentPane.add(label);  
}  
}

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [September 21, 2006, 7:20pm UTC](https://www.ruby-forum.com/t/include-java-applet-in-ruby-on-rails-web-pages/69530/2 "2006-09-21T19:20:46Z")

</div>

Have you tried using the tag? is really meant for IE  
only,  
otherwise you do have the tag. Also, is the class file in the  
right  
location for Rails to find it? Though I don’t know where the best place  
to  
put it is, whether in public/ or next to the rhtml.

Jason

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [September 21, 2006, 9:55pm UTC](https://www.ruby-forum.com/t/include-java-applet-in-ruby-on-rails-web-pages/69530/3 "2006-09-21T21:55:15Z")

</div>

On Thu, Sep 21, 2006 at 01:16:19PM -0400, Jason R. wrote:

> Have you tried using the tag? is really meant for IE only,

No, “object” is made for standards compliance. Please read up on html  
before trying to explain it to others…

> otherwise you do have the tag. Also, is the class file in the right  
> location for Rails to find it? Though I don’t know where the best place to  
> put it is, whether in public/ or next to the rhtml.

In public. Unless it’s a template of some sort, it doesn’t belong in  
app/views.

> >

You might want to look around on the [w3.org](http://w3.org) site for information on the  
object tag. I believe that for modern html, you need only do something  
like this:

You don’t have java ☹

With the text in there being the “alternative” text. I use very similar  
syntax for embedding a couple of flash elements into a site that I’ve  
recently completed and it works great. No “applet” or “embed” tags, and  
it’s much cleaner syntax because of it.

## Michael

Michael Darrin Chaney  
removed\_email\_address@domain.invalid  
[http://www.michaelchaney.com/](http://www.michaelchaney.com/)

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [September 22, 2006, 3:05am UTC](https://www.ruby-forum.com/t/include-java-applet-in-ruby-on-rails-web-pages/69530/4 "2006-09-22T03:05:47Z")

</div>

+1 for Jason

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [September 22, 2006, 5:02am UTC](https://www.ruby-forum.com/t/include-java-applet-in-ruby-on-rails-web-pages/69530/5 "2006-09-22T05:02:15Z")

</div>

You need to export the classpath and javahome before running ruby  
script/server so that it can find the class…(I think)

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [September 21, 2006, 10:33pm UTC](https://www.ruby-forum.com/t/include-java-applet-in-ruby-on-rails-web-pages/69530/6 "2006-09-21T22:33:22Z")

</div>

So Sun is completely wrong about applet deploying?

> **[JDK 20 Documentation - Home](https://docs.oracle.com/en/java/javase/20/)**
>
> The documentation for JDK 20 includes developer guides, API documentation, and release notes.

Man the w3 site is frustrating to navigate. Finally found:

[http://www.w3.org/TR/html4/struct/objects.html#edef-OBJECT](http://www.w3.org/TR/html4/struct/objects.html#edef-OBJECT)  
[http://www.w3.org/TR/html4/struct/objects.html#edef-APPLET](http://www.w3.org/TR/html4/struct/objects.html#edef-APPLET)

So the w3 standard is as says, but that means what? We all know that  
browsers are not fully W3 standardized, especially IE, so I’ll ask  
again:

Have you tried other tags besides object?

And maybe try informing instead of berating next time, it’s very  
unbecoming.

Jason

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [September 22, 2006, 5:08am UTC](https://www.ruby-forum.com/t/include-java-applet-in-ruby-on-rails-web-pages/69530/7 "2006-09-22T05:08:17Z")

</div>

here’s my example crap (just threw it together out of interest… but  
in case you need it)  
-----------------------------views/test/index.rhtml------------------------------------------------------

-----------------------------command line  
crap----------------------------------------------------------

### Note, I just threw your Hello.java in the jdk bin directory and

compiled it from there…

C:\rails\javatest\>set CLASSPATH=“C:\Program Files\Java\jdk1.5.0\_07\bin”  
C:\rails\javatest\>set JAVAHOME=“C:\Program Files\Java\jdk1.5.0\_07\bin”  
C:\rails\javatest\>ruby script/server

good luck…

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [September 22, 2006, 5:48am UTC](https://www.ruby-forum.com/t/include-java-applet-in-ruby-on-rails-web-pages/69530/8 "2006-09-22T05:48:22Z")

</div>

On Thu, Sep 21, 2006 at 04:26:58PM -0400, Jason R. wrote:

> So Sun is completely wrong about applet deploying?
> 
> [http://java.sun.com/docs/books/tutorial/deployment/applet/deployindex.html](http://java.sun.com/docs/books/tutorial/deployment/applet/deployindex.html)

Apparently. is the future.

> Man the w3 site is frustrating to navigate. Finally found:
> 
> [Objects, Images, and Applets in HTML documents](http://www.w3.org/TR/html4/struct/objects.html#edef-OBJECT)  
> [Objects, Images, and Applets in HTML documents](http://www.w3.org/TR/html4/struct/objects.html#edef-APPLET)
> 
> So the w3 standard is as says, but that means what? We all know that  
> browsers are not fully W3 standardized, especially IE,

Right. Ironically, in this case, though, you claim that IE is the  
browser where “object” works. Think about it.

> so I’ll ask again:
> 
> Have you tried other tags besides object?
> 
> And maybe try informing instead of berating next time, it’s very unbecoming.

Let’s deconstruct this briefly. Some guy asks about using the   
tag, which is correct. You come in and tell him that he’s wrong to use  
it, that it’s an IEism:

> > On Thu, Sep 21, 2006 at 01:16:19PM -0400, Jason R. wrote:
> > 
> > > Have you tried using the tag? is really meant for IE  
> > > only,

I’m not berating you. Just please be careful as bad advice tends to end  
up in Google.

## Michael

Michael Darrin Chaney  
removed\_email\_address@domain.invalid  
[http://www.michaelchaney.com/](http://www.michaelchaney.com/)

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [September 22, 2006, 4:35pm UTC](https://www.ruby-forum.com/t/include-java-applet-in-ruby-on-rails-web-pages/69530/9 "2006-09-22T16:35:31Z")

</div>

Bad advice? Who’s giving bad advice? Are you trying to say that I’m  
mis-leading the OP? As for in IE, what is there to think about?  
I  
read from Sun’s website that is for IE. Thus I recommend using  
 or . If you actually cared about preventing “bad advice”  
you  
wouldn’t be launching into an egotistical “you’re wrong, I’m right, and  
you  
should know this already” campaign.

As the OP has yet to respond to the topic, why don’t we just wait for  
it, if  
it comes and continue to help when and if needed.

Jason
