• Post Reply Bookmark Topic Watch Topic
  • New Topic

Create jar file from specific .java file inside a main .jar file  RSS feed

 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there,
I have a .jar file which was created by my job mate...the main file is called SLS.jar!
Well, he made a java program which is actually a frame with many buttons. This would be the main program...from this main interface it is launched another frame which is in a separate class, Table.java.
He has many inner classes inside the main program(SLS.jar) and a separate class for table which I'm interested in(Tabla.java)...Tabla.java is the class I want to launch!
Well that table class shows us whether we have some files to work...we receive work files from the official journal and these files are displayed in this JFrame(new class Table.java)...which can be launched from the main interface via one button( Tabla is the name of the button).
Well instead of manually click that button to see if I have files to work...I want to automate the process but there it isn't a .jar file created from the Table.java(Table.java does not have a main method..obviously) so I can't launch it...the only .jar file is SLS.jar where the main function actually is.

I think I have 2 approaches for this:

1) I could access directly Table.java( I already decompiled Main.jar and got to Table.java but it is related to other classes) then make my own class and create a .jar file from it and then access the jar(the table) directly.
2) I could modify Main class(SLS.class) and add a timer so the button gets clicked automatically(maybe with Thread.sleep)

What do you think would be the best approach and how can I implement it? Thanks in advance!

It happens often to me that I can't focus on some other things(like google-ing, youtube) on my free time(at work...when I don't have files) and I have to click on that button in order to see whether I have files to work or not...
If I can just click automatically that button from the main interface from minute to minute, let's say that would be great!
Until now I created this simple program that opens the SLS.jar repeatedly( I need to close it manually so I can avoid having 1000 instances of SLS.jar...)



Well, I started learning java...but more object concepts...
I kinda skipped over all those incipient phases like: making classes public, put them into a package, create .jar files from the classes...etc!
Anyhow, I have access to all the classes from the SLS.jar but when I open them in IntellIJ IDEA it shows me with a green circle(like an error)...this happens when I'm trying to open .java file directly from the files I extracted...well first I extracted sls.jar using winrar then I used the jad tool to obtain java classes...files I can open in INTELLIJ IDEA but could not run...and I don't know why!!
Thanks in advance for any help!
 
Saloon Keeper
Posts: 7993
143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Alin,

You can create a new project which has a dependency on the SLS.jar. You can then write a class that interacts with the Table class directly.
 
Alin Andrei
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Stephan van Hulst wrote:Hi Alin,

You can create a new project which has a dependency on the SLS.jar. You can then write a class that interacts with the Table class directly.


In theory it seems awesome but I've never did this before...
As I've read on the internet...this thing implies using Maven and maybe you could get me more details around it...thanks anyway
 
Ranch Foreman
Posts: 3072
37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What are you using to write your code?
Is it an IDE or are you using something like Notepad and compiling from the command line?
 
Stephan van Hulst
Saloon Keeper
Posts: 7993
143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No you don't need Maven. You can do this by putting the SLS.jar on your classpath when you compile and when you run the application. If you're working with an IDE, the IDE can do this for you automatically.

Using the command line, and assuming your source is in MyApplication/src and your dependencies are in MyApplication/lib it would look something like this:

javac -sourcepath src -classpath lib/SLS.jar;lib/AnotherDependency.jar;lib/etc.jar -d bin src/com/example/Main.java
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!