Groovy has next advantages comparing to Groovy (but not only):
- better OOP implementation
- has more primitive types. Perl only has scalar, array and Map
- Groovy types could be both dynamic and static
- easer to read and understand
- Groovy may use all power and libraries of Java
- better IDE support (like IntelliJ IDEA, Eclipse, etc)
Groovy advantages comparing to Perl
CliBuilder
CliBuilder is a very usefull Groovy tool for parsing command line arguments. It reminds me Perl’s Getopts function.
See documentation here
http://groovy.codehaus.org/gapi/groovy/util/CliBuilder.html
Recently looked for analog of ‘which‘ command for Windows.
C:\Python25\Tools\scripts>python which.py python
python: not found
Pfffff! Funny!
See
http://stackoverflow.com/questions/304319/is-there-an-equivalent-of-which-on-windows
for other ideas
How to run command silently in the Bash
Example:
myCommand & > /dev/null 2>&1
Explanation:
& – start command as background task
> – output redirection
/dev/null – is a special file that discards all data written to it (but reports that the write operation succeeded) and provides no data to any process that reads from it (yielding EOF immediately)
2>&1 – redirect Std-Error to Std-Output
NoClassDefFoundError and ClassNotFoundException. Difference, examples, solutions
First at all, let’s discuss what is the difference between NoClassDefFoundError and ClassNotFoundException. I would like to focus on the next:
- NoClassDefFoundError is descendant of Error, but ClassNotFoundException is descendant of RuntimeException. And both are runtime, unchecked.
- NoClassDefFoundError occurs when Classloader loads classes implicitly, but ClassNotFoundException explicitly.
Please read additional details in Java docs: ClassNotFoundException and NoClassDefFoundError
In my practice ClassNotFoundException was not so puzzling as NoClassDefFoundError, because we can get it only in case when we explicitly call next methods:
- The forName method in class Class.
- The findSystemClass method in class ClassLoader.
- The loadClass method in class ClassLoader.
But NoClassDefFoundError can appear in very unexpected situations (from easiest to more complicated):
1. You are using some library, like spring or Apache commons, and forgot to add this jar to your CLASSPATH.
Solution. Add necessary jars to CLASSPATH. Use findjar.com if you don’t know what jar your class belongs to.
2. You added necessary jar, but your CLASSPATH is not correct.
Solution. Check current CLASSPATH. You may check your run-script or Ant/Maven dependencies. Another way is to connect to you application using JMX (JConsole, jvisualvm) locally or remotely. To check remotely add next parameters (as example): -Dcom.sun.management.jmxremote.port=${your_port} -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false.
Or use System.getProperty(“java.class.path”) to check current CLASSPATH from the code in debug log mode.
3. You are running program using -jar command, but forgot to define ClassPath attribute of this class to manifest file.
Solution. Add ClassPath attribute to your manifest file.
4. Program is compiled, but at runtime necessary class is absent.
Solution. Add necessary classes/jars to CLASSPATH.
5. Necessary classes was loaded, but not in the same Classloader or parent ClassLoader.
For example, you put foo.jar that uses spring.jar to Tomcat’s common/lib directory; your web application (in $TOMCAT/webapps/ ) uses foo.jar; you put spring.jar into $TOMCAT/webapps/yourapplication/WEB-INF/lib directory. And this will cause NoClassDefError! Why?
ClassLoader in “common” (higher) level doesn’t see classes loaded by it’s descendant’s ClassLoader.
You may read more detailed information in Tomcat ClassPath HOW-TO and Java ClassLoader hierarchy.
Solutions
- move foo.jar to $TOMCAT/webapps/yourapplication/WEB-INF/lib if no other web applications use this jar.
- move required jars to $TOMCAT/common/lib that foo.jar requires (beware jar mess)
- configure shared.loader property in catalina.properties file (beware configuration mess)
6. Same class is located in different jars of your CLASSPATH or same jar is located in different ClassLoader’s levels.
For example foo.jar is located in common/lib and WEB-INF/lib. This may cause ClassDefNotFoundError. Sometimes it happens sometimes not.
Solution. Remove duplicate jar files from your CLASSPATH.
Запуск JSTL в Eclipse Dynamic Web Project
Оказывается не все так просто, если запускать Tomcat под Eclipse.
Если в Eclipse создать Dynamic Web Project, то простое добавление
jstl.jar и standard.jar в WEB_INF/lib может не помочь,
даже если в Java Build Path они есть.
При этом, если экпортировать .war, то в Tomcat запустится нормально.
Не запускается именно из-под Eclipse.
Помогло следующее:
при вызове контекстного меню в Run As -> Run configuration
выбирает нужный сервер из списка Apache Tomcat (перед этим нужно остановить)
справа выбираем сервер и в закладке Classpath и добавляем (Add jars):
jstl.jar, standard.jsr, servlet-api.jar, jsp-api.jar, el-api.jar
Hibernate: ошибка связанная с SLF4J
Проблема:
При запуске нового проекта на Hibernate 3.3.2 скопированы с архива (папка lib) все необходимые библиотеки, в том числе и slf4j-api-1.5.8.jar.
Но при старте теста появляется ошибка:
SLF4J: Failed to load class “org.slf4j.impl.StaticLoggerBinder”. SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details. Exception in thread “main” java.lang.ExceptionInInitializerError
Решение:
На сайтеhttp://www.slf4j.org/codes.html#StaticLoggerBinder эту ошибку описывают так:
“This error is reported when the org.slf4j.impl.StaticLoggerBinder class could not be loaded into memory. This happens when no appropriate SLF4J binding could be found on the class path. Placing one (and only one) of slf4j-nop.jar, slf4j-simple.jar, slf4j-log4j12.jar, slf4j-jdk14.jar or logback-classic.jar on the class path should solve the problem.”
То есть нужно в пути к библиотекам добавить один из (и только один slf4j-nop.jar, slf4j-simple.jar, slf4j-log4j12.jar, slf4j-jdk14.jar or logback-classic.jar)
Скачать необходимую библиотеку можно с сайта
http://www.slf4j.org/dist/
(берем ту же версию, что и slf4j-api).
В jar архиве есть необходимые библиотеки.
Я взял slf4j-jdk14-1.5.8.jar.