Compile a folder with java classes into a JAR - jar

I had a jar file paymentService.jar which had a lot of class files. I have decompiled a class file, made some changes to it's code and created a .java file. I have kept the .java file in the same location as .class file.
How can I recompile the .java file and then recreate a JAR of the folder.
I can't compile the .java file using javac /my/../example.java because imports will fail.

Related

java.lang.NoClassDefFoundError with external library

I have created a custom jar file and tried to access the function in the java file from Flow in corda 3.3 version. I have added the jar file using Project Structure>Project Settings>Libraries>Java>. While running the code its not identifying the class path of added jar file and throwing java.lang.NoClassDefFoundError
Modified the build.gradle file and added flatDir {
dirs 'libs'
} where the jar file is residing

How to update a JAR file with a modfied Java file

I have one JAR named as abc.jar with 15 class files. In JAR file I need to modify xyz.class, so I decompiled to xyz.java and modified it.
How can I update that JAR with the modified Java file? While trying to create (compile) the JAR file I am getting errors.
You can add your newly compiled class to the jar and overwrite the old one, here is how to add xyz.class and xyz.java to the jar :
jar uf abc.jar xyz.class xyz.java
See here for more about updating a jar file.
Or simply you can use any archiving tool, like winrar to open and add files to the jar.
Compile the xyz.java and replace the xyz.class file directly in jar without building the jar again, if the single class has been modified.

Can .java file be saved as .class file without compilation?

I am having a jar file from my project. I need to make certain modifications in a particular class. So , I extracted the particular class file , decompiled it and converted it to .java file. I made my changes by editing the .java file through notepad++ and then I saved the file as .class file and added it back to the jar. will it work?
It won't work.
You must have to compile this & add .class file. To compile it successfully you have to add all dependencies.

how to compile a java file which is in a jar and then re-create the jar

I have a jar file (Gestp.jar) . And I have some .Java files (which are web applications) within the jar file
I need to modify a particular .Java file . And then re-create the Jar file and deploy it in a server.
I have extracted the jar file , and did the modification to the .Java file. But unable to create the .class file with the changes , in eclipse as it is a web application.
Please help.
Thanks in advance,
Aditya.T

How do you include .java files and .html files in a .jar file when you take Clean and Build in Netbeans 7?

If you have files in the build/classes/folderToJar Netbeans7 takes the .class files and make a .jar file when you take Clean and Build.
But how can you have .java files and .html files go into the .jarfile as well?
First Create a package(Say html) under Source Packages
copy all of your html files to this package(when you create a package,a folder in the name of your package will be created inside your project src folder, so copy files to it)
You can access your html file from your program as
URL someURL = yourclass.class.getResource("/html/yourhtml.html");

Resources