Java, Uncategorized

Message – Could not initialize class sun.awt.X11GraphicsEnvironment – Exception Type java.lang.NoClassDefFoundError

today i have message error in my page web application about :

java.lang.NoClassDefFoundError: Could not initialize class sun.awt.X11GraphicsEnvironment
java.lang.Class.forName0(Native Method)
java.lang.Class.forName(Class.java:264)
java.awt.GraphicsEnvironment.createGE(GraphicsEnvironment.java:103)
java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment(GraphicsEnvironment.java:82)
sun.awt.X11FontManager.isHeadless(X11FontManager.java:509)
sun.awt.X11FontManager.getFileNameFromPlatformName(X11FontManager.java:189)
sun.font.SunFontManager.initCompositeFonts(SunFontManager.java:3481)
sun.font.SunFontManager.access$700(SunFontManager.java:65)
sun.font.SunFontManager$2.run(SunFontManager.java:545)
java.security.AccessController.doPrivileged(Native Method)
sun.font.SunFontManager.<init>(SunFontManager.java:376)
sun.awt.FcFontManager.<init>(FcFontManager.java:35)
sun.awt.X11FontManager.<init>(X11FontManager.java:57)
sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
java.lang.reflect.Constructor.newInstance(Constructor.java:423)
java.lang.Class.newInstance(Class.java:442)
sun.font.FontManagerFactory$1.run(FontManagerFactory.java:83)
java.security.AccessController.doPrivileged(Native Method)
sun.font.FontManagerFactory.getInstance(FontManagerFactory.java:74)
java.awt.Font.getFont2D(Font.java:491)
java.awt.Font.canDisplayUpTo(Font.java:2060)
java.awt.font.TextLayout.singleFont(TextLayout.java:470)
java.awt.font.TextLayout.<init>(TextLayout.java:531)
org.apache.poi.xssf.usermodel.helpers.ColumnHelper.getColumnWidth(ColumnHelper.java:326)
org.apache.poi.xssf.usermodel.XSSFSheet.autoSizeColumn(XSSFSheet.java:337)

My application running in Centos 6.8. This problem found if i want download file pdf, excel, etc.

And Solution i found in https://groups.google.com/forum/#!topic/railo/49KLaaXkdrs

# Tomcat memory settings
# -Xms<size> set initial Java heap size
# -Xmx<size> set maximum Java heap size
# -Xss<size> set java thread stack size
# -XX:MaxPermSize sets the java PermGen size
JAVA_OPTS=”-Xms1024m -Xmx1024m -XX:MaxPermSize=512m “;   # memory settings

-Djava.awt.headless=true
export JAVA_OPTS;

And its very helpfull.

Advertisements
in my Live, Java

dynamic category and question

now i have chalenge for create dynamic category and question

Screenshot_2

 

String totalCat = (String) request.getAttribute("totalcat");
Integer totalCategory = Integer.parseInt(totalCat);

System.out.println("total category:" + totalCategory);

for (int countCat = 0; countCat < totalCategory; countCat++) {
  String Category = (String) request.getAttribute("category" + countCat);
  System.out.println("categoryid:" + Category);
  String totalQuestion = (String) request.getAttribute("totalquest" + Category);
  System.out.println("totalQuestion:" + totalQuestion);
  Integer totalQuestions = Integer.parseInt(totalQuestion);

// System.out.println(totalQuestions);

for (int countQuest = 0; countQuest < totalQuestions; countQuest++) {
 questId = (String) request.getAttribute("cat" + Category + "quest" + countQuest);
 answerText = (String) request.getAttribute("answertext" + questId);
 }
 }
Uncategorized

get WSDL to package (Eclipse/STS)

in my job (i use opentext cws), i have case to use web service SOAP and must to use ws-import for getting java class from server.

With maven you can use 3 dependency

<dependency>
<groupId>com.sun.xml.ws</groupId>
<artifactId>jaxws-rt</artifactId>
<version>2.2.8</version>
</dependency>
<dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.4.3</version>
</dependency>
<dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.19.1</version>
</dependency>

add maven-failsafe-plugin

<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.6</version>
<!– Disable tests for now, until we have client jar built then we can
run as follows; To run the tests: $ mvn verfiy -DskipTests=false –>
<configuration>
<skipTests>${skipTests}</skipTests>
</configuration>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>

and add plugin ws import

<plugin>
<groupId>org.jvnet.jax-ws-commons</groupId>
<artifactId>jaxws-maven-plugin</artifactId>
<version>2.2</version>
<executions>
<execution>
<goals>
<goal>wsimport</goal>
</goals>
</execution>
</executions>
<configuration>
<wsdlUrls>
<wsdlUrl>${ipaddress}/cws/services/Authentication?wsdl</wsdlUrl>
<wsdlUrl>${ipaddress}/cws/services/ContentService?wsdl</wsdlUrl>
</wsdlUrls>
<sourceDestDir>${basedir}/src/main/java/</sourceDestDir>
</configuration>
</plugin>

your class will be download to /src/main/java/

thanks//Danang

Development Environment, in my Live

Migration Redmine (Bitnami) to New Server

redmine_logo_v1

Now, i have case to migration redmine to new server  (at Centos 6.5), and this is my notes.

1. Dump database mysql on last server and copy folder /contents

2. Install your redmine bitnami in new server.

3. Add path ruby to new server at .bashrc in /root

PATH="$PATH:/opt/redmine/ruby/bin:/opt/redmine/git/bin:/opt/redmine/perl/bin::/opt/redmine/apache2/bin::/opt/redmine/subversion/bin"

and restart to run the path.

4. Run rake command to migrate database,

$ rake db:migrate RAILS_ENV=production

5. Run rake command to migrate plugin,

$ rake db:migrate_plugins RAILS_ENV=production

end.

Programming, Shell Script

Extract last day file zip with shell script

Now I get a new experience in the manipulation of files using shell script. In this condition I got a challenge to select the file on the last day, and in a compressed zip file.

I started looking on the last day of the file using the command

#find /location/file type f -ctime -1

then you can combine with unzipp command and give the location of the target folder

#find "$dir" -type f -ctime -1 -exec sh -c 'unzip -d `dirname {}`/../unzipp {}' ';'

you can run the command on a .sh file and you can run as a cron job to use.

Java

Kembali mengingat JUnit

JUnit berguna untuk memastikan (testing) code yang kita buat berjalan sesuai dengan yang kita butuhkan.

sekarang saya coba kembali mengingat membuat unit testing sederhana untuk memeriksa karakter dari sebuah kalimat.

import static org.junit.Assert.assertEquals;
import org.junit.Test;

public class TestJunit {
 @Test
 public void testAdd() {
 String str= "Latihan menggunakan JUnit";
 assertEquals("Latihan menggunakan Junit",str);
 }
}

lalu buat class runner untuk menjalankannya.

import org.junit.runner.JUnitCore;
import org.junit.runner.Result;
import org.junit.runner.notification.Failure;

public class TestRunner {
 public static void main(String[] args) {
 Result result = JUnitCore.runClasses(TestJunit.class);
 for (Failure failure : result.getFailures()) {
 System.out.println(failure.toString());
 }
 System.out.println(result.wasSuccessful());
 }
 }

lalau jalankan. hasil yang didapat akan menampilkan hasil perbandingan kalimat “Latihan menggunakan Junit” dengan false atau true .

Development Environment, Java

Install Gradle

logo Gradle
logo Gradle

Gradle is a dependency management / build tool that combines the best of Maven and Ant, and making it an extremely powerful and customizable tool. Here’s how to install.
1. Install Java
First you need to have the Java JDK (Java Development Kit) installedon computer; because having the JRE (Java Runtime Environment) is not enough.
To check if you have the JDK installed, open a command prompt or terminal and write:
javac -version
If you have a JDK installed, you will see your javac version output, eg. javac 1.7.0_25.
Iif you get an error, you must download and install the Java JDK.
2. Download Gradle
Download from Gradle site at http://www.gradle.org/installation
3. Unpack and Set System variables
Windows :

  1. Unzip the Gradle download to the folder to which you would like to install Gradle, eg. “C:\Program Files”. The subdirectory gradle-x.x will be created from the archive, where x.x is the version.
  2. Add location of your Gradle “bin” folder to your path. Open the system properties (WinKey + Pause), select the “Advanced” tab, and the “Environment Variables” button, then add “C:\Program Files\gradle-x.x\bin” (or wherever you unzipped Gradle) to the end of your “Path” variable under System Properties. Be sure to omit any quotation marks around the path even if it contains spaces. Also make sure you separated from previous PATH entries with a semicolon “;”.
  3. In the same dialog, make sure that JAVA_HOME exists in your user variables or in the system variables and it is set to the location of your JDK, e.g. C:\Program Files\Java\jdk1.7.0_06 and that %JAVA_HOME%\bin is in your Path environment variable.
  4. Open a new command prompt (type cmd in Start menu) and run gradle –version to verify that it is correctly installed.

Mac and Linux :

  1. Extract the distribution archive, i.e. gradle-x.x-bin.tar.gz to the directory you wish to install Gradle. These instructions assume you chose /usr/local/gradle. The subdirectory gradle-x.x will be created from the archive.
  2. In a command terminal, add Gradle to your PATH variable: export PATH=/usr/local/gradle/gradle-x.x/bin:$PATH
  3. Make sure that JAVA_HOME is set to the location of your JDK, e.g. export JAVA_HOME=/usr/java/jdk1.7.0_06 and that $JAVA_HOME/bin is in your PATH environment variable.
  4. Run gradle –version to verify that it is correctly installed.

You now have Gradle ready!

references:

Development Environment

Membuat dan Menggunakan Repository di GitHub

GitHub

Pada artikel kali ini saya akan mencoba membuat repository Git pada GitHub. Sebelumnya apa itu GitHub? Github adalah layanan yang menggunakan Git sebagai Version Control untuk mengelola dan memanajemen file. Dan ini sangatlah berguna dalam hal distribusi file, khususnya dalam dunia pemrograman. Berikut ini adalah tutorial dasar untuk mempermudah pekerjaan dengan mudah menggunakan GitHub.

Step 1. Membuat repository baru di GitHub 

Dalam menggunakan Version controll, anda akan selalu melakukan Commit pada Git, tempat tersebut dinamakan sebuah repository (a.k.a. “repo”). Dan untuk menyimpan project yang anda buat pada GitHub, anda perlu memiliki GitHub Repository. Berikut ini adalah cara untuk membuat repository pada GitHub.

Click New Repository .

github2012-12-23_211436

Selanjutnya masukkan informasi tentang anda. jika sudah di isi, selanjutnya click “Create Repository.”

Screenshot from 2012-12-20 21-19-08
Selamat! Sampai pada tahap ini, anda sudah memiliki Repo
Installasi Git pada komputer anda
  • Sistem operasi Linux Ubuntu

Jika anda pengguna Sistem operasi Linux Ubuntu, anda hanya mengetikkan perintah dibawah ini untuk melakukan instalasi Git pada komputer anda.

sudo apt-get install git

  • Sistem operasi Windows

Jika anda pengguna Windows  anda harus mendownload aplikasi  github dari http://windows.github.com/

Membuat file README untuk repo.

File  README bukanlah bagian yang diperlukan dari repo GitHub, tapi kita akan membuat file tersebut untuk uji coba apakah repo dapat digunakan. File README adalah catatan yang bagus untuk menggambarkan proyek Anda atau menambahkan beberapa dokumentasi seperti cara menginstal atau menggunakan proyek Anda. Anda mungkin ingin menyertakan informasi kontak person – jika proyek Anda menjadi orang yang populer akan ingin membantu Anda suatu saat.

 

sekarang masuklah ke command prompt, lalu buat folder sesuai nama project :

mkdir ~/Hello-World  #Membuat direktori "Hello-World"

setelah itu, masuk ke folder tersebut:

cd ~/Hello-World #Masuk ke folder yang anda buat

setelah masuk, ketik perintah tersebut untuk meng initialize folder tersebut:

git init    #Sets up the necessary Git files

setelah masuk, ketik perintah tersebut untuk meng initialize folder tersebut:

touch README# Creates a file called "README" in your Hello-World directory

nah sekarang kita coba file README  di folder Hello-World tersebut menggunakan teks editor anda. tambahkan tulisan “Hello World!” di file tersebut, lalu di simpan .

Step 2. Commit file README 

Sekarang file README sudah siap untuk di commit. Untuk meng -commit dibutuhkan snapshot dari semua file di project anda pada waktu yang sama. pada command prompt, ketikan perintah:

git add README #untuk menambahkan file README
git commit -m 'first commit' #Commit file anda, dengan menambahkan pesan "first commit"

Step 3: Push  commit anda 

Sampai pada step ini, anda telah melakukan commit pada lokal repository anda, tapi masih belum melakukan apapun pada repo GitHub.

Untuk menghubungkan lokal koneksi anda ke GitHub, anda perlu me remote repo dan melakukan push pada commit  anda.

Masukkan perintah ini untuk melakukannya :

git remote add origin https://github.com/namauser/Hello-World.git # membuat remote dengan nama "origin" pointing pada GitHub repo
git push origin master# Mengirimkan perintah commit sebagai "master" branch pada GitHub

Sekarang anda dapat melihat repository anda di GitHub, anda akan dapat melihat file README ada di repo .

 9165bb84-3ae2-40a7-ba6a-d63640a281e0

Selamat…

Congratulations! anda sudah membuat sebuah repository di GitHub, membuat README, meng commit nya , dan push di GitHub.  😀

Seluruh Command

membuat repo menggunakan command

touch README.md
git init
git add README.md
git commit -m "first commit"
git remote add origin https://github.com/username/Hello-World.git
git push -u origin master

Push  repository dari command

git remote add origin https://github.com/usernam/Hello-World.git
git push -u origin master

Reference