I'm going to be honest and say that I have never deployed an applet, but it seems to be incredibly painful. The <applet code> doesn't work on chrome so im using the jnlp to hopefully get past this nightmare, but it only seems to add to my migrane. Everything runs fine in eclipse, but when it comes to deployment.. I might be needing a new computer if I can't figure this out haha.
Started out creating the java jar (jar cvf WebGame.jar bin):
Then I created the JNLP file that looks like this (named bounce.jnlp):
I thought I was starting to get somewhere when I created my html file (Bounce.html):
So I decided to upload everything to test out how it works on chrome:
It looked like my game was loading on the browser but I ended up getting this:
So after messing around with it for a couple of hours I'm all like this:
If anyone could help me out I would DEFINITELY appreciate it, (I can't really afford to buy a new computer at the moment).
I suspect that your StartingPoint class is not actually in the bin package, this is the hint for me:
java.lang.NoClassDefFoundException: bin/StartingPoint (wrong name StartingPoint)
This would indicate that your class is in the default package (i.e. has no package declaration at the beginning).
Try changing your JNLP to
main-class="StartingPoint"
and create your jar file from within the bin directory:
$ cd Documents/Java/TheBasics/WebGame/bin
$ jar cvf ../WebGame.jar *
Related
I'm new to using jar files on my applications so here is my problem.
I wrote my code on net beans and added into the library the jar file I need, which is:
poi-3.10-FINAL. The program runs perfectly from net-beans, however when i try to run it from the command line seems like it doesn't find some of the files inside the jar. Reason for this I would like to make it an executable after i get this solved.
In the command line I'm compiling my code as follows:
C:\Users\chuser10\Desktop\Excel\src\excel>javac *.java -cp C:\Users\chuser10\Des
ktop\Excel\src\excel\lib\poi-3.10-FINAL.jar
It compiles perfectly, which lead me to think everything is good to go, however this is not so. I tried then running my main as ...>java GUI and i got this:
C:\Users\chuser10\Desktop\Excel\src\excel>java GUI
Exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError: org/apach
e/poi/poifs/filesystem/POIFSFileSystem
I checked inside the jar and the file is there. Any clue why this might be?
You need to specify the classpath when you run the program too. Compiling doesn't link the library into your code as happens in C and many other languages; in Java linking happens at runtime.
Probably -cp .;C:\Users\chuser10\Desktop\Excel\src\excel\lib\poi-3.10-FINAL.jar will be what you need. The '.' at the beginning means the current directory, which is where the class files that constitute your program are rooted. The ';' is just a separator.
Got it working. You are both correct, we have to specify the class-path at runtime as well.
I went ahead and went for the executable jar file creation and put it on my manifest:
..>jar cfm < *.class>
On my manifest:
Class-Path: poi-3.10-FINAL.jar
Main-class: GUI
Cheers!
Ok, I'm stumped here. I'm using Matlab version 2013b with a Java RTE of 1.7.0_11 and I'm trying to run a simple piece of code to see if Matlab is able to read the .jar file and nothing seems to be working.
Here is the Java code, which is compiled to a .jar named JavaOCT.jar, which is placed in the Matlab working directory:
package VTK;
public class vtkVolumeView{
public int Test(){
return 10;
}
}
That is it, no other dependencies, nothing fancy. In Matlab, I try:
javaaddpath('\JavaOCT.jar'); %<-Directory and name are 100% correct
import VTK.*; %<-Package name from above
methodsview VTK.vtkVolumeView; %<-Can't find the class, argh!
Matlab kicks back that it can't find the class.
Things I've done to try and solve the problem:
Reverted to the exact same JDK as the Matlab RTE
Tried an older 1.6 JDK
Done lots of stack overflow research to try and solve it 1 2 3 4
Tried used javaclasspath and pointing to the compiled class instead
Read the Matlab documentation 5
Using clear -java after the javaaddpath
Any help would be appreciated, it is driving me nuts!
Update: Daniel R suggested just javaaddpath('JavaOCT.jar') which doesn't work either.
Final update: It finally works! I wasn't building the .jar properly. In IntelliJ, click on the project and hit F4. This brings up the Project Structure, then go to Artifacts and click the green + button and add DirectoryContent and then point to the out\production. Once this is done, as mentioned by others, it should show up in Matlab as an expandable .jar.
I don't know which operating system you are using, but the ./ seems invalid.
Try javaaddpath('JavaOCT.jar'); or javaaddpath(fullfile(pwd,'JavaOCT.jar'));.
What does exist(fullfile(pwd,'JavaOCT.jar')) return?
Some things to try:
Add the class file. When using a package, you need to add the class file in at the host of the package. For example, if your code is here:
\\full\path\to\code\VTK\vtkVolumeView.class
Then use:
javaaddpath('\\full\path\to\code')
I'm still suspicious of your *.jar path. You should usually use absolute paths when adding jar files. Try adding the results of which('JavaOCT.jar')
How did you make your jar file? Does it contain the appropriate directory structure implied by your package declaration?
I have been searching the web trying to find the answer to my question, but everywhere I look seems to have too complex of a solution for a beginner like me. I have been working on this project, and just now realized that I should've made a package, or something like that. The thing is though, my program was working fine until I started dabbling with it, and now it won't work at all. I am getting this error:
Exception in thread "main" java.lang.NoClassDefFoundError: BubbleSort. class
Caused by: java.lang.ClassNotFoundException: BubbleSort.class
at java.net.URLClassLoader.findClass(URLClassLoader.java:434)
at java.lang.ClassLoader.loadClass(ClassLoader.java:672)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:358)
at ``java.lang.ClassLoader.loadClass(ClassLoader.java:638)
Could not find the main class: BubbleSort.class. Program will exit.
Here's how my "path" looks, if I am not mistaken. I am connected to my school's Z: drive through a remote connection, and from there I have a folder called myFirstname_Lastname_A4,
which then leads me to another folder called sortingzz which I believe is supposed to have only my source files, but it also ended up with my class files in there whenever I compiled. So here's what I am doing to compile.
cd myFirstname_Lastname_A4/sortingzz
javac *.java (Works fine, this is where I end up with my Class files inside of my sortingzz folder)
java * (This is where I get the error)
I am pretty sure I am just trying to run the program wrong. Before I started messing around with stuff I wasn't ready for, I used to just run the file with my main function in it, like this
javac SortingImplementation.java
java SortingImplementation
And that for the most part worked fine, but I started having trouble calling certain classes from other classes, so thats when I found out I was suppose to do the packaging and importing stuff.
In case that is the issue, I have on the top line of every source file:
package sortingzz;
and I am importing like this:
import sortingzz.*;
This is correct, right?
UPDATE:
I decided to give up on class pathing and trying to package everything, because as usual, I am getting responses that are way over my head, and to be honest I don't think it is necessary.
After removing package and importing from everything, and once again compiling using javac *., it actually compiles this time. However whenever I try to run my class with the main in it, SortingImplementation, it tells me that
Could not find the main class: SortingImplementation. Program will exit.
I don't get it, I am looking at the SortingImplementation.class right now, with all the other classes and java files, so I am not sure what it's trying to do.
javac *.java is fine. This will compile your files. However, you only need to run the file with your main method in it: java MainClass
You say that you are using packages to organize the classes. In this case you need to set the class path using the -cp flag.
javac -cp /path/to/parent/of/package classname.java
and
java classname
Also, your main class should be declared public and should have a main()
NoClassDefFoundError occures when a class was recognised in compile time but was not available during runtime.
So the JVM can't find your class in the classpath.
using -cp flag to specify where your package is should work.
the commanc javac *.java compiles all found java files to corresponding .class files. If you all your classfiles are in the same folder, which they should, you just run your regular java SortingImplementation command.
java * would, a bit depending on your OS, yield in an undesired command. For instance, on Linux it would be expanded by the OS to java SortingImplementation.java SortingImplementation.class BubbleSort. The last one is a directory, which ofcourse is not an executable class.
I usually don't have any problems setting up the classpath and running programs, but I'm running into a bit of a problem. I'm working on a program that will download a series of reports. If the working directory is called Report downloader, my project resides in
src/org/report/reportdownloader
and the jar files I'm working with reside in
lib/
When I'm going to compile my project (I'm in windows :( ) I type in
javac -classpath .;..\..\..\..\..\lib.transfer.jar; ..\..\..\..\..\lib.someotherjar.jar; ReportGrabber.java ReportDriver.java
I get an error message saying
ReportDriver.java:12: error:package com.transfer does not exist
import com.transfer.*;
^
1 error
And I don't really understand why. I'm trying to import a valid package, and I showed it where to find the jar in the classpath and it's still giving me grief.
I'm losing my mind, I feel so dumb for asking about this. I could give up and just use eclipse but I really want to figure this out.
EDIT: When I type
java -cp .;..\..\..\..\lib\transfer.jar; ..\..\..\..\lib\someotherjar.jar; ReportDriver
to run the file, I get an error saying
Error: could not find or load main class ..\..\..\..\lib\someotherjar.jar;
Any ideas?
Why are there 5 .. instead of 4?
to access your lib directory from reportdownloader, you have to do
..\..\..\..\lib
not
..\..\..\..\..\lib
Using a relative path seems like a bad idea to me.
Why not do this:
... -classpath /lib/transfer.jar /lib/someother.jar
or in windows:
... -classpath c:\lib\transfer.jar c:\lib\someother.jar
I know this question is not new but I am posting this after going through enough googling around.
I have a jar file which I don't control. I mean I have not written the Java class in there and all I know is that there is a class named "hist" in it which takes two arrays and gives out the output. Now I have to use PHP to call this class "hist" in the jar file named "histvol.jar". I have installed the PHP/Java Bridge and it is installed correctly.
But I don't understand how to call this jar file in PHP and where to place this jar file.
This is what I did:
Installed tomcat and php-javabridge
Placed the jarfile "histvol.jar" under Tomcat/webapps/JavaBridgeTemplate621/webinf/lib/
Went to xampp/htdocs and created a file named testjava.php
<?php
require_once("http://localhost:8080/JavaBridgeTemplate621/java/Java.inc");
$System = java("java.lang.System");
$myclass=java("histvol");
echo $System->getProperties();
?>
Class not found exception is expected because I am not calling it anywhere in PHP, but how do I call it?
I am lost, please help (I don't know a word of Java).
Ok I got it finally, I just had to do this:-
$myclass=new java("histvolone.histvol");
instead of
$myclass=new java("histvol");
It worked !