NoClassDefFoundError: ..FRLayout, hosting Applet - java

I have created an applet, which i aim to put online, i have created the HTML code for it and put the class files in the area, and i am running into issues, my applet uses the JUNG library, and i have been putting all the files individually up on to the web-space in the corresponding folders (I cannot put the whole library on the web-space as i do not have enough space)
However after going through many and getting the hang of putting them all in the right location, i am now stuck.
I have located what i believe is the right file ie FRLayout.class from the JUNG library and put it into the directory: edu/uci/jung/algorithms/layout/ however when i do and i try to run the applet i get the corresponding error:
RunTimeException:
java.lang.NoClassDefFoundError: edu/uci/jung/algorithms/layout/FRLayout (wrong name: edu/uci/jung/algorithms/layout3d/FRLayout)
Now this path directory actually does not exist on my webspace? and i have tried putting the file in here just in case that works but it didn't.
i wondered whether i had got the 3d version of the FRLayout, but i have checked the folders and i don't believe it is, i have also re-extracted the Jar file, but to no avail.
Really stuck
Any help would be appreciated.
Thanks
I have tried both the 3d and non-3d versions in the layout folder, however both provide me with the same runtime exception.
Really could use some advice, Thanks

Related

Exporting java body with imagine into jar w/ images

I wrote code that works whenever i run in Eclipse, but whenever i try to export it into a runnable Jar, my images dont show up.
For my images this is the code being used pic1=ImageIO.read(FourCournersRunner.class.getResource("/Images/1.png"));
When exporting the project I've chosen "Package required libraries into generated JAR":
Please also show the code where you display the image in GUI, the problem might lie in there.
Did you also package the Images folder to the .jar file?
The problem might be caused by the way you set up build path too.
In short, I don't think the code you provide right now can reproduce the problem.

Moving downloaded file to project in Eclipse

So from what I understand all classes need to be within a Java project in order to run them. However, when I just downloaded a Java class it automatically opened up in Eclipse outside of a project. Because of this I also cannot simply move it, as Refactor->Move gives the error "the resource is not on a build path of a Java project". So basically because it is not in a project, I cannot move it into a project? Is there a way to overcome this without just copying the class contents into a newly created class?
Edit: also I did not have this problem until a few days ago, when I moved the Eclipse application from a random folder in which it was previously installed, to the program files folder. If anyone could shed a light on why this might have triggered it, and why this predicament was not happening before this would also be appreciated.

IntelliJ IDEA - Decompiling/Editing/Recompiling JAR

I realize this may seem like a completely stupid question and this question is a "wall of text", but I'm feeling like I've gotten way out of my depth here and need some guidance. I've read several SO questions on this topic, but still can't seem to find one that addresses this particular situation. (please reference update(s) at the end of this post)
BACKGROUND
Our company has an application that was built in Java and released as an executable JAR package by a developer who passed away a couple of years ago. Since then, there has been minimal need for even looking at that code, let alone making any changes. That's been really good because I do my programming in VB.NET (Visual Studio) and, while I can read and make sense of Java code, I'm not proficient in actually writing/debugging that code.
However, a recent issue has come up that forced me to try to take a look at this Java code due to some internal changes in organization and data structure. I've looked in his "src\" directory and found older versions of his original code but wasn't able to find the most recent version anywhere. I found some code that made it possible for me to extract the JAR that's currently being used to a local directory on CodeProject (JarsVB), so I've been able to look over some of the .java files when trying to figure out what query is being used for some random operation. I don't know what tool(s) the original developer used to create the project/JAR, so I've installed the IntelliJ IDEA Community Edition 2018 as an IDE, and it's worked for me so far to simply view the code so I can understand a bit about what it's doing.
PROBLEM/GOALS
Unfortunately, now there is a need for me to make a change to the Java code and update the JAR, and this is where I can't seem to make heads or tails of what I need to do. I have my local copy of the code from the "unzipped" JAR containing all the .java and .class files (along with all the other resources), but I'm not sure how to go from that to modifying the code and recompiling the executable JAR.
So, my goals here are as follows:
(properly) Decompile the existing executable JAR. (If the JarsVB solution I mentioned above did what it was supposed to do, I should already have this part handled, but if there's a better, more "integrated" way of doing it, I'd be open to that as well.)
Modify one or more .java files. (I believe I can figure out the syntax well enough to get this part done.)
Debug/test my changes.
Recompile the changes into an updated executable JAR for release. (THIS is where I'm experiencing the most confusion.)
WHAT I'VE DONE
I've been looking at the documentation for IntelliJ to try to figure out how to make this all happen, but I feel like I'm missing stuff. I set my "Project Structure" settings to point to a specific folder, but I can't seem to get it to actually build anything in my specified path.
I went into one of the .java files and made/saved a small change to test, then went to the Build menu and tried all the building options available to me: "Build Project", "Build Module", and "Rebuild Project". Each time, the event log shows that "All files are up-to-date" (even though I changed one), so I go to my output directory to see what it built, but the folder is empty.
I looked at the IntelliJ documentation for Packaging a Module into a JAR File, which says to
On the main menu, choose Build | Build Artifact
But that option is disabled in my Build menu, and when I look in the Project Structure dialog, the Artifacts section is empty, so I try to add a new setting (Add -> JAR -> From modules with dependencies...), but I'm not sure how to properly set that up either.
I tried to select a Main Class from my classes/ directory, but it wouldn't actually accept any of the .class files I selected, so I just left it blank. Then, I did a search for a MANIFEST file, but couldn't find one anywhere so I left that blank as well. The Build menu option is enabled now, but when I tried to Build Artifact, again, I get nothing in my output directory. In fact, the only files I can find that have changed are in my local working directory. I'm just dumbfounded at this point.
FINAL THOUGHTS/QUESTIONS
I've tried to provide as much detail here as I could think of about all the things I've tried and gone through to get this JAR updated, but if there's a question about anything, please let me know. I'm not looking for a "handout" and I don't expect anyone to do this for me, but I'm also not wanting to become a Java developer just for the sake of making some minor changes to an application that will eventually be replaced by a .NET application. I simply am not familiar enough with the tools or Java development in general to know how to get to where I want to be from where I am.
My decompiled source files are in a totally separate directory from the original, production JAR file because, when I recompile this time, I want to completely recreate the JAR. Am I understanding the Java development process correctly in editing one of the .java files I got from decompiling with the JarsVB and then recompiling the JAR?
Thanks in advance for any assistance in finding the resources I need to accomplish these goals.
EDIT/UPDATE
So, looking at the link in the accepted answer in another SO question, How to build jars from IntelliJ properly?, I figured out at least one part of my issue: Leaving the Main Class setting of my Artifacts configuration blank was a problem. Since I hadn't been able to select a .class file and I wasn't sure how to correctly populate that field, I hadn't given the IDE enough information to operate correctly. I entered the namespace and class (namespace.class) I found in the class file that apparently defines the main method for the application, then set the path for the MANIFISET.MF file to my output directory and tried again to Build Artifact.
This time, at least, it DID produce a JAR in my defined output directory, but it's only 1KB in size. As stated above, the source files are in a completely separate directory from the original JAR file from which they were decompiled. The output directory, too, is completely separate from the location of the original JAR file. Do I need a copy of the original JAR file in the output path for recompiling to work correctly?
I'm making progress, but I'm sure I'm overlooking something "stupid" at this point that's primarily due to my unfamiliarity with the IDE and developing Java applications in general.
UPDATE 2
Looking at another SO question - how to create jar of java package in intelliJ idea - I learned that I have to individually add the necessary files for repackaging into the JAR. However, this brings up the question, what files do I add? The linked question identifies the .class files, but when I go look at the .class files in my working directory, none of those have been updated recently, so it looks like I'm still missing a step somewhere.
Another question this brings up is, are there certain conventions for Java development of which I need to be aware when preparing my environment? I have my output path set to a completely separate folder than any working or production code, so I'm wondering if something in that setup might potentially cause issues.
As I said before, I made a small change to one of the .java files, then tried both the Build Module and Rebuild Project options, but those are still telling me that "All files are up-to-date". Even so, I tried adding just the .class files from under my classes\ directory to my Artifact configuration and tried again to Build Artifact. I got a bit larger file (approx. 5MB), but when I try to execute the JAR, it just doesn't appear to do anything, let alone actually launch the application.
I tried again by adding the root folder of my local copy of the source adding everything the root folder contains. (yes, the directory probably needs some "spring cleaning", but that's for another day)
This time, I got a much larger file this time (approx. 21MB), so I thought I might have fixed the problem. Unfortunately, no such luck. The JAR still doesn't appear to execute.
For reference, the original JAR file from which the code was decompiled is approx. 59MB in size so, either IntelliJ is doing an incredible job with compression, or there's yet another step I haven't yet found. I'm sure this is all a matter of getting my IDE configured correctly, but I just can't seem to find the right combination of settings.

My Jar Files Won't Open, and My Motivation to Solve the Issue is Dying

Sorry for the crappy title.
I've been building games in Java since February, teaching myself as I go along. Recently, I worked on a dungeon crawler for over a month using Java FX, and I was quite pleased with the result. I was, in fact, so pleased with the game that I decided to publish it on my Game Jolt account, which I had previously used to produce games I made in Visual Basic.
I went through the process of building a .jar file as an Artifact in Intellij IDEA, and eventually, one was produced. When I tried to run the file however, it started to open but then crashed. I couldn't figure out why even after rummaging through my Console looking for errors to no avail (I'm using a Mac,) and after attempting to open the jar on a PC I found around the house, I concluded it was an error with the app. I soon found that I hadn't signed the jar, causing a security error, so I went through the process of trying to self-sign. When I tried to do that, it worked, but the jar still wouldn't open.
Evidently, there is a underlying issue with my app that needs to be remedied. I have no idea where to start looking, largely because I have tried several times to create new files, including a Hello World application, none of which resulted in a functioning application.
So, here's the entire project.
If any of you would like to have a look through it and point me in the right direction, I would appreciate it, and credit you on my Game Jolt page. This has been giving me headaches for far too long, and I'm about to give up and learn a new bloody language. Please help, it's always appreciated.
Sincerely, a 15-year-old Java-lover who just wants to produce a damn dungeon crawler, fgs.
UPDATE: As per #AndreyAkhmetov's advice, I removed the Class-Path from my manifest file. Unfortunately however, I still don't get anything opening when trying to launch the application. Hope this helps, everyone. Thanks for the feedback so far!
I have made a pull request to fix your game ;).
your problem is how to load resources. You can use maven to organize your project and resources. It helps to make your project platform independent and easy to share.
you should use this structure:
Crawler /
src /
main/
java/
resources/
Images/
pom.xml
The pom.xml is a configuration file and all your resources like Images are in the resources folder. Then you can load it using this:
InputStream loadimg = Main.class
.getClassLoader()
.getResourceAsStream("Images/chest.png");
chest.setImage(new Image(loadimg));
also you should change the directories where you load saved files, from this c\\... to this ./saved.txt. Then the jar can be executed from anywhere.
To create an artifact you can do
$ mvn package
or if you are using Intellij, in the side bar click on Maven then on lifecycle and package.
That will create a target folder with the jar inside, you can execute it by clicking on it or with this command to see the console errors.
java -jar Crawler.jar
Try to split your components from your Main class, it is too large and difficult to read and understand.
Nice game, good luck!

Loading Images from Jar file only works on Development Machine?

I am having trouble loading Images contained within a JAR file. I have read a number of other posts related to this. But cannot find the answer. Now here is where it gets complicated.. This all works fine if I am using a Runnable JAR file exported from Eclipse and Run it using the standard JRE. However This JAR file is actually a plugin for a piece of software called pro/ENGINEER which has it's own JRE that is used to run the JAR file. The strange thing is.. that this works fine on the development machine, that has eclipse installed and so on, but doesn't work on any of the client machines?! But I can't see what is different.
I am trying to load the image using:
ImageIcon icon = new ImageIcon(this.getClass().getResource("resources/Header.png");
This method is called from my 'Start' class, and the Jar is structured as follows:
load
Start.java
load.resources
Header.png
If I Open the Jar file with WinRar you can see the Image definitely exists in the jar, in this position.
I know this may be a very specific question but if anyone can be of any help that would be great.
I did not have the particular problem you're having now, however I ran into the problem of not finding a resource in a JAR file several times in the past.
The solution was to not get the resource from the class, but from the class loader as demonstrated below:
ImageIcon icon = new ImageIcon(this.getClass().getClassLoader().getResource("resources/Header.png"));
Mind the .getClassLoader() call after the getClass().
Hope this helps.

Categories

Resources