java

Tomcat configuration

wget https://raw.githubusercontent.com/panticz/installit/master/install.tomcat.sh -O - | bash -

#!/bin/bash

# ensure that this script is run by root
if [ $(id -u) -ne 0 ]; then
  sudo $0
  exit
fi

# install Java JDK
wget -q https://raw.githubusercontent.com/panticz/installit/master/install.java-jdk.sh -O - | bash -

# install tomcat
apt-get install -y tomcat7

# configure JAVA_HOME
echo "JAVA_HOME=/usr/lib/jvm/$(ls /usr/lib/jvm | grep oracle | tail -1)" >> /etc/default/tomcat?

# install authbind
apt-get install -y authbind

# create /etc/authbind/byport/80
touch /etc/authbind/byport/80
chmod 500 /etc/authbind/byport/80
chown tomcat7:tomcat7 /etc/authbind/byport/80

# configure tomcat to port 80
sed -i 's|port="8080"|port="80"|g' /etc/tomcat?/server.xml

# bind to a privileged port
sed -i 's|#AUTHBIND=no|AUTHBIND=yes|g' /etc/default/tomcat?

# restart tomcat
/etc/init.d/tomcat7 restart

# start
export JAVA_HOME=/usr/lib/jvm/jdk1.6.0
export JAVA_OPTS="$JAVA_OPTS -Xmx256m"
/usr/local/apache-tomcat-5.5.20/bin/startup.sh

# deploy
/opt/SDK2/bin/asadmin deploy /tmp/Intranet.war

# change default port from 8080 to 80

# log directory
/var/log/tomcat6

# redirect by default to a app
mv /var/lib/tomcat6/webapps/ROOT/index.html /var/lib/tomcat6/webapps/ROOT/index.old.html
cat < /var/lib/tomcat6/webapps/ROOT/index.html

EOF

# manager
http://YOUR_TOMCAT_IP/manager/html/

# apache module
mod_jk

# LINKS
http://wiki.ubuntuusers.de/Tomcat
http://linux-sxs.org/internet_serving/c581.html
http://shrubbery.mynetgear.net/c/display/W/Disable+Directory+Listing+in+Tomcat
http://wiki.ubuntuusers.de/Tomcat

Install Sun / Oracle Java JDK under Ubuntu

wget -q https://raw.githubusercontent.com/panticz/installit/master/install.java-jdk.sh -O - | bash -

#!/bin/bash

# ensure that this script is run by root
if [ $(id -u) -ne 0 ]; then
  sudo $0
  exit
fi

# install debconf
apt-get install -y debconf-utils

# create answer file
debconf-set-selections <<\EOF
oracle-java8-installer shared/accepted-oracle-license-v1-1 select true
EOF

# ensure that add-apt-repository is installed
apt-get install -y software-properties-common

# add repository
add-apt-repository -y ppa:webupd8team/java

# update repository
apt-get update -qq

# install
export dl_direct=DIRECT
apt-get install -y oracle-java8-installer
unset dl_direct

# set Java environment variables
apt-get install -y oracle-java8-set-default

# set java 8 as default java version
update-java-alternatives -s java-8-oracle

OPTIONAL: Uninstall OpenJDK
sudo apt-get remove -y openjdk-7-jre-headless

Display your current java version
java -version

Links
http://www.webupd8.org/2014/03/how-to-install-oracle-java-8-in-debian.html
http://www.webupd8.org/2012/11/oracle-sun-java-6-installer-available.html - HowTo, install Java under Ubuntu and Debian
https://launchpad.net/~webupd8team/+archive/java - webupd8team Java repository

Java: Add autocompletion to a (editable) JComboBox

1. Download this source code and add to your Java project:
http://www.orbital-computer.de/JComboBox/source/AutoCompletion.java

2. Add folowing code to enable autocompletion for your JComboBox:
AutoCompletion.enable(yourComboBox);

For further information about JComboBox and AutoCompletion see:
http://www.orbital-computer.de/JComboBox/
https://today.java.net/pub/a/today/2007/07/19/adding-auto-completion-to-swing-comboboxes.html

installSqlDeveloper.sh

Get Oracle SQL Developer package
1. go to Homepage: http://www.oracle.com/technology/software/products/sql/index.html
2. accept the licence
3. login
4. download "Oracle SQL Developer for other platforms"

wget https://raw.githubusercontent.com/panticz/installit/master/install.sqldeveloper.sh -O - | bash -

#!/bin/bash

if [ -z "$1" ]; then
  echo "Please enter the url to download"
  exit
else
  URL=$1
fi

FILE=${URL##*/}
[ -n "$2" ] && USER=$2

# install Java JRE
wget -q https://raw.githubusercontent.com/panticz/installit/master/install.java-jdk.sh -O - | bash -

# get file
if [ ${URL:0:4} == "http" ]; then
  wget -q ${URL} -O /tmp/${FILE}
else
  cp ${URL} /tmp/${FILE}
fi

case ${FILE: -3} in
rpm)
  # convert rpm package to debian
  sudo apt-get install -y alien
  sudo alien /tmp/${FILE}
  sudo dpkg -i /tmp/${FILE/.rpm/.deb}
  ;;
deb)
  # install debian package
  sudo dpkg -i /tmp/${FILE}
  ;;
zip)
  # extract
  [ -d /opt ] || sudo mkdir /opt
  sudo unzip /tmp/${FILE} -d /opt/
  sudo chmod +x /opt/sqldeveloper/sqldeveloper.sh
  ;;
*)
  echo "Unknown file format"
  exit
  ;;
esac

# fix "Error: SQL Developer can't recognize the JDK version" error
sudo sed -i '1a unset GNOME_DESKTOP_SESSION_ID' /opt/sqldeveloper/sqldeveloper.sh

# create startet
cat << EOF | sudo tee -a "/usr/share/applications/Oracle SQL Developer.desktop"
[Desktop Entry]
Version=1.0
Encoding=UTF-8
Name=Oracle SQL Developer
Type=Application
Terminal=false
Exec=/opt/sqldeveloper/sqldeveloper.sh
Icon=/opt/sqldeveloper/icon.png
Categories=Application;Development;
EOF

# create user config to the latest installed JDK version
[ -d /home/${USER}/.sqldeveloper ] || mkdir /home/${USER}/.sqldeveloper
[ -f /home/${USER}/.sqldeveloper/jdk ] || echo "/usr/lib/jvm/$(ls /usr/lib/jvm | grep oracle | tail -1)/" > /home/${USER}/.sqldeveloper/jdk

# set owner
chown -R ${USER}:${USER} /home/${USER}/.sqldeveloper/

# cleanup
rm /tmp/${FILE}

# ToDo
# http://download.oracle.com/otn/java/sqldeveloper/sqldeveloper-4.0.2.15.21-1.noarch.rpm?AuthParam=XXX_XXX
# use a repository
# configure global

Install Java JRE

wget https://raw.githubusercontent.com/panticz/installit/master/install.java-jre.sh -O - | bash -

#!/bin/bash

# no JRE package available, use JDK package
wget -q --no-check-certificate https://raw.githubusercontent.com/panticz/installit/master/install.java-jdk.sh -O - | bash -

Download Oracle Java JRE & JDK using a script
https://ivan-site.com/2012/05/download-oracle-java-jre-jdk-using-a-script/

Fix mozilla java plugin
JAVA_HOME=/usr/lib/jvm/jdk1.7.0
MOZILLA_HOME=~/.mozilla
mkdir $MOZILLA_HOME/plugins
ln -s $JAVA_HOME/jre/lib/i386/libnpjp2.so $MOZILLA_HOME/plugins
or
ln -s $JAVA_HOME/jre/lib/amd64/libnpjp2.so $MOZILLA_HOME/plugins
or
ln -s /usr/lib/jvm/java-7-oracle/jre/lib/amd64/libnpjp2.so ~/.mozilla/plugins/

Links
http://wiki.ubuntuusers.de/make-jpkg
https://github.com/flexiondotorg/oab-java6 - Create a local apt repository for Sun Java 6 and/or Oracle Java 7 packages.
http://www.webupd8.org/2012/01/install-oracle-java-jdk-7-in-ubuntu-via.html
http://www.webupd8.org/2011/03/install-java-in-ubuntu-1104-natty.html
http://www.sysadminslife.com/linux/howto-oracle-sun-java-7-installation-unter-debian-6-squeeze/

Install MS SQL Server JDBC Driver

# get driver
wget http://netcologne.dl.sourceforge.net/project/jtds/jtds/1.2.5/jtds-1.2.5-dist.zip -P /tmp/
unzip /tmp/jtds-1.2.5-dist.zip -d /tmp/
sudo cp /tmp/jtds-1.2.5.jar /usr/share/java/

Eclipse > Build Path > Configure Build Path
Libraries > Add External JARs
/usr/share/java/jtds-1.2.5.jar

# fix tomcat
sudo cp /usr/share/java/jtds-1.2.5.jar /var/lib/tomcat6/webapps/builder3/WEB-INF/lib/

# Links
http://www.java-tips.org/other-api-tips/jdbc/how-to-connect-microsoft-sql-server-using-jdbc.html

Install Eclipse

wget -q https://raw.githubusercontent.com/panticz/installit/master/install.eclipse.sh -O - | bash -

#/bin/bash

# download link
if [ "$(uname -m)" == "x86_64" ]; then
  # 64 bit
  if [ "$1" == "-e" ]; then
    URL=http://mirror.netcologne.de/eclipse/technology/epp/downloads/release/luna/R/eclipse-jee-luna-R-linux-gtk-x86_64.tar.gz
  else
    URL=http://mirror.netcologne.de/eclipse/technology/epp/downloads/release/luna/R/eclipse-java-luna-R-linux-gtk-x86_64.tar.gz
  fi
else
  # 32 bit
    if [ "$1" == "-e" ]; then
    URL=http://mirror.netcologne.de/eclipse/technology/epp/downloads/release/luna/R/eclipse-jee-luna-R-linux-gtk.tar.gz
  else
    URL=http://mirror.netcologne.de/eclipse/technology/epp/downloads/release/luna/R/eclipse-java-luna-R-linux-gtk.tar.gz
  fi
fi

# install Java JDK
wget -q https://raw.githubusercontent.com/panticz/installit/master/install.java-jdk.sh -O - | bash -

# download new eclipse release
wget -q ${URL} -P /tmp

# backup old release
[ -d /usr/lib/eclipse/ ] && sudo mv /usr/lib/eclipse/ /usr/lib/eclipse.$(date -I)

# install new release
sudo tar xzf /tmp/eclipse-*-linux-gtk*.tar.gz -C /usr/lib/

# set owner and permissions
sudo chown -R root:root /usr/lib/eclipse
sudo chmod -R +r /usr/lib/eclipse

# add executable to path
cat <<EOF> /tmp/eclipse
#!/bin/sh
export ECLIPSE_HOME="/usr/lib/eclipse"

\${ECLIPSE_HOME}/eclipse $*
EOF

sudo mv /tmp/eclipse /usr/bin/eclipse
sudo chmod 755 /usr/bin/eclipse

# fix UI bug on Debian Wheezy
. /etc/os-release
if [ "${ID}" == "debian" -a "${VERSION_ID}" == "7" ]; then
  sudo sed -i '3i export SWT_GTK3=0' /usr/bin/eclipse
fi

# create starter
cat <<EOF> /tmp/eclipse.desktop
[Desktop Entry]
Encoding=UTF-8
Name=Eclipse
Comment=Eclipse IDE
Exec=eclipse
Icon=/usr/lib/eclipse/icon.xpm
Terminal=false
Type=Application
Categories=GNOME;Application;Development;
StartupNotify=true
EOF

sudo mv /tmp/eclipse.desktop /usr/share/applications/eclipse.desktop
sudo chmod +r /usr/share/applications/eclipse.desktop

# configure memory
sudo sed -i 's|-Xmx384m|-Xmx1024m|g' /usr/lib/eclipse/eclipse.ini

# clean up
rm /tmp/eclipse-*-linux-gtk*.tar.gz

Git plugin
# http://www.vogella.com/tutorials/EclipseGit/article.html
http://download.eclipse.org/egit/updates

WindowBuilder (Java GUI creator plugin)
http://www.eclipse.org/windowbuilder/

sudo eclipse
install new software:
http://download.eclipse.org/windowbuilder/WB/release/R201209281200/4.2/

Global settings
/usr/lib/eclipse/eclipse.ini

OPTIONAL: change editor line break to 240 char
Project > Properties
Configure Worksapece Settings
Edit
Line Wraping
Maximum line widht: 240

Links
http://www.youtube.com/watch?v=WY9QbOdWkn0 - create Java Gui Tutorial (german)
http://code.google.com/intl/de/eclipse/docs/install-eclipse-3.5.html
http://sourceforge.net/projects/shelled/

Install NetBeans

wget https://raw.githubusercontent.com/panticz/installit/master/install.netbeans.sh -O - | bash -

#!/bin/bash

# download link
if [ "$1" == "-e" ]; then
  URL=http://download.netbeans.org/netbeans/8.0/final/bundles/netbeans-8.0-javaee-linux.sh
else
  URL=http://download.netbeans.org/netbeans/8.0/final/bundles/netbeans-8.0-javase-linux.sh
fi

# install Java JDK
wget -q https://raw.githubusercontent.com/panticz/installit/master/install.java-jdk.sh -O - | bash -

# download and install netbeans from homepage
wget -q ${URL} -O /tmp/netbeans-linux.sh
sudo bash /tmp/netbeans-linux.sh --silent

# cleanup
rm /tmp/netbeans-linux.sh

Add git repository
https://www.youtube.com/watch?v=mzzAUEFS4vs
https://netbeans.org/kb/docs/ide/github_nb_screencast.html

OPTIONAL: install MySQL driver
sudo apt-get install libmysql-java

DEP: fix ubuntu locale settings for german
sed -i 's|en_US.UTF-8|de_DE.UTF-8|g' /etc/scim/global

DEP: disable compiz effects (Visual Effects (System > Preferences > Appearance > Visual Effects => none)
metacity --replace &

Fix bold fonts under Linux
sudo apt-get remove -y fonts-unfonts-core

Links
http://www.techytalk.info/netbeans-cannot-find-java-please-use-jdkhome-switch/ - HowTo (re)configure JAVA JDK
http://wiki.netbeans.org/NBPackagingPlan

Connect to MySQL DB

# ubuntu package
sudo apt-get install -y libmysql-java

path: /usr/share/java/mysql-connector-java.jar

# download
wget http://ftp.gwdg.de/pub/misc/mysql/Downloads/Connector-J/mysql-connector-java-5.1.12.tar.gz -P /tmp

# extract
tar xzf /tmp/mysql-connector-java-5.1.12.tar.gz -C /tmp/

# copy to your classpath
cp /tmp/mysql-connector-java-5.1.12/mysql-connector-java-5.1.12-bin.jar ~/NetBeansProjects/classpath/

# Netbeans
add Library / Jar File
select
~/NetBeansProjects/classpath/mysql-connector-java-5.1.12-bin.jar

# create tatabase
create database java;

Syndicate content