Nick's Tech Blog: java

Pages

Showing posts with label java. Show all posts
Showing posts with label java. Show all posts

Tuesday, December 24, 2013

Installing Tomcat8 as a service on Window7

Install it!

  1. Download Tomcat8 zip for your operating system. -> http://tomcat.apache.org/download-80.cgi (I grabbed the Windows 64bit version)
  2. Unzip it to the directory where you want it to live.

Check your Config

  1. Check your config by running <tomcat_home>\bin\configtest.bat

Error1: JVM & JDK had a space in the name.
Fix1: Fixed by setting JAVA_HOME and JRE_HOME Environment Variables to use C:\Progra~1\Java\<java_version>

Error2: JVM was 32bit, needed to be 64bit
Fix2: Changed JAVA_HOME and JRE_HOME to use correct 64bit Java install. 

Install Tomcat8 as a service

  1. Run: <tomcat_home>\bin\service.bat install
When starting, it failed with "Error Code 4".
I had a look in the Windows System Logs, and found this: "The Tomcat8 service terminated with service-specific error The system cannot open the file."

Enable logging:

  1. Run <tomcat_home>\bin\tomcat8w.exe (a window will open)
  2. Under the "Logging" tab, set the logging directory
  3. Set the STDOUT and STDERR files
  4. Set the logging to DEBUG (turn this back to INFO when app starts up successfully).
  5. Attempt to start the app again, and check the logs:

Error3: stderr.log
2013-12-24 13:18:43 Commons Daemon procrun stderr initialized
java.lang.NoClassDefFoundError: org/apache/catalina/startup/Bootstrap
Caused by: java.lang.ClassNotFoundException: org.apache.catalina.startup.Bootstrap
Fix3: Using tomcat8w.exe
  1. Run <tomcat_home>\bin\tomcat8w.exe (a window will open)
  2. Under the "Java" tab, set the classpath (which was empty) to the following:
C:\devtools\apache-tomcat-8.0.0-RC5\lib\*;C:\devtools\apache-tomcat-8.0.0-RC5\bin\*;

After that, I was able to start up Tomcat8 successfully -> http://localhost:8080/

After installing some apps, I got:
Error4: java.lang.OutOfMemoryError: PermGen space
Fix4: 
  1. Run <tomcat_home>\bin\tomcat8w.exe (a window will open)
  2. Under the "Java" tab, I changed the "Java Options" to:
-Dcatalina.base=C:\devtools\apache-tomcat-8.0.0-RC5
-Dcatalina.home=C:\devtools\apache-tomcat-8.0.0-RC5
-Djava.endorsed.dirs=C:\devtools\apache-tomcat-8.0.0-RC5\endorsed
-Djava.io.tmpdir=C:\devtools\apache-tomcat-8.0.0-RC5\temp
-Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager
-Djava.util.logging.config.file=C:\devtools\apache-tomcat-8.0.0-RC5\conf\logging.properties
-Xms256M
-Xmx1024M
-XX:MaxPermSize=1024M
-XX:MaxHeapSize=256M
-XX:PermSize=256M
-XX:+CMSClassUnloadingEnabled
-XX:+CMSPermGenSweepingEnabled

Everthing's now working smoothly!

Additional Notes:

1) I had to add <tomcat_home>/bin/tomcat7.exe and <tomcat_home>/bin/tomcat7w.exe to Windows Firewall.

2) When uploading a new application, I got the following error:
java.lang.IllegalStateException: org.apache.tomcat.util.http.fileupload.FileUploadBase$SizeLimitExceededException: the request was rejected because its size (53706238) exceeds the configured maximum (52428800)
Simply modify the following section in <tomcat_home>/webapps/manager/WEB-INF/web.xml
    <multipart-config>
      <!-- 50MB max -->
      <max-file-size>52428800</max-file-size>
      <max-request-size>52428800</max-request-size>
      <file-size-threshold>0</file-size-threshold>
    </multipart-config>

I doubled the values from 52428800 to 104857600.

Monday, September 26, 2011

Fedora > libfontconfig.so.1: cannot open shared object file: No such file or directory

Problem

Received the following exceptions (seperately) when attempting to run a java program on Fedora 15 amd64.

/lib/ld-linux.so.2: bad ELF interpreter: No such file or directory
...
libstdc++.so.5: cannot open shared object file: No such file or directory
...
Exception in thread "main" java.lang.UnsatisfiedLinkError: /some/directory/libmawt.so: libXext.so.6: cannot open shared object file: No such file or directory
...
libfontconfig.so.1: cannot open shared object file: No such file or directory


and so on.

Solution

Obviously a couple of dependencies were missing. To find out which package/s you need to install to fix a missing dependency, use "yum provides <missing_file>".
e.g.
# yum provides libfontconfig.so.1
fedora/metalink |  21 kB     00:00    
jenkins |  951 B     00:00    
updates/metalink |  12 kB     00:00    
fontconfig-2.8.0-3.fc15.i686 : Font configuration and customization library
Repo        : fedora
Matched from:
Other       : libfontconfig.so.1

Then install the packages...
e.g.
# yum install fontconfig

Repeat for all missing files.

Thursday, September 22, 2011

Fedora > java.lang.NoClassDefFoundError: Could not initialize class sun.awt.X11GraphicsEnvironment

Problem 

The following exception was encountered when running a java program on Fedora:
java.lang.NoClassDefFoundError: Could not initialize class sun.awt.X11GraphicsEnvironment

Assumptions: you know what an xserver is.

Solution

Basically, the java program is trying to access the xserver, and can't.

If it should be accessing the xserver, make sure the xserver is started/running:
  • e.g. ps -ef | grep Xvfb
If it shouldn't be accessing an xserver, make sure the "DISPLAY" environment variable is unset:
  • unset DISPLAY

See also:
Fedora > install Xvfb as a service

Wednesday, September 14, 2011

Install Java Plugin on Ubuntu Firefox

Current as of: 14 Sept, 2011

Versions
Ubuntu 'Natty' 11.04
Firefox 6.0.2
Sun Java6 Plugin

Add the 'universe' software source
  1. Open the "Ubuntu Software Center"
  2. In the menu, navigate to Edit > Software Sources...
  3. (Enter administrator password)
  4. Other Software > Add
  5. Enter "deb http://archive.canonical.com/ubuntu natty universe" in the apt line
  6. Click "Add Source"
  7. Check that "Canonical Partners universe" entry has been added.
  8. Click "Close"

Install the java6 plugin
Back in the "Ubuntu Software Center" window...
  1. Navigate to "Get Software" and search for "sun-java6-plugin"
  2. It should now return an entry for "sun-java6-plugin"
  3. Click "Install"

It's that simple. Once complete, you should now be able to start/restart firefox and the java plugin will be installed.

You can optionally check, that the following symbolic link has been created.
/usr/lib/mozilla/plugins/libjavaplugin.so -> /etc/alternatives/mozilla-javaplugin.so