Embed Java Applet on GitHub Page

我们两清 提交于 2019-12-24 12:44:20

问题


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?


回答1:


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.




回答2:


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



来源:https://stackoverflow.com/questions/23281598/embed-java-applet-on-github-page

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!