I am working on a Java project that I am hosting on GitHub. I wanted to use GitHub Pages to have a page hosted on GitHub with the applet embedded. Now, I'm trying to embed an applet into the page, with the applet files hosted on GitHub on the gh-pages branch. I exported the Java applet as "exploded", so all of the class files show up in their correct hierarchy. In `index.html, I'm using this code:
<section id="main_content">
<script>
var attributes = {codebase: 'cubesorter/me/nrubin29/cubesorter/',
code: 'Viewer.class',
archive: 'cubesorter.jar',
width: '800',
height: '600'};
var parameters = {java_arguments: '-Xmx256m'}; // customize per your needs
var version = '1.5'; // JDK version
deployJava.runApplet(attributes, parameters, version);
</script>
</section>
However, I get a ClassNotFoundException for Viewer.class. Do I have everything set up correctly?
I can't leave comments yet, but I'm wondering if the ClassNotFoundException is referring to one of your classes that you wrote or a class from a dependency. Are you depending on external .jar files? They might be on your development environment but not in deployment. Perhaps you need something like Maven to make sure everything (including all the classes) is being deployed.
You need to move viewer.class into the cubesorter/tree/gh-pages directory.
Simple fix. Not much more to it.
<!-- try the applet tag instead -->
<applet src="cubesorter.jar" code="https://github.com/nrubin29/cubesorter/blob/gh-pages/cubesorter/me/nrubin29/cubesorter/Viewer.class?raw=true">Java not supported</applet>
<!-- <section id="main_content">
<script>
var attributes = {codebase: 'cubesorter/me/nrubin29/cubesorter/',
//How is this even parsed?
code: 'https:\/\/github.com\/nrubin29\/cubesorte\r/blob/gh-pages/\cubesorter\/me\/nrubin29\/cubesorter\/Viewer.class?raw=true',
archive: 'cubesorter.jar',
width: '800',
height: '600'};
var parameters = {java_arguments: '-Xmx256m'}; // customize per your needs
var version = '1.5'; // JDK version
deployJava.runApplet(attributes, parameters, version);
</script>
</section> -->
In the code above, I hotlinked viewer.class for you
Related
problem:
<img src="#{/images/0.jpg}" alt="error occured"/>
I am using Eclipse and folder images is in src/main/resources/static/images and Thymeleaf template which uses:
<img src="#{/images/0.jpg}" alt="error occured"/>
is in folder: src/main/resources/templates
The image is for example: 1.jpg
No, th:src is 'Thymeleaf Standard Dialect'. If your project is properly set up, spring/thymeleaf will be able to find your image on the webserver (e.g. Tomcat) by the given relative path itself. You do not need any own controller.
I hope this will help you: https://stackoverflow.com/a/29475520/9158389
How can I include my java applet class into my web page using JSP on a netbeans web application project.
I don't want it as a jar. When I use a jar it works correctly.
I have a package named "com.example" which is the applet named Scan.java
Also have a web page named main.jsp which I added the code below.
I am using this code to include the class but
<APPLET CODE="Scan.class" WIDTH=150 HEIGHT=250>
On the browser the applet doens't open and it says "ClassNotFoundException"
How to fix that?
The class "Scan" should be on the same directory than your HTML/JSP page, or you could specify the relative path (from the JSP) to reach your Scan.class with the attribute CODEBASE.
<APPLET CODE="Scan.class" CODEBASE="../classes/com/example" WIDTH=150 HEIGHT=250>
I am trying embed a java applet into my webpage. Unfortunately, I can't put my .class file straight into the server so, I was going to read the .class file from a git repository and pointing to it with the archive attribute in my html code.
This is the html code:
<html>
<body>
<applet code="DodgemApplet.class" width="640" height="480" archive="https://github.com/smithg017/repo.git">
</applet>
</body>
</html>
I am still pretty new to html so can someone show me the right way I should be going to get my java applet embedded into my website? Thanks!
Well, there was a hidden property I didn't know about and after much digging I found the property codebase.
I put this:
codebase="https://github.com/smithg017/repo/blob/master/"
right after
code = "DodgemApplet.class"
code is simply the name. by default it will look in the same directory as the html file. In my case, in the Desktop folder. If your class file is elsewhere, reference the folder your class file is in under the codebase property.
How do I go from the Eclipse project to making a file that will run the applet in a browser? From what I understand, I have to make it into a .jar file and then make an html file with the applet tag, like follows:
<html>
<body>
<applet name="TerisApplet.java" code = "TetrisApplet.jar">
</applet>
</body>
</html>
I do this and I run into nothing but trouble. Right now I am receiving a ClassNotFoundException. What am I doing wrong?
If someone can walk me through step by step from getting the Java Applet from Eclipse into an applet running over a browser, that would be awesome. This is for my own learning experience btw and not for school. I'm pretty good with Java I think but fairly new to applets.
1) the code should be
<html>
<body>
<applet code="name.class"
width="500"
height="250"/>
</body>
</html>
2) you must add your .class file to the folder in which your html file is located
for this just search your name.class file and ther would be two files one with a $ sign , copy them both to the folder which contains your .html file
In "name.class","name" means your class name
and you can take width and height as you want this is just an example.
My applet doesn’t see the external libraries. Everything works using the appletviewer, but not using the browser. I’ve put in my “test_applet” folder the jar (TreC-Vis.jar) containing the applet classes, four jar libraries used by TreC-Vis and the html file with the following applet tag:
<applet code="gui.Gui" archive="TreC-Vis.jar,postgresql-8.4-701.jdbc4.jar,postgis_1.5.0.jar,jfreechart-1.0.13.jar,jcommon-1.0.16.jar" width="1024" height="768"> </applet>
Java console gives me a java.io.FileNotFoundException for each of the four jar libraries.
I specify that I exported TreC-Vis.jar from the corresponding Eclipse project, in which I put these libraries in a “lib” folder at the same level of the “src” package.
What’s wrong with the applet tag I wrote?
Reading the tutorial here
http://download.oracle.com/javase/tutorial/deployment/jar/downman.html
I’ve been considering the possibility to put everything, applet and libraries, in one jar as a solution, but I would need some example of the “custom code” mentioned in the Note.
Thanks in advance.
My applet doesn’t see the external libraries. ..They are just native libraries, .. .class files ..
OK. If then, you mean 'natives' as in files of type .dll, .so etc., that is problematic for an applet in that they cannot use the natives unless they are already installed in the appropriate directory of the user system.
Having said that, recent developments allow us to deploy an embedded applet using Java webstart (JWS). JWS makes use of natives easy. Simply put them in the root of a Jar file and add them to a nativelib element in the (XML based) launch file (file type .jnlp).
Even better, JWS can separate the downloads into resources for different operating systems, so Windows gets the .dll natives, while *nix get the .so natives.
JWS offers many more useful features, but the important thing here is that they can make natives available to applets.
Use of native libs in an applet, requires the applet to be trusted.
jar cfm MyApplet.jar MyManifest.txt MyPackage1 MyPackage2 MyPackage3
This was the line I was looking for. This way I've put in my manifest the classpath of the external libraries.
Here is my code and how I have used native libraries in that. It does work in Windowes but it doesn't work in Linux and I receive
access denied("java.lang.RuntimePermission""loadLibrary.hello")
Here is my JNLP:
<?xml version="1.0" encoding="UTF-8"?>
<jnlp spec="1.0+" codebase="" href="">
<resources>
<!-- Application Resources -->
<j2se version="1.7+"
href="http://java.sun.com/products/autodl/j2se"/>
<jar href="applet.jar" main="true" />
<nativelib download="eager" href="libhello.jar"/>
</resources>
<applet-desc
name="Math Applet"
main-class="NativeHelloApplet"
width="10"
height="1">
</applet-desc>
<update check="background"/>
</jnlp>
My Applet:
import java.security.*;
import javax.swing.*;
public class NativeHelloApplet extends JApplet
{
public native String displayHelloWorld();
public native int initPKE (int[] retVal);
public NativeHelloApplet() {
}
public void init()
{
// privileged code goes here, for example:
System.loadLibrary("hello");
getContentPane().add(new JLabel("Test"));
getContentPane().add(new JLabel(displayHelloWorld()));
}
}
My native .c code :
#include <jni.h>
#include "NativeHelloApplet.h"
#include <stdio.h>
JNIEXPORT jstring JNICALL
Java_NativeHelloApplet_displayHelloWorld(JNIEnv *env, jobject obj)
{
return (*env)->NewStringUTF(env,"Hello world!\n");
}
My HTML page:
<Html>
<Head>
<Title>Java Example</Title>
</Head>
<Body>
This is my page<br>
Below you see an applet<br>
<br>
<script language="javascript" type="text/javascript" src="deployJava.js"></script>
<script>
var attributes = {
id: "sswSignApplet",
code: "NativeHelloApplet",
width: 300,
height: 60
};
var parameters = {jnlp_href:"launch.jnlp"}; <!-- Applet Parameters -->
var version = "1.6"; <!-- Required Java Version -->
deployJava.runApplet(attributes, parameters, version);
</script>
</Body>
</Html>
libhello.jar contains the shared object of my native code and is located on the same folder as html and jnlp.
It works in windows when I put hello.jar(containing hello.dll) in resource section but in Linux I received the mentioned error.