Εμφάνιση αναρτήσεων με ετικέτα Eclipse. Εμφάνιση όλων των αναρτήσεων
Εμφάνιση αναρτήσεων με ετικέτα Eclipse. Εμφάνιση όλων των αναρτήσεων

Παρασκευή 1 Φεβρουαρίου 2008

How to debug your web application in JBoss with Eclipse

For many developers, debugging a web application simply means looking at the logs and trying to figure out what went wrong. Fortunately, there is an easier way. You can debug a web/JEE application the same way you debug a JSE or JME application.
With today's IDEs you can also debug web/jee applications step by step, while the application is deployed to an application server like JBoss. The following trick works with JBoss application server, please contribute for other application servers.
OK, here is the trick. Open %JBOSS_HOME%/bin/run.bat (Windows) or $JBOSS_HOME/bin/run.sh (Linux) and uncomment the line that contains the port 8787, i.e. this line (by simply deleting the rem word in front):

rem set JAVA_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,address=8787,server=y,suspend=y %JAVA_OPTS%

If you cannot find the line in run.sh, try $JBOSS_HOME/bin/run.conf.

In your eclipse environment, click on the arrow next to the Debug button and select Debug... Select Remote Java Application and press the New button to create a new configuration of this type.
In the Connect tab, browse your web / jee eclipse project, leave the connection type to Standard (Socket Attach) and enter the host name (localhost if it is local) but modify the port to 8787 (this is JBoss' debugging port). In the Source tab you may wish to add any dependent projects. Click on Apply. That's it.

Now all you need to do is start your JBoss application server, deploy before or after your war or ear file. The application server stops waiting for someone to listen to port 8787. Click on Debug or select the above configuration in the Debug window, and voila, JBoss continues starting up.

Set your breakpoints etc. enjoy!

P.S. Netbeans has very good debugging integration with most of the application servers. If your application server is not listed in its list of available application servers, simply define it under Tools --> Server.

References
  1. Monitoring a remote JBoss Server from Eclipse

Πέμπτη 11 Οκτωβρίου 2007

Greek and Java

Under this subject I publish any issues that a Java programmer may encounter with Greek letters while writing Java programs. This information might be useful to programmers of other native languages too.

Issue 1: Apache Tomcat doesn't display Greek

Instead ???? are displayed.

Solution
You have to perform the following steps:
  1. Edit conf/server.xml like so:

    connector port="8080" maxhttpheader="8192" maxthreads="150" minsparethreads="25" maxsparethreads="75" enablelookups="false" redirectport="8443" acceptcount="100" connectiontimeout="20000" disableuploadtimeout="true" URIEncoding="ISO-8859-7" or URIEncoding="UTF-8" depending on your application.

  2. If you are using a servlet, then you have to add the following lines of code to your doGet() method:

    request.setCharacterEncoding("ISO-8859-7"); // or UTF-8
    response.setCharacterEncoding("ISO-8859-7"); // or UTF-8


  3. If you are using a JSP, then you must include the following header on the beginning of the jsp page:

    <%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> // or ISO-8859-7
  4. You may need to add this line too
    // or ISO-8859-7
  5. In case the encoding of the GET command is different than the one in URIEncoding (e.g. ISO-8859-7 and URIEncoding="UTF-8"), then use the command request.getQueryString() to get the original query string, before this is changed by Tomcat's URIEncoding, manually parse the string to a variable, e.g. myVar, and then use e.g. URLDecoder.decode(myvar, "ISO-8859-7").

Note: This info applies to JBoss too, as it is based on Tomcat.

References:
  1. JHUG forum link
  2. Apache Tomcat wiki
  3. The absolute minimum about Unicode and Character Sets

Issue 2: Greek support in Eclipse IDE

Right click an eclipse project and select Properties. In the info property, under Text file encoding box, select one of the following encodings:
  • ISO-8859-7
  • Cp1253
  • UTF-8
Issue 3: Greek support in Netbeans IDE

Right click on a project and select Properties. In the Encoding property, select one of the following encodings:
  • ISO-8859-7
  • Windows-1253
  • UTF-8
Issue 4: Greek support in MySQL

Use one of the following collations: utf8_unicode_ci or utf8_general_ci. Charset should be UTF-8.
If you are using phpmyadmin, you can do this while creating the database. If you have already created the database, you can change its collation by clicking on Operations tab.
If you can still not see Greek, edit my.conf and under [mysqld] tag add the string
character-set-server = utf8.

To use together with Tomcat:

url="jdbc:mysql://localhost/timesheet?useUnicode=true;characterEncoding=utf8" // or ISO-8859-7

Issue 5: Define encoding

Whenever you open/save a text file, specify the character encoding and don't rely on the OS default encoding:

Reader r = new InputStreamReader(new FileInputStream(file), "UTF-8"); // ISO-8859-7
Reader r = new InputStreamWriter(new FileInputStream(file), Charset.forName("ISO-8859-7"));
Writer w = new OutputStreamWriter(new FileOutputStream(file), "ISO-8859-7"); // UTF-8
Writer w = new OutputStreamWriter(new FileOutputStream(file), Charset.forName("UTF-8"));
String s = new String(byteArray, "UTF-8");
byte[] a = string.getBytes("UTF-8"); // Cp1253

Issue 6: Greek locale
private static final Locale GREEK_LOCALE = new Locale("el", "GR");

Issue 7: Greek and JEditorPane
Unfortunately, JEditorPane supports HTML 3.2 (to some arguable extend), while named Greek entities were added in HTML 4.0. This means, that

jEditorPane.setContentType("text/html");
jEditorPane.setText("αβγδ");
System.out.println(jEditorPane.getText());

will not return the Greek characters but something like

#965;#966;#967;#968

You can try

jEditorPane.setContentType("text/html;charset=utf-8");
jEditorPane.setText(new String("αβγδ".getBytes("utf-8"),"utf-8");

but it still doesn't work.

A solution is simply to use

jEditorPane.setContentType("text/plain");

In any case, it is better to handle the text from the variable it is stored than getting it from jEditorPane.getText().

References:
  1. Java Anti-Patterns