Passing from java to HTML - java

I have i problem, I made a program in java using eclipse compilator, the thing is that It has two packages and in each package there are 3 classes i have tried to insert this code in a html file useing the applet tag but the problem is that it doesnt works, i dont know how to do it, and its quite important
I have tried using applet tags and tried the .jar I found something like this
<applet codebase ="." code="zuve.ZuveApplet.class"
archive=".jar,1.jar"
height="1000" width="1000"/>

I recomend you do a short tutorial on Applets:
http://java.about.com/od/webapplications/ss/firstapplet_3.htm
It is quite easy and you may made a misstake at one of those important points:
Compile your source: This includes a.) having your .java files beeing transformed to .class files and b.) packaging everything into a .jar file (you can make a .zip and rename it to .jar by hand).
Link your applet: This is done like described here: http://docs.oracle.com/javase/tutorial/uiswing/components/applet.html. You want to have both of your different packages packed in ONE .jar and have that single jar defined as argument 'archive' while your argument Code has to point to your applet class (e.g. the one extending from either Applet or JApplet or something like that).
Make sure that paths are set properly, easiest way would be to have everything (the .html with the applet tag and the .jar with your applet code inside) inside the same folder.

Related

how to work on a project that solely consists of .class files in eclipse?

it's been a while since i've been working with java and especially with eclipse. My professor sent me a huge folder with many subfolders and subsubfolders, that mainly contain .class java files. Now I'm supposed to work on these files, but i just can't seem to figure out how to get all of them working. I found a few solutions for single class files, but i have a whole folder hirarchy here that i want to work on.
I hope you can help me - I read something about decompiling? How does that work?
Note that I have around 50 different files here that need to be accessible.
Thank you very much!
I suppose the class you are attending is not something like "CS 902 - Reverse Engineering", because if that was the case, you would know what to do with the .class files.
So, one of the following holds true:
Your professor has made a mistake, and instead of sending you the java files, he/she sent you the class files instead.
Your professor sent you the entire project, which contains both .java and .class files, and for some reason you have only managed to find the .class files, while the .java files are there, and you just haven't found them. Unfortunately, the convention in the java world is to store .class files in a subfolder under the project root, so if you copy the project folder, you are copying .class files together with everything else.
Your assignment is to write new code which makes use of classes and interfaces supplied by your professor, but your professor does not want you to have the source code of those files. In this case, you can still work with the .class files, because the public definitions contained therein are parseable by Eclipse and usable in your project, without any reverse engineering. So, what you need to do is to find a way to tell eclipse that these .class files form a "Class Library" which is supposed to be used by your project, and then go ahead and develop new .java files making use of the library. I don't remember how this is done in Eclipse, but you should be able to find it out by yourself, or look it up, or perhaps someone else might post a how-to answer. However, at this point we do not even know whether this is in fact what you need to do.
You can use a java decompiler like JD-GUI, you can find it at http://jd.benow.ca/ . This is a very handy tool to have when you want to view a decompiled version of your jar. There are plugins available for eclipse and intellij as well.

Trouble running an applet made in Eclipse in a browser

I have made a Java applet game in Eclipse which has many classes and media associated with it. I have now been trying to finally test the game in a browser but I am having a hell of a hard time getting it to work.
I have exported a .jar file (a non-runnable, could that be a problem?) and tried many different ways of loading the applet. I have read over the materials on the oracle website as well.
My first two basic questions are:
My applet does not have a static void main(String args[]){ line because I was under the impression that for applets you use a init() and start() method. Could this be the problem?
if not, my class which contains the init and start and the other basic methods is called Start.class and is located in a bin/ directory. Am I able to edit the manifest which is included in the .jar exported from eclipse and but this Start.class as the main class using Main-Class: Game.Start?
Another very basic question also when it comes to directories in java or specifically in .jar archives, are folders in a path names always separated by a .? or do /'s work too?
My project name is simply Game, I have a src folder with .java files and a bin folder with .class how do I direct the manifest to the bin/start.class file?
Sorry this has been rather frustrating especially because I really want to be able to share this applet. Any help would be greatly appreciated.
1) My applet does not have a static void main (args[]){ line because I was under the impression that for applets you use a init() and start() method. Could this be the problem?
No, this is not a problem, as Applets and JApplets do not use main methods to run. Note that some may have main methods that may be used to allow the coder to test the code in a non-applet environment, but when run as an applet, the main methods are ignored.
2) Another very basic question also when it comes to directories in Java or specifically in .jar archives, are folders in a path names always separated by a "."? or do "/"'s work too?
the directeries in jar files use "/". Please check that you are not trying to use resources as Files since jar files do not hold files (but rather resources).
My project name is simply Game, I have a src folder with .java files and a bin folder with .class how do I direct the manifest to the bin/start.class file?
Consider showing the structure of your jar file and also a small test html file where you try to run the applet.
Start.class and is located in a bin/ directory
I agree with Hovercratft about a missing main (not missing), about runnable jar (not necessary).
One problem which might exists is the exact location of files and naming of classes.
If your class name is bin.Start, because you defined a package bin (very uncommon), you need to put the bin directory into the jar.
If you didn't declare a package, you don't have a directory to put into the jar. Maybe eclipse handles this for you automatically.
To test your applet, you need a html file, and start the html file in the appletviewer. If this works, you test it in the browser. Else verify that you can start foreign applets in your browser, to make sure it is installed in the correct way.
Since you show a sloppy habit in the question of cases: Start.class or start.class: This is significant for Java. Use initial uppercase names everywhere.

What does a never ending Java Applet loader signify?

Currently I am trying to embed a Java applet onto a webpage, and the only result I get is the java logo spinning and an empty loading bar.
example
I can't tell if its an error in my Java code or if I did something wrong with the HTML file.
Here is what I have for HTML.
<applet>
archive="game.jar"
code="BRANDON.GameApplet.class"
width=800
height=600
</applet>
BRANDON is the package I created with the rest of my files and GameApplet is the class which has the applet necessary methods. The game.jar is located in the same location as my HTML file, and the GameApplet class file is located in the jar within the BRANDON folder. The applet runs just fine in eclipse when told to run as an applet so I can't imagine it being a problem with the Java code.
My suspension is that it is a problem with file placement but every variation I try comes up with similar results. Anyone know what the mysterious loader means, and what I am doing to cause it?
Thanks to anyone who might answer.
EDIT: Just enabled the developer console and the only output it gives me is:
APPLET tag missing CODE parameter.
I don't know how much this helps.
Enable the Java Console so you can see the error messages and take appropriate action.
edit: You need it inside the applet tag
<apple code="..." ...>
now it is just some text inside the tag.
My suspicion is that your class files are simply not being found, though I don't have enough info to know for sure. Some thoughts:
double-check the file structure inside of game.jar. e.g. GameApplet.class should appear in the BRANDON/GameApplet.class folder relative to the root of your jar file.
check that your folder names and class names are correct
check that when you jar'd your applet, you didn't forget to include class files. I have jar'd all of my source files before, forgetting to compile them before creating the jar

Embedding a java applet in Wordpress

I have an applet that works alright on this page. It just references the .class file. (unfortunately, I have lost the source, and the jar files.)
I want to reference it here, however it does not start. Probably because it cannot find the class file. the applet tag looks like this
<applet code="/applets/language/LanguageEngineApplet.class" width="1174" Height="402">
<embed code="/applets/language/LanguageEngineApplet.class" width="1174" height="402" type="application/x-java-applet" pluginspage="http://www.java.com/en/download/manual.jsp"/>
</applet>
I know the .class file is there, because I can link to it. So I'm stumped as to why this won't work.
I just put the applet in a page on it's own. The problem was not my Java version, it was the class name and the path and the package interacting somehow. I had to put it in a directory on its own, with the html file that referenced it in that directory.
You may want to look at the Java Deployment Toolkit
If you do decide to embed a Java applet inside WordPress and not outside, I just released a new plugin that easily allows you to do that. It uses shortcodes.
http://huyz.us/2011/the-easiest-way-to-embed-java-in-wordpress/
Hmmm, maybe I have to support uploading *.class files in your case. Let me know, if you need that.

Problems importing WAR files in Eclipse?

I was unfortunately forced to result to uploading a WAR file as my backup for a web application I am working on.
Luckily I have the most recent WAR file available. I am using Eclipse IDE and am using the Web Tools plugin for all the J2EE work that I am doing with the Dynamic Web Application Project.
When I imported my WAR file, and ran it on a local server, everything works fine. The problem I a ran into is that in the Java Resources/src folder that all my packages and .java files were now only consists of all the same packages, but they are empty.
I checked to see if I could find the files and I found the .class files in an "Imported files" folder that is not accessible in the Eclipse Project Explorer. I believe that I need to do some type of build or something so that my .java files are available for me, but unfortunately this is one area where I lack.
One thing I would also like to know is, one way or the other, am I able to obtain the .java source code files if I have access to the .class files?
Also, I would like to configure this environment as it was before where my Java Resources:src folder contaiend the packages and .java files.
One thing I would also like to know is, one way or the other, am I able to obtain the .java source code files if I have access to the .class files?
The short answer is No. There is no way to regenerate original source files from bytecode files.
If you were really, really desperate you could try to use a Java bytecode decompiler on your bytecode files, but the result will be be nothing like your original source code.
All comments and javadocs will be gone.
All original code layout will be gone.
Original local variable and parameter names may be gone, depending on your original compiler switches.
Constant expressions may have been pre-evaluated, and loops, string concatenations and other constructs may have been transformed unrecognizably.
Depending on the maturity of the decompiler, the Java code might not be semantically equivalent to the original code, and might not even be compilable.
I hope you haven't spent too long developing this application because the best answer may be to start again.

Categories