Win a copy of Machine Learning for Business: Using Amazon SageMaker and JupyterE this week in the Jython/Python forum
or Object Design Style Guide in the Object-Oriented programming forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
  • Knute Snortum
Sheriffs:
  • Liutauras Vilda
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Joe Ess
  • salvin francis
  • fred rosenberger

Jar file is not generating properly

 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have three java files, SizeRange, SizePrices is getting generated properly, but when i am generating pricelistutil file i am getting below .class only.can anyone please help me on this?

I need to create a jar file with these three files.


{}








[/code]
 
Saloon Keeper
Posts: 11189
244
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What do you mean by generated? What are you generating it from? And how?
 
Rancher
Posts: 4450
47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you compile PriceListUtil, then the following line:

will produce an anonymous class (for the TypeReference).
That anonymous class will be in a class file called PriceListUtil$1.class.

Not sure where you pulled that code for it from?
 
sushobhan bhaumik
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Stephan van Hulst wrote:What do you mean by generated? What are you generating it from? And how?



Hi actually i need to create a jar with this, so while generating class file for priceutil its not giving me full class file.
 
sushobhan bhaumik
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Dave Tolls wrote:If you compile PriceListUtil, then the following line:

will produce an anonymous class (for the TypeReference).
That anonymous class will be in a class file called PriceListUtil$1.class.

Not sure where you pulled that code for it from?



yes correct, typereference is present in jackson-core jar file.
I am using this file to parse my json tree.
but why its not showing other lines in the class file?
 
Stephan van Hulst
Saloon Keeper
Posts: 11189
244
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A class file doesn't contain lines. It's a binary format and contains byte code. So if you managed to get code from it, you did it by decompiling it, which may only yield class headers, depending on the arguments you used.

So, what did you do to get lines of Java code from a .class file?
 
sushobhan bhaumik
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Stephan van Hulst wrote:A class file doesn't contain lines. It's a binary format and contains byte code. So if you managed to get code from it, you did it by decompiling it, which may only yield class headers, depending on the arguments you used.

So, what did you do to get lines of Java code from a .class file?



so to create jar with these files, which approach i should follow?
 
Dave Tolls
Rancher
Posts: 4450
47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Where are you gettig the code for this from:
PriceListUtil$1
?

I can only assume you are decompiling the class file?

If so, why?
 
sushobhan bhaumik
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Dave Tolls wrote:Where are you gettig the code for this from:
PriceListUtil$1
?

I can only assume you are decompiling the class file?

If so, why?



yes i am getting from $file only, actually, my requirement is to add these java files in existing jar file.

so struggling to copy this pricelist class file in that jar.
 
Stephan van Hulst
Saloon Keeper
Posts: 11189
244
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you please give direct answers to these questions?

1) Are you decompiling the .class files?

2) If the answer to question 1 is yes, what command are you using?

3) Do you need to add the .class files to the JAR?

4) Do you need to add the .java files to the JAR?

5) If the answers to questions 1 and 4 are yes, then why are you decompiling the .class files instead of just adding the original .java files?
 
sushobhan bhaumik
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Stephan van Hulst wrote:Can you please give direct answers to these questions?

1) Are you decompiling the .class files?

2) If the answer to question 1 is yes, what command are you using?

3) Do you need to add the .class files to the JAR?

4) Do you need to add the .java files to the JAR?

5) If the answers to questions 1 and 4 are yes, then why are you decompiling the .class files instead of just adding the original .java files?



1. yes
3.yes
4.yes.

but how to add these class or java files into that jar?
 
Stephan van Hulst
Saloon Keeper
Posts: 11189
244
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please answer 2) and 5).
 
sushobhan bhaumik
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Stephan van Hulst wrote:Please answer 2) and 5).



2.using java decompiler
5.to see class file contains proper line of codes or not.
 
Dave Tolls
Rancher
Posts: 4450
47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why do you need to see if they contain the right lines of code?

And what lines of code were you expecting from the class in question, which has no lines of code in it in any case.
 
Stephan van Hulst
Saloon Keeper
Posts: 11189
244
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay well, first of all, you shouldn't have any reason not to trust that the Java compiler doesn't correctly compile .class files from your .java files. Secondly, when you decompile code, you will never get the original code back. And depending on how you used the decompiler (which you still haven't told us yet) you may only get class and method signatures, and not method bodies.

Anyway, decompilation is not needed.

To add sources to a JAR, you would use the jar command line tool and specify the source folder with the -C switch, the same way you specify the compiled code folder with the -C switch. An easier option is, if you're using Maven, to use the Apache Maven Source Plugin. It will add sources to your build artifact for you.
 
sushobhan bhaumik
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Stephan van Hulst wrote:Okay well, first of all, you shouldn't have any reason not to trust that the Java compiler doesn't correctly compile .class files from your .java files. Secondly, when you decompile code, you will never get the original code back. And depending on how you used the decompiler (which you still haven't told us yet) you may only get class and method signatures, and not method bodies.

Anyway, decompilation is not needed.

To add sources to a JAR, you would use the jar command line tool and specify the source folder with the -C switch, the same way you specify the compiled code folder with the -C switch. An easier option is, if you're using Maven, to use the Apache Maven Source Plugin. It will add sources to your build artifact for you.



ok i will, try to generate jar using that and update in the forum after that. thanks for all your help, actually i was little bit worried thats why
 
sushobhan bhaumik
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Stephan van Hulst wrote:Okay well, first of all, you shouldn't have any reason not to trust that the Java compiler doesn't correctly compile .class files from your .java files. Secondly, when you decompile code, you will never get the original code back. And depending on how you used the decompiler (which you still haven't told us yet) you may only get class and method signatures, and not method bodies.

Anyway, decompilation is not needed.

To add sources to a JAR, you would use the jar command line tool and specify the source folder with the -C switch, the same way you specify the compiled code folder with the -C switch. An easier option is, if you're using Maven, to use the Apache Maven Source Plugin. It will add sources to your build artifact for you.




So in the existing jar I can add my files right I. E those three files. Using above mentioned command?
 
Stephan van Hulst
Saloon Keeper
Posts: 11189
244
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can use the jar tool to create a new JAR or to add files to an existing JAR.

Note that a JAR file uses the ZIP compression format, so you can also add files to an existing JAR using any ZIP tool you like.
 
sushobhan bhaumik
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Stephan van Hulst wrote:You can use the jar tool to create a new JAR or to add files to an existing JAR.

Note that a JAR file uses the ZIP compression format, so you can also add files to an existing JAR using any ZIP tool you like.



Hi,

i am using following steps:

1.compiling java files to get .class files
2. opening existing jar using 7zip
3. copying .class files in packages and jackson jar in lib folder.

please let me know my steps are correct or not.

thanks in advance

 
Marshal
Posts: 67464
257
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please explain step 3 more. Your description is not clear, and that step might be wrong.
 
Stephan van Hulst
Saloon Keeper
Posts: 11189
244
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's definitely wrong if you're trying to add other dependencies to your JAR.

Why do you need to modify an existing JAR? Can't you build a new one?

Honestly, it sound to me that you can save yourself a lot of pain if you learn some Maven and use the source and the assembly build plugins.
 
sushobhan bhaumik
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:Please explain step 3 more. Your description is not clear, and that step might be wrong.



I have and existing jar.
in that some class files are there in com.package folder
it has one lib folder
it has one manifesto file


i have created 3 java files.
will convert these class and paste in this jar.
will add dependency jar in lib folder.


 
sushobhan bhaumik
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Stephan van Hulst wrote:It's definitely wrong if you're trying to add other dependencies to your JAR.

Why do you need to modify an existing JAR? Can't you build a new one?

Honestly, it sound to me that you can save yourself a lot of pain if you learn some Maven and use the source and the assembly build plugins.



yeah even i ma thinking to proceed with maven to build a jar, but will it work in jaspersoft server if i place same jar in jaspersoft lib folder?
 
Marshal
Posts: 24950
61
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The answer to the question "Will it work" greatly depends on a large number of details, which of course you haven't posted here because nobody knows what they are going to be. But one of the first caveats is "It depends on whether you have generated the jar file correctly." Which of course also depends on a large number of details which I haven't posted because there's far too many to enumerate.
 
What do you have to say for yourself? Hmmm? Anything? And you call yourself a tiny ad.
Sauce Labs - World's Largest Continuous Testing Cloud for Websites and Mobile Apps
https://coderanch.com/t/722574/Sauce-Labs-World-Largest-Continuous
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!