1

I am using Java8. I have one .jar file containing .class files.

I downloaded the source code of the same .jar file. And I edited one of the file in it. It is .java file.

Now I want to compile all these .java files in the source code and create a new .jar file with .class files

Any clues?

5
  • have you used IDE, if its eclipse you can be able to create jar from IDE it self, no hard stuff from command you need to do @Soniya Commented Apr 5, 2018 at 13:18
  • I am using eclipse Commented Apr 5, 2018 at 13:30
  • Right click on project -> Export -> Java -> Jar file Commented Apr 5, 2018 at 13:32
  • Mine is a gradle project The dependency is compile group: 'org.drools', name: 'drools-compiler', version: '7.0.0.Final' I just want edit 1 file in one of the jars Commented Apr 5, 2018 at 13:59
  • I think already done with modification, and you just want to make a build of that. Now i getting confuse what exactly you looking for, please elaborate a bit @Soniya Commented Apr 5, 2018 at 17:29

3 Answers 3

1

There are many options 1. if you want to do it from command prompt then you would need to set the classpath and then either create a list of java files with package name and use it for compiling, something like this

# Linux
$ find -name "*.java" > source.txt
$ javac  -classpath "${CLASSPATH}" @source.txt

:: Windows
> dir /s /B *.java > source.txt
> javac  -classpath %{CLASSPATH}% @source.txt

or use build tool like Ant. Once you have the .class files, you can use "jar" command to create a jar of the .class files 2. Use IDE - you can use any of these IDEs - eclipe, intellij, netbeans. You need to setup a project with the java files and compile project and export as jar using class files. I think it would work out better for you to use an IDE.

Sign up to request clarification or add additional context in comments.

Comments

0

1) Compile the classes (javac command)

If you don't have any jar dependencies required at compile time, you should not need to set the classpath. Otherwise you should specify the cp argument with.
Example (Unix way) :

javac -cp "myLib.jar:myOtherLib.jar" *.java   

2) Then create a jar from these compiled class (jar command)

Example :

jar cf myjar myFolderWithCompiledClass

Comments

0

extract your jar to a folder and run this: javac [folder]/*.java

read that for more info: https://docs.oracle.com/javase/7/docs/technotes/tools/windows/javac.html

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.