Win a copy of High Performance Python for Data Analytics this week in the Python 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
  • Paul Clapham
  • Ron McLeod
  • Bear Bibeault
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Jj Roberts
  • Carey Brown
Bartenders:
  • salvin francis
  • Frits Walraven
  • Piet Souris

Building .jar file from a Java project which contains InMemoryJavaCompiler in NetBeans IDE

 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I wrote a Java project in NetBeans IDE. This project contains two abstract Java Classes which are compiled with InMemoryJavaCompiler.
When I run the code in the IDE it works. I produced a .jar file from this project with build packing and clear and build.
When I run the .jar file I receive a NullPointerException error when I use the abstract classes.
Could someone suggest some solution?
Thank you for your help in advance!
 
Saloon Keeper
Posts: 7622
68
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
We would need to see the **complete** exception message, including the stack trace with line numbers. Then we'd also need to see the code that includes the line of your code that the exception blames for the null pointer.
 
Master Rancher
Posts: 4107
37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Does your code require the java command from the JDK where the compiler classes are located?  The compiler classes are not in the JRE.
 
Marshal
Posts: 3355
492
Android Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Norm Radder wrote:Does your code require the java command from the JDK where the compiler classes are located?  The compiler classes are not in the JRE.


The GitHub InMemoryJavaCompiler project page has a note: Please make sure you use JDK in your runtime
 
Beata Szabo-Takacs
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here is the ComPiler.java class where I used InMemoryJavaCompiler:



and here is the part of the code where I called the ComPiler Class:

I receive the following error:
java.lang.NullPointerException
       at org.mdkt.compiler.InMemoryJavaCompiler.compile(InMemoryJavaCompiler.java:19)
       at meteoread.ComPiler.CodeFromString(ComPiler.java:261)
....

The JDK 1.8 is installed on my PC.
 
Norm Radder
Master Rancher
Posts: 4107
37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Did you use the java command from the JDK?

Copy the contents of the command prompt window that shows the command line used to execute the jar file and paste it here.
 
Carey Brown
Saloon Keeper
Posts: 7622
68
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I cut and pasted into this code. Commented out the last 3 lines and stubbed out the static variables to be null. It runs.

 
Carey Brown
Saloon Keeper
Posts: 7622
68
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This code would have been SO much cleaner using the triple-quote feature of Java 14 and 15. Sigh, not official yet.
 
Marshal
Posts: 71752
312
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I thought text blocks were official in Java15.
 
Carey Brown
Saloon Keeper
Posts: 7622
68
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here's what (most) of your code would look like using Java 14/15 text blocks. It it much easier to develop and maintain and makes generating formatted (indented) output easier.
 
Beata Szabo-Takacs
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Finally, I could solve the matter. I checked the code
on Linux OS where the java path was jdk\jre. I changed the path of
the java to jdk\bin by editing the .bash_profile. The code works now.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic