Editing java file within jar library - java

I need to replace one word (REPLACE with MODULATE) within the StdDraw3D.java file. I have opened the jar jd-gui and am pretty stuck now. I have been looking for videos or websites and cant quite find a way to do it. Any help would be greatly appreciated. I have not copy paste the code as i don't need help with code just how to edit or replace the original java file.

You have to download the complete source code for StdDraw.jar, update the required java file and rebuild the code again to get the updated jar file. Then use the updated jar in your project.

Steps:-
1. Download the StdDraw.jar
Extract the jar file in folder by right click on it and click on extract.
Copy the StdDraw3D.java file and edit and make required changes then compile it again. Then copy the changed class and java files in the above folder.
Now again create jar file out of that folder.

Related

Importing .java and .class file gone wrong in eclipse

Recently I worked on a project on a mac, using eclipse. When I was done with the project I copied certain .java files and their corresponding .class files onto a USB drive and brought it to my personal computer. When I try to use the import feature on eclipse and import everything, my main method is not recognized by eclipse. It will work if I create a new eclipse "class" by the name I have in the program and copy paste the code. I have many classes so I can not do this for each one. Is there any way for me to change all .java/.class files into files that will be read by the system?
Thanks
An eclipse project contains a lot of meta information. Just open the project directory in a file browser, and have a closer look. There are files like .classpath for example.
When you just copy your source code, you leave all the meta information behind!
You should either copy the complete project directory, or simply use the export task to create a ZIP file of your project. (to later import that in other systems).
There is one other way you can do this. Just create a new project with the SAME EXACT PROJECT NAME that you did at school or wherever. After you create your project, go to your file explorer and navigate to the following place:
<"Directory to work-space">/<"Project Name">/src/
For ex: in Windows, it is Generally:
C:/Users/your_name/workspace/projectName/src
In here, copy all your ".java" files.
Now go to eclipse, right click on your project and hit refresh. You will find all your .java files there. Right-click on your project and hit "Run"->"Run as a Java Project". It should run! hope this helps.
PS: You do not need your class if you are executing it in Eclipse. Eclipse will create its own class files.

cannot paste clipboard contents into selected elements Eclipse

I'm trying to create a simple login form using servlets connected to database. But I got this error:
No JDBC driver found
I had added mysql-connector as external JAR file. After searching for solution on stackoverlow, it was suggested instead of adding it as external JAR file, copy paste it into WEB-INF/LIB folder. But whenever I try that, it gives me error:
Cannot paste clipboard contents into selected elements
How can I resolve this?
EDIT 1: Eclipse not allowing me to drag-drop either
To fix it in that case, extract the file(s) from the archive first(.rar,.tar,.zip), then c-and-paste the file into Eclipse. Works for me under Package Explorer, too.
OR Go for
project->clean
just go through that
Eclipse & JAR Hell
May be that Help you out !!
Instead of copy paste try to drag file and place it in web-inf/lib folder
please Be sure that the file is not from a zip folder.
If it is from zip folder extract it , then copy paste the file.
download winrar-x64 /winrar-x32
install winrar
now unzip ur files
copy paste in eclipse
Best Solution:
Yes i try to start learning JDBC and had to face this issue.
I read the stackoverflow posts but nothing seems to be solving my issue.
Then i did one thing
1.Right click the project
2.Go to properties
3.java Build path
4.libraries
5.Add external Jars
6.Add the jar file
7.hit ok to save
8.Then copy and paste same jar file into the project that you have done before
9.Success!you won't see any error prompt
I am happy now and i hope that you too when you follow this procedure 😊

How do I make a JAR file for my homework assignment?

My instructor asked us to do a homework assignment in Eclipse and save it as a JAR file so he can open it in his own Eclipse... Previously, I've always zipped my .class files and sent them off, so I don't quite know how to do this...
I did find that I can "export" to a jar file, but when I try to open it again I can't figure out how... so I don't know if I exported it properly or if there's just some unknown method he uses to load it into Eclipse afterward.
Yes, "export" to JAR file is the way to go. To check what it contains, please understand that a jar file is in fact a zip file with a different extension, and so you can make a copy of the jar file, change its file extension to .zip then unzip it, and you'll see if it contains what you need.
Edit
I suggest that you use Export to JAR (and not Export to Runnable Jar) since this has the option of exporting the source files as well.
If you do this, you will see:
and you will wish to make the selection Export to JAR as noted in the figure.
Next you will see:
Which is where you choose the files that should be part of the JAR. Make sure to click "Export Java source files and resources" so that your jar file has text readable source. When done, don't click Finish, but instead click Next >.
Then you will see
The Jar Manifest Specification, where you choose which file that holds the main method, that should be run, by entering it into the Main class: text field, or by finding it using the browse button next to the text field.
Then once you've selected the main file, click Finish:
And you're done. Be sure that in the Jar File Specificaion you choose to export the source files.
In Eclipse you can right click on the project and choose "export as jar"
You could also see the documentation.
In Eclipse, right click on your project in Project Explorer. Then go to export and select JAR file. From here you select which files you want to include and a destination for the JAR file. Once complete, you can attach this to an email and send to your Professor.
Hope I could help.

What's the best way of storing and extracting files inside the .jar archive?

I am looking for a way to store files inside the jar (and extract them), but it must work when running/debugging from Eclipse as well.
explanation:
Storing files as in images that I want to use for an icon of a Frame. I hope it's clear now.
I still think that the question is a bit unclear.
What is it that you want to do? You can create and read from jar-files using JarInputStream/JarOutputStream, and you can also read files from jar-files that are on the classpath using Class.getResourceAsStream(String name)
I don not get your question clearly.
Eclipse can export runnable jar files , right click on the project name and choose export. Then from the dialog choose runnable jar file under java category.
Creating JAR file using Eclipse IDE is pretty much easy.
Follow the simple steps.
1. Right click on your project, which you want to create a JAR file.
2. Select Export from the context menu.
Eclipse understands Ant build files. Write a build file that (compiles &) Jar's the code at the same time and this becomes a non-issue.

How to use a code within a .jar file while writing a program in NetBeans

I am trying to use the jAudioPackage in a class project. I need it's functionality of getting the id3 tag info from the header of a MP3 file. I looked at the website and once you have everything set-up it seems pretty easy to use. I am just having trouble with actually importing the .jar file which contains the code. How would I go about this in NetBeans?
To summarize, I have the .jar file I just dont know how to get to use the code within the file.
Right click on your project and go to Properties -> Libraries -> Add JAR/Folder and select the jar file in the following dialog. It should then have access to it when coding/compiling.
You need to add the jar file in your project's libraries. Read http://netbeans.org/kb/docs/java/project-setup.html#projects-classpath.
Please read the documentation for the library as to what the calls are and then call the required methods in order to accomplish what you are doing. Before you do that you will have to import the jar in to your project...

Categories

Resources