Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Alternatives for running Java headless? Making Excel files on Unix with Apache POI causes errors

 
George Impagliazo
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Admins: I wasn't sure which subforum to put this in, please feel free to move it, thanks.

I'm using Apache POI, WebLogic 11G, Java 1.6 and Spring 3.1 MVC to send data wrapped in Excel ( *.xlsx ) back to a browser screen.

Everything works on my computer using the above software and Windows 7 professional.

On the server ( Unix SunOS 5.10, weblogic 11g, Java 1. 6, Spring MVC
3.1 ), I am getting a "500 Internal Server Error"


According to my logs, retrieval of the data is completely successful.
Things are dying when it comes to wrapping the data in Excel, when
operating on SunOS 5.10. I found these messages in my log:



ManagersAndAlternates:getManagersInAACMEOrg(): records.size() == 38
[ACME]: [DEBUG] - 2013-Sep-24 10:12:44 - PhoneListView:createFirstSheet(): Completed database call to get SubAcmeOrg1 all federal mangers
<Sep 24, 2013 10:12:47 AM EDT> <Error> <HTTP> <BEA-101017> <[ServletContext@30304209[app:acme module:acme.war path:/acme spec-version:2.5]] Root cause of ServletException.
java.lang.NoClassDefFoundError: Could not initialize class sun.awt.X11GraphicsEnvironment
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:169)
at java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment(GraphicsEnvironment.java:68)
at sun.font.FontManager.initSGEnv(FontManager.java:1307)
at sun.font.FontManager.findFont2D(FontManager.java:1984)
Truncated. see log file for complete stacktrace


And ...



ManagersAndAlternates:getManagersInAACMEOrg(): records.size() == 38
[ACME]: [DEBUG] - 2013-Sep-24 10:12:44 - PhoneListView:createFirstSheet(): Completed database call to get SubAcmeOrg1 all federal mangers
<Sep 24, 2013 10:12:47 AM EDT> <Error> <HTTP> <BEA-101017> <[ServletContext@30304209[app:acme module:acme.war path:/acme spec-version:2.5]] Root cause of ServletException.
java.lang.NoClassDefFoundError: Could not initialize class sun.awt.X11GraphicsEnvironment
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:169)
at java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment(GraphicsEnvironment.java:68)
at sun.font.FontManager.initSGEnv(FontManager.java:1307)
at sun.font.FontManager.findFont2D(FontManager.java:1984)
Truncated. see log file for complete stacktrace



I Googled on those exceptions and found a number of posts about people
trying to run Java GUI applications on Unix servers. The bottom line was
that many such servers are "headless", as such X11/Graphics libraries
which Java looks for aren't there and that leads to the errors.

The most advised solution is to use this JVM setting in any script that
starts WebLogic 11g:

-Djava.awt.headless=true

It tells Java not to look for those libraries.

My problem is that my networking department isn't very flexible. I was
wondering if there was a way, in the WebLogic 11g Admin interface, to set
that JVM option and ONLY set it for my webapp (ACME) that has the feature
that tries to download data in Excel.
 
Paul Clapham
Sheriff
Posts: 21107
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
George Impagliazo wrote:
The most advised solution is to use this JVM setting in any script that
starts WebLogic 11g:

-Djava.awt.headless=true

It tells Java not to look for those libraries.

My problem is that my networking department isn't very flexible. I was
wondering if there was a way, in the WebLogic 11g Admin interface, to set
that JVM option and ONLY set it for my webapp (ACME) that has the feature
that tries to download data in Excel.


No. As you say, it's a JVM setting (known as "System property" in Java) and so it applies to the entire JVM, which in your case would be the entire WebLogic server. Personally I don't see any harm in setting that property for all the other web apps in the server, because I don't think it can do them any harm, but I'm guessing that your networking department isn't going to be convinced by "Some guy on the Internet thinks it should be okay if we do this".
 
George Impagliazo
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I ended up adding this to my code and it worked


 
Paul Clapham
Sheriff
Posts: 21107
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Excellent! (That property still applies to the entire JVM, so now you're testing my theory that it won't make any difference to anything else. Good luck!)
 
George Impagliazo
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Clapham wrote:Excellent! (That property still applies to the entire JVM, so now you're testing my theory that it won't make any difference to anything else. Good luck!)


The webapp runs on web logic, which has a sub module called "servers". The other webapps on mine are either not in use or also had to make adaptations because the physical servers are indeed headless.

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic