Friday, August 21, 2015

"couldn't make stderr distinct from stdout" when running Cygwin commands


>SOLUTION

Check you envvars.

Originally the Path had Git's bin before cygwin64.
  Path=..;C:\Git\bin;C:\cygwin64\bin

Switching places:
  Path=..;C:\cygwin64\bin;C:\Git\bin
in order to read cygwin's library first.

In such case, you may get issues with git. So test it after your have changed the Path.

If it happens to get problems with Git, it's necessary to point git's executables manually or using a script to set the local envvar during git's execution context.

Another solution could be adopting one or another.

>ENV

Windows 7-10

Saturday, August 8, 2015

apache2 vs. php5 (lump) - install failure on debian 7 (wheezy)


If you get one of the messages below, probably you need to upgrade your installation.
Check the commands at the end.

-------------------------------------------------------------------------------------------------------
>failure messages

apache2: Syntax error on line 140 of /etc/apache2/apache2.conf: 
Syntax error on line 1 of /etc/apache2/mods-enabled/php5.load: Cannot load /usr/lib/apache2/modules/libphp5.so into server: /usr/lib/x86_64-linux-gnu/libk5crypto.so.3: symbol krb5int_buf_len, version krb5support_0_MIT not defined in file libkrb5support.so.0 with link time reference

--- --
[FAIL] Starting web server: apache2 failed!
[warn] The apache2 configtest failed. ... (warning).
Output of config test was:
apache2: Syntax error on line 140 of /etc/apache2/apache2.conf: Could not open configuration file /etc/apache2/mods-enabled/php5.load: No such file or directory

-- --
Action 'configtest' failed.
The Apache error log may have more information.


-------------------------------------------------------------------------------------------------------
>commands

If you have MySQL already installed, you just need to install apache, php and phpmydmin.
If not, install MySQL first.

To install apache and php5, run the following commands as root (su or sudo).

apt-get ugrade
apt-get update
apt-get install apache2
apt-get install php5
apt-get install libapache-mod-php5


Sunday, May 24, 2015

maven version conflict


>PROBLEM
[WARNING] Rule 0: org.apache.maven.plugins.enforcer.RequireMavenVersion failed with message:
Detected Maven Version: 3.0.4 is not in the allowed range 3.1.1.


>SOLUTION
Using an old version incompatible with the version required.
  M2_HOME=D:\portables_d\apache-maven-3.0.4

Switch the M2_HOME envvar to the new maven version:
  M2_HOME=D:\portables_d\apache-maven-3.1.1





Sunday, March 15, 2015

Apache or Node? Which one is best?


My Thoughts and Conclusions About Two Different Ways of Doing Something Concerning Server's Approaches Using Node.js vs. Apache Comparison Example

When the major problem is the number of persons to travel, matter less if the car has front-wheel drive or rear-wheel drive.
Number of seats care most.

Being straight, more requests demand more resources and increase possible concurrencies issues.
It matters less how the process requests are handled, but how the project's resources in general may scale with high availability.

Putting aside that, if you have light CPU processing per request, Node.js will be lighter approach, otherwise, if it is not possible to guarantee that, threads will fit better, so Apache is a better choice.

See more at:

http://www.quora.com/What-are-the-pros-and-cons-of-Node-js-versus-Apache-web-server

http://voidcanvas.com/describing-node-js/

http://www.toptal.com/nodejs/why-the-hell-would-i-use-node-js

https://thomashunter.name/blog/php-vs-nodejs/

Sunday, December 28, 2014

git svn clone command fails on windows


>PROBLEM

The following command is executed:

    git svn clone file://D:/work/dev/java/lab/junit

It returns:   

    C:\Program Files (x86)\Git\bin\perl.exe: *** unable to remap C:\Program Files (x86)\Git\bin\libsvn_wc-1-0.dll to same address as parent -- 0x6F1C0000






 The same problem happened on Git's bash and Cygwin console.



>SOLUTION

I updated the cygwin´s perl and git libraries to the last one by this time, since It was not possible to update Git, because the last version was already installed (Git-1.9.5-preview20141217.exe),
After the update, a new attempt using Cygwin succeeded.




The clue came from:

https://code.google.com/p/conemu-maximus5/wiki/AppHelp


Sunday, September 14, 2014

Windows Update failure: WindowsUpdate_000000FF WindowsUpdate_dt000

Update failure returning message:
   
    "WindowsUpdate_000000FF" "WindowsUpdate_dt000"
   
I got this message during of of the procedures of windows update when trying to install Microsoft.NET Framework 4.5.1 and 4.

>SOLUTION

Manual installation of each update that failed.
First, to download, identify the hotfix number shown on "windows update".
Usually it is a number like this: KB2894854.
Find and download by this number. Ex.:
search for:
  download KB2894854
or
  download microsoft KB2894854

After download, run the executables to install the hotfix.


>INSTALLED PACKAGES

For example, in my case I had to download and install each hotfix that windows' update refused to.
This is the hotfix list and the respectives URLs:
- Microsoft .NET Framework 4.5.1 = http://www.microsoft.com/pt-br/download/details.aspx?id=40779
http://www.microsoft.com/pt-br/download/details.aspx?id=41378
- KB970892 = http://www.microsoft.com/en-us/download/confirmation.aspx?id=42779
- KB2894854 = http://www.microsoft.com/pt-br/download/details.aspx?id=41378
- KB2898869 = http://www.microsoft.com/pt-br/download/details.aspx?id=41903
- KB2901126 = http://www.google.com.br/url?url=http://www.microsoft.com/pt-br/download/details.aspx%3Fid%3D41918&rct=j&q=&esrc=s&sa=U&ei=utYVVPnoMeOmigLK-4HoCw&ved=0CBQQFjAA&usg=AFQjCNFX685_-qZvmx3_HKq84SxCb_SaWA
- KB2972216 = http://www.microsoft.com/en-ie/download/details.aspx?id=44181





Sunday, June 8, 2014

'Maven Dependencies' references non existing library ... com\sun\tools\1.6\tools-1.6.jar'


>PROBLEM

  'Maven Dependencies' references non existing library ... com\sun\tools\1.6\tools-1.6.jar'    auth        Build path    Build Path Problem
Full Compilation Error Message:

  The container 'Maven Dependencies' references non existing library
    'D:\work\repolib\java\mvn_repo\com\sun\tools\1.6\tools-1.6.jar'    auth        Build path    Build Path Problem


>SOLUTION

This error is caused by this dependency:

        <dependency>
            <groupId>org.jboss.as</groupId>
            <artifactId>jboss-as-jpa-hibernate3</artifactId>
            <version>7.2.0.Final</version>
        </dependency>

It was substituted by another.

>ENV
eclipse, maven, java, hibernate


>DETAILED APPROACH

A build path problem usually indicates that a dependency is missing.
So, this kind of problem may have many reasons.
First check your development tool configuration.
If Eclipse, go to preferences, Build Path. Check also Project Facets.
Go to the pom.xml and check the compilation configuration version.
It must be the same of Eclipse's configuration.

Example:

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                    <encoding>UTF-8</encoding>
                </configuration>
            </plugin>
        </plugins>
    </build>

If Eclipse configuration is using version java 7, switch to 1.7 where it is 1.6.


After all this check up, if the problem remains, do the following:

1. Remove all dependencies from your pom.xml file and let it as follow:

    <dependencies>
    </dependencies>

2. Then insert the dependencies again using small groups (for instance 3 dependencies) until one of them triggers the target error.
Then isolate the dependency that causes the problem removing and test one by one in that group until the error disappears.


Saturday, May 31, 2014

Eclipse java project and the "The selection did not contain any resources that can run on a server" warn.



>PROBLEM

When you try to run the project on the server using "Run on Server" (SA+X+R) option, eclipse returns the following message:
  The selection did not contain any resources that can run on a server.


>SOLUTION

On the navigation panel, click over the project for pop-up menu, properties, Project Facets, check:
- Dynamic Web Module
- Java




>ENV
eclipse, maven java project.


Wednesday, May 28, 2014

Spring-MVC - WARN [CglibAopProxy] Unable to proxy method


ENVIRONMENT

Spring-MVC using Spring Security.


PROBLEM

Suddenlly, the compiler begins warning:

WARN [CglibAopProxy] (CglibAopProxy.java:...) - Unable to proxy method [public final void org.springframework.web.servlet.mvc.AbstractController.setSynchronizeOnSession(boolean)] because it is final: All calls to this method via a proxy will be routed directly to the proxy.

SOLUTION

First it was commented the annotation:
  @PreAuthorize("permitAll")
on the Controller class.

Recompiled and the warns disappeared.
So, the problem comes from the procedure triggered by this annotation.

To fix, it was taken off the following attribute from "security:global-method-security" element:
  proxy-target-class="true"
on the spring-security.xml configuration.



- spring-security.xml configuration setup:

BEFORE:
    <security:global-method-security pre-post-annotations="enabled" secured-annotations="enabled"
        jsr250-annotations="enabled" proxy-target-class="true">
    </security:global-method-security>
AFTER:
    <security:global-method-security pre-post-annotations="enabled" secured-annotations="enabled"
        jsr250-annotations="enabled" >
    </security:global-method-security>

COMMENT

The proxy-target-class attribute enabled (proxy-target-class="true") forces the use of CGLIB proxying (for example, to proxy every method defined for the target object, not just those implemented by its interfaces).
However, there are some issues to consider, like the final methods that cannot be advised, as they cannot be overriden.
See more at Spring AOP documentation .



FULL WARN MESSAGES:
  2014-05-28 14:18:26,148  WARN [CglibAopProxy] (CglibAopProxy.java:263) - Unable to proxy method [public final void org.springframework.web.servlet.mvc.AbstractController.setSynchronizeOnSession(boolean)] because it is final: All calls to this method via a proxy will be routed directly to the proxy.
  2014-05-28 14:18:26,150  WARN [CglibAopProxy] (CglibAopProxy.java:263) - Unable to proxy method [public final boolean org.springframework.web.servlet.mvc.AbstractController.isSynchronizeOnSession()] because it is final: All calls to this method via a proxy will be routed directly to the proxy.
  2014-05-28 14:18:26,150  WARN [CglibAopProxy] (CglibAopProxy.java:263) - Unable to proxy method [public final void org.springframework.web.servlet.support.WebContentGenerator.setSupportedMethods(java.lang.String[])] because it is final: All calls to this method via a proxy will be routed directly to the proxy.
  2014-05-28 14:18:26,151  WARN [CglibAopProxy] (CglibAopProxy.java:263) - Unable to proxy method [public final java.lang.String[] org.springframework.web.servlet.support.WebContentGenerator.getSupportedMethods()] because it is final: All calls to this method via a proxy will be routed directly to the proxy.
  2014-05-28 14:18:26,151  WARN [CglibAopProxy] (CglibAopProxy.java:263) - Unable to proxy method [public final void org.springframework.web.servlet.support.WebContentGenerator.setRequireSession(boolean)] because it is final: All calls to this method via a proxy will be routed directly to the proxy.
  2014-05-28 14:18:26,152  WARN [CglibAopProxy] (CglibAopProxy.java:263) - Unable to proxy method [public final boolean org.springframework.web.servlet.support.WebContentGenerator.isRequireSession()] because it is final: All calls to this method via a proxy will be routed directly to the proxy.
  2014-05-28 14:18:26,152  WARN [CglibAopProxy] (CglibAopProxy.java:263) - Unable to proxy method [public final void org.springframework.web.servlet.support.WebContentGenerator.setUseExpiresHeader(boolean)] because it is final: All calls to this method via a proxy will be routed directly to the proxy.
  2014-05-28 14:18:26,152  WARN [CglibAopProxy] (CglibAopProxy.java:263) - Unable to proxy method [public final boolean org.springframework.web.servlet.support.WebContentGenerator.isUseExpiresHeader()] because it is final: All calls to this method via a proxy will be routed directly to the proxy.
  2014-05-28 14:18:26,153  WARN [CglibAopProxy] (CglibAopProxy.java:263) - Unable to proxy method [public final void org.springframework.web.servlet.support.WebContentGenerator.setUseCacheControlHeader(boolean)] because it is final: All calls to this method via a proxy will be routed directly to the proxy.
  2014-05-28 14:18:26,153  WARN [CglibAopProxy] (CglibAopProxy.java:263) - Unable to proxy method [public final boolean org.springframework.web.servlet.support.WebContentGenerator.isUseCacheControlHeader()] because it is final: All calls to this method via a proxy will be routed directly to the proxy.
  2014-05-28 14:18:26,153  WARN [CglibAopProxy] (CglibAopProxy.java:263) - Unable to proxy method [public final void org.springframework.web.servlet.support.WebContentGenerator.setUseCacheControlNoStore(boolean)] because it is final: All calls to this method via a proxy will be routed directly to the proxy.
  2014-05-28 14:18:26,154  WARN [CglibAopProxy] (CglibAopProxy.java:263) - Unable to proxy method [public final boolean org.springframework.web.servlet.support.WebContentGenerator.isUseCacheControlNoStore()] because it is final: All calls to this method via a proxy will be routed directly to the proxy.
  2014-05-28 14:18:26,154  WARN [CglibAopProxy] (CglibAopProxy.java:263) - Unable to proxy method [public final void org.springframework.web.servlet.support.WebContentGenerator.setCacheSeconds(int)] because it is final: All calls to this method via a proxy will be routed directly to the proxy.
  2014-05-28 14:18:26,154  WARN [CglibAopProxy] (CglibAopProxy.java:263) - Unable to proxy method [public final int org.springframework.web.servlet.support.WebContentGenerator.getCacheSeconds()] because it is final: All calls to this method via a proxy will be routed directly to the proxy.
  2014-05-28 14:18:26,155  WARN [CglibAopProxy] (CglibAopProxy.java:263) - Unable to proxy method [public final void org.springframework.web.context.support.WebApplicationObjectSupport.setServletContext(javax.servlet.ServletContext)] because it is final: All calls to this method via a proxy will be routed directly to the proxy.
  2014-05-28 14:18:26,155  WARN [CglibAopProxy] (CglibAopProxy.java:263) - Unable to proxy method [public final void org.springframework.context.support.ApplicationObjectSupport.setApplicationContext(org.springframework.context.ApplicationContext) throws org.springframework.beans.BeansException] because it is final: All calls to this method via a proxy will be routed directly to the proxy.
  2014-05-28 14:18:26,155  WARN [CglibAopProxy] (CglibAopProxy.java:263) - Unable to proxy method [public final org.springframework.context.ApplicationContext org.springframework.context.support.ApplicationObjectSupport.getApplicationContext() throws java.lang.IllegalStateException] because it is final: All calls to this method via a proxy will be routed directly to the proxy.



Monday, April 14, 2014

spring "java.lang.ClassNotFoundException: org.springframework.web.servlet.DispatcherServlet"


Problem
Running the application using eclipse's server you get the following exception:

 spring java.lang.ClassNotFoundException: org.springframework.web.servlet.DispatcherServlet  

Solution

Check if you have the spring-mvc jar in the project's classpath.
If using maven, you must have something like this in your pom.xml:

<!-- Spring 3 MVC depends on spring-core, spring-beans, spring-context, spring-web -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${spring.version}</version>

</dependency>

If you respective reference is verified and correct, just remove the project from your server.
Perform a project clean, building everything from scratch.
Deploy the project again.

Sometimes, the eclipse's server may fail requiring a new deploy.




Tuesday, March 4, 2014

Jboss-characters' and URLs strange behavior



>PROBLEM

Jboss-characters' and URLs strange behavior, compromising navigation.



>SOLUTION

Set the proper encoding.
Edit the file:
  $JBOSS_INTALL_DIR/standalone/configuration/standalone.xml

If using UTF-8, insert the following after  </extensions> tag:

    <system-properties>
        <property name="org.apache.catalina.connector.URI_ENCODING" value="UTF-8"/>
        <property name="org.apache.catalina.connector.USE_BODY_ENCODING_FOR_QUERY_STRING" value="true"/>
    </system-properties>



>ENV
JBoss server

Eclipse using AspectJ Plugin



If  you are using Eclipse with aspectJ plugin, you may get this exception below, because it is necessary to convert the project before running it.
See details below.


PROBLEM

Exception thrown:


SEVERE: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'logAspecto' defined in ServletContext resource
[/WEB-INF/applicationContext.xml]: No matching factory method found: factory method 'aspectOf()'. 

Check that a method with the specified name exists and that it is static.
    at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:528)


SOLUTION


After AspectJ plugin installation it is necessary to convert the project.
Right click the project > configure > convert to aspect project


 
INTALLING AspectJ plugin in Kepler

To install aspectJ plugin in Eclipse Kepler, go to menu, help, Install new software.
Point to http://download.eclipse.org/tools/ajdt/43/update .
Wait a minute to update, check all then install.


Monday, December 2, 2013

python import from another dir (another package, no the current)


Usually an import from another source under the same package is straight.
All you have to do is to declare import for the source, but if the source is outside, another directory, you have two alternatives: use sys.path or PYTHONPATH envvar.

To use PYTHONPATH envvar you just append to it the new path that contains the source to be used by the import statement.


Using sys.path

Supposing the scenario below, follow by the example.



 
- The D:\work\devcli\python\Sandbox\examples\modules\testB\modTest3.py file, contains:

def printTest3():
    print('test3')

   
- The D:\work\devcli\python\Sandbox\examples\modules\testA\modTest2.py, contains:
def printTest2():
    print('test2')

   
- The D:\work\devcli\python\Sandbox\examples\modules\testA\modTest1.py, contains:
def printTest1():
    print('test1')
   
import sys, modTest2 
# using absolute path
#sys.path.append('D:/work/devcli/python/Sandbox/examples/modules/testB')
# or using relative path
sys.path.append('../testB')
import modTest3

def printTest1():
    print('test1')

printTest1()
modTest2.printTest2()
modTest3.printTest3()



- Running, the example you get:

test1
test2
test3


 |

Thursday, November 28, 2013

linux debian - logging as another user throws "Module is unknown"



>Environment
Debian 7 - amd64.



>Problem:
Attempt to login as another user throws the following error message:
  Module is unknown


 >Solution
 


Three possibilities:
- pam configuration
- pam module not installed
- pam module corrupted

Try to fix the most simple first: pam configuration, then follow the order suggested.





1. PAM CONFIGURATION:

- As root, edit the file:
su
scite /etc/pam.d/login &

- Comment the following line
session    required   pam_limits.so
- becomes:
#session    required   pam_limits.so

If you have a local oracle instance, for testing purpose and security is not a issue, comment also the lines below if you have oracle's concerned issues:


#oracle 11g install from rin201
session required /lib/security/pam_limits.so       
session required pam_limits.so

- becoming:
#oracle 11g install from rin201
#session required /lib/security/pam_limits.so       
#session required pam_limits.so

- Try again to log as another user, for instance:

  sudo login postgres

- If it fails, check pam installation.



2. INSTALLING PAM MODULES

NOTE: if you're not sure if pam is installed, you can install it.
There is no problem since if it is already installed, the apt-get will return a message telling you so.


- check the package name
dpkg --search pam

- install the following:
apt-get install libpam-modules
apt-get install libpam-runtime


3. TO REINSTALL PAM




aptitude reinstall libpam-modules



SEE ALSO:
http://www.linuxquestions.org/questions/linux-general-1/failing-at-chroot-101-a-758547/#post3705048

Sunday, November 10, 2013

struts maven project fails to start with eclipse's embedded tomcat server


Scenario:

Using eclipse's embedded tomcat server to deploy a struts project:




Result: it fails to start.



Solution

Supposing that server's configuration is correct(addres, port, etc), check the war plugin configuration in the pom.xml file.


The current value:

<plugin>
  <artifactId>maven-war-plugin</artifactId>
  <version>2.3</version>
  <configuration>
    <warSourceDirectory>WebContent</warSourceDirectory>
    <failOnMissingWebXml>false</failOnMissingWebXml>
  </configuration>
</plugin>

During a copy/paste from another project, the proper value was not set.

Switch to :

<plugin>
  <artifactId>maven-war-plugin</artifactId>
  <version>2.3</version>
  <configuration>
    <warSourceDirectory>src/main/webapp</warSourceDirectory>
    <failOnMissingWebXml>false</failOnMissingWebXml>
  </configuration>
</plugin>



 



Result : problem fixed.





Monday, November 4, 2013

Maven jar plugin missing resource




>Problem

Eclipse points parsing error on "<packaging>jar</packaging>" tag.

The error message:

Execution default-resources of goal org.apache.maven.plugins:maven-resources-plugin:2.5:resources failed:
    A required class was missing while executing org.apache.maven.plugins:maven-resources-plugin:2.5:resources:
    org/codehaus/plexus/util/io/FileInputStreamFacade







>Solution

1. Update the libraries used by the jar plugin and add common-io jar.

- Before:

        <dependency>
            <!--used by jar plugin -->
            <groupId>commons-lang</groupId>
            <artifactId>commons-lang</artifactId>
            <version>2.1</version>
        </dependency>

        <dependency>
            <!--used by jar plugin -->
            <groupId>org.codehaus.plexus</groupId>
            <artifactId>plexus-utils</artifactId>
            <version>1.1</version>
        </dependency>




- After:

        <dependency>
            <!--used by jar plugin -->
            <groupId>commons-lang</groupId>
            <artifactId>commons-lang</artifactId>
            <version>2.6</version>
        </dependency>
      
        <dependency>
            <!--used by jar plugin -->
            <groupId>org.codehaus.plexus</groupId>
            <artifactId>plexus-utils</artifactId>
            <version>3.0.15</version>
        </dependency>

        <dependency>
            <!--used by jar plugin -->
            <groupId>commons-io</groupId>
            <artifactId>commons-io</artifactId>
            <version>2.4</version>
        </dependency>


2. Finally, update the project, run:

mvn install
                      





Wednesday, September 18, 2013

maven/eclipse message: No marketplace entries found to handle maven-compiler-plugin:2.3.1:compile in Eclipse


If eclipse throws a message like this:

No marketplace entries found to handle maven-compiler-plugin:2.3.1:compile in Eclipse

Check your maven configuration.
Go to menu, windows, preferences, type "maven" in the filter box, select "User Setttings".
Set your local repository references.

For example:





Wednesday, September 11, 2013

linux debian startup: warn pulseaudio configured per session



PROBLEM

When starting debian  or a debian based distribution, you may get a warn message during startup, something like this:
[WARN] pulseaudio configured per session ...


NOT A REAL SOLUTION

Searching for a solution, you'll get many posts resolving this issuing by switching the following parameter
PULSEAUDIO_SYSTEM_START=0
to
PULSEAUDIO_SYSTEM_START=1

According to the pulse audio documentation, "system" mode shall be avoided for the general use.
See http://www.freedesktop.org/wiki/Software/PulseAudio/Documentation/User/WhatIsWrongWithSystemWide/


SOLUTION

I agree with Paul, about his comment at
http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=644809

http://www.freedesktop.org/wiki/Software/PulseAudio/Documentation/User/FirstSteps/


It makes no much sense in terms os usability such warning.
The configuration for the general use should come out of the box, like the most applications do.
That way, after reading the documentations at:
http://www.freedesktop.org/wiki/Software/PulseAudio/Documentation/User/FirstSteps/
and
http://mpd.wikia.com/wiki/PulseAudio
I checked the configuration file at /etc/pulse/client.conf  to make sure that everything is like it should.

Then, I've decided that this warning should be commented, since the my configuration was correct.
I edited the /etc/init.d/pulseaudio file and commented the lines as shown below:

test -f /etc/default/pulseaudio && . /etc/default/pulseaudio
#if [ "$PULSEAUDIO_SYSTEM_START" != "1" ]; then
#    log_warning_msg "PulseAudio configured for per-user sessions"
#    exit 0
#fi


Problem gone.
Unless there is something more to get it from it, let me know.
That's it.

Monday, August 5, 2013

java.lang.SecurityException: ... signer information does not match signer information of other classes in the same package exception


The exception gotten using Maven and jMock:

java.lang.SecurityException: class "org.hamcrest.TypeSafeMatcher"'s signer information does not match signer information of other classes in the same package
  at java.lang.ClassLoader.checkCerts(Unknown Source)
  ...


Sulution at:  java.lang.noclassdeffounderror using maven, jmock






java.lang.NoClassDefFoundError: org/hamcrest/TypeSafeMatcher exception using maven and jmock



Running Ctrl+F11 on the test class to issue JUnit test, you get:

java.lang.NoClassDefFoundError: org/hamcrest/TypeSafeMatcher
  at java.lang.ClassLoader.defineClass1(Native Method)
  ...






This exception may be thrown when running the JUnit test using eclipse (Ctrl+F11 having the test class active).
More than just one cause is possible.

Here, I'm gonna show a consistent debug use case to discover and solve the problems, step by step.

First step is to make sure if the application has a successful build, because sometimes you get it although not having a successful result in the JUnit test via eclipse (below you'll see).

The "build" may be issued using:

- the prompt ("mvn build", "mvn install" or "mvn install -U"), under the PROJECT_ROOT.
or
- eclipse: Ctrl+F11 on the pom.xml file to run "mvn install" command.


Using eclipse:





This test also fails:

Tests in error: 
  testSayGreeting(br.com.adr.rin157.GreetingTest): org/hamcrest/TypeSafeMatcher
  testJmock(br.com.adr.rin160.TestClass3): org/jmock/internal/matcher/MethodMatcher





Then, let's fix the build first, and after we check the JUnit test - it is a two-phase checking.

Reading the exception thrown, the problem is about the "hamcrest" library.
Let's check all the "hamcrest" dependencies, removing all them.
Then check which one is really necessary.

This is simple, a necessary library causes messages of unknown classes by the eclipse's on-the-fly compiler.
Let just the necessary libraries, and try switching the alternatives, adding and testing each one, one by its turn.
When the on-the-fly compilation runs without errors or messages, the new configuration is set correctly.

In this example, it was the hamcrast's source declaration which was causing the problem.
After the test described above, the conflicting dependency was found and removed, shown below.

  <dependency>
    <groupId>hamcrest_260_local</groupId>
    <artifactId> core</artifactId>
    <version> sources</version>
    <type>jar</type>
  </dependency>





After that, a new final "mvn install test" to confirm, which shall be successful:






I got some information on the Internet that the order of the dependencies could be the cause of the problem.
You may also test it.
In this example, the tests demonstrated that the order was irrelevant.
Check the following two pictures below.








After a successful build, the JUnit test is checked again, issuing the command referred above.
Unfortunately, there is yet another issue to solve.
The exception returned is:

java.lang.SecurityException: class "org.hamcrest.TypeSafeMatcher"'s signer information does not match signer information of other classes in the same package
  at java.lang.ClassLoader.checkCerts(Unknown Source)
  ...



The trick for the solution is inside is the "Run configurations..." setting.
Go to:






The wrong configuration - classpath after project:






The right configuration - classpath before project:






To set the right configuration, inverting project vs. classpath order, do:

1. Select the project entry and click the "Remove" button.
2. select "User entries", then "Add Projects"


Follow by blue highlighted buttons in the picture:











Then run:
























That's it. : )


NOTES

You can check by your own -  the code is here .

The test was created as follows:

1. Eclipse Juno, but any version fits.

2. The code used here you find at http://www.askeygeek.com/jmock-for-beginners/

3. The library is jmock-2.6.0 downloaded from the jMock site and installed at a local maven repository.

Alternatively, you may use the following dependencies from Maven Repository, or use the pom.xml file inside the code :

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.9</version>
<scope>test</scope>
</dependency>

<!--jMock 2 Core -->
<dependency>
<groupId>org.jmock</groupId>
<artifactId>jmock</artifactId>
<version>2.6.0</version>
</dependency>

<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-all</artifactId>
<version>1.3</version>
</dependency>

<dependency>
<groupId>org.beanshell</groupId>
<artifactId>bsh-core</artifactId>
<version>2.0b4</version>
</dependency>

<dependency>
<groupId>org.objenesis</groupId>
<artifactId>objenesis</artifactId>
<version>1.0</version>
</dependency>

<dependency>
<groupId>cglib</groupId>
<artifactId>cglib</artifactId>
<version>3.0</version>
</dependency>

<dependency>
<groupId>org.jmock</groupId>
<artifactId>jmock-junit3</artifactId>
<version>2.6.0</version>
</dependency>

<dependency>
<groupId>org.jmock</groupId>
<artifactId>jmock-junit4</artifactId>
<version>2.6.0</version>
</dependency>

<dependency>
<groupId>org.jmock</groupId>
<artifactId>jmock-script</artifactId>
<version>2.6.0</version>
</dependency>

<dependency>
<groupId>org.jmock</groupId>
<artifactId>jmock-legacy</artifactId>
<version>2.6.0</version>
</dependency>






Monday, July 29, 2013

Maven vs. Eclipse: An internal error occurred during: "Importing Maven projects". Unsupported IClasspathEntry kind=4


I had this kind of problem twice while trying to import a Maven project using Eclipse.
One using mvn command and the other using the option File, Import, Existent Maven Projects.
Check which one is your's.
Usually this kind of problem happens due to unicode issues.


1.  USING File, Import, Existent Maven Projects


>PROBLEM

You the get the warning when trying to import the maven project.



 >SOLUTION

 Delete the folder and files shown on the picture below and import the project again.








2.  USING mvn COMMAND

Problem

Importing by Eclipse a project created using maven commands, as follows:
mvn archetype:generate
...
cd project_root
mvn eclipse:eclpse

generates the message above.

Follow the details by the pictures below.

Solution

Use just the "mvn archetype:generate" command and then go straight to the Eclipse's import, without using "mvn eclipse:eclipse".



Step by Step the Import Failure 







Sunday, July 28, 2013

openJPA, Eclipse: ... an api incompatibility was encountered while executing org.codehaus.mojo:openjpa-maven-plugin ..



Problem

The openJPA's enhancer plugin throws an error message:

... an api incompatibility was encountered while executing org.codehaus.mojo:openjpa-maven-plugin ..

For instance:

Description Resource Path Location Type
Execution enhancer of goal org.codehaus.mojo:openjpa-maven-plugin:1.2:enhance failed: An API incompatibility was encountered while executing 
org.codehaus.mojo:openjpa-maven-plugin:1.2:enhance: java.lang.VerifyError: Expecting a stackmap frame at branch target 36 in method 
br.com.adr.simplest.entities.Category.<clinit()V at offset 27
...


The enhancer execution from "openjpa-maven-plugin" of "org.codehaus.mojo" is declared in pom.xml file at:

<groupIdorg.codehaus.mojo</groupId
<artifactIdopenjpa-maven-plugin</artifactId
...
<executions
<execution
<idenhancer</id


On eclipse, you can see on "Markers" panel:




Solution

It's due libraries's incompatibilities.
In this case, the openjpa version is not compatible with the java's version used by the compiler, defined at "maven-compiler-plugin".
Follow by the example below, in order to fix the problem.

Before
...
<dependency
<groupIdorg.apache.openjpa</groupId
<artifactIdopenjpa-all</artifactId
<version2.1.1</version
</dependency
...
<plugin
<groupIdorg.apache.maven.plugins</groupId
<artifactIdmaven-compiler-plugin</artifactId
<version2.3.2</version
<configuration
<source1.6</source
<target1.6</target
</configuration
</plugin
...
<plugin
<groupIdorg.codehaus.mojo</groupId
<artifactIdopenjpa-maven-plugin</artifactId
<version1.2</version
<configuration
<includesbr/com/adr/*/entities/*/*.class</includes
<includesbr/com/adr/*/entities/*.class</includes
<addDefaultConstructortrue</addDefaultConstructor
<enforcePropertyRestrictionstrue</enforcePropertyRestrictions
</configuration
<executions
<execution
<idenhancer</id
<phaseprocess-classes</phase
<goals
<goaltest-enhance</goal
<goalenhance</goal
</goals
</execution
</executions
<dependencies
<dependency
<groupIdorg.apache.openjpa</groupId
<artifactIdopenjpa</artifactId
<!-- set the version to be the same as the level in your runtime --
<version2.1.1</version
</dependency
</dependencies
</plugin
...


-----------------------------------------------------------------------

After:
...
<dependency
<groupIdorg.apache.openjpa</groupId
<artifactIdopenjpa-all</artifactId
<version2.2.2</version
</dependency
...
<plugin
<groupIdorg.apache.maven.plugins</groupId
<artifactIdmaven-compiler-plugin</artifactId
<version3.1</version
<configuration
<source1.7</source
<target1.7</target
</configuration
</plugin
...

<plugin
<groupIdorg.codehaus.mojo</groupId
<artifactIdopenjpa-maven-plugin</artifactId
<version1.2</version
<configuration
<includesbr/com/adr/*/entities/*/*.class</includes
<includesbr/com/adr/*/entities/*.class</includes
<addDefaultConstructortrue</addDefaultConstructor
<enforcePropertyRestrictionstrue</enforcePropertyRestrictions
</configuration
<executions
<execution
<idenhancer</id
<phaseprocess-classes</phase
<goals
<goaltest-enhance</goal
<goalenhance</goal
</goals
</execution
</executions
<dependencies
<dependency
<groupIdorg.apache.openjpa</groupId
<artifactIdopenjpa</artifactId
<!-- set the version to be the same as the level in your runtime --
<version2.2.2</version
</dependency
</dependencies
</plugin
..





-----------------------------------------------------

NOTE:

Use properties to reference the versions.
They make things easier.
For instance:

    <properties
    <openjpa.version2.2.2</openjpa.version
    </properties
    ...
    <dependency
    <groupIdorg.apache.openjpa</groupId
    <artifactIdopenjpa-all</artifactId
    <version${openjpa.version}</version
    </dependency

    ...
    <!--
    The enhancer pluging:
    -->
    ...

<executions
<execution
<idenhancer</id
<phaseprocess-classes</phase
<goals
<goaltest-enhance</goal
<goalenhance</goal
</goals
</execution
</executions
<dependencies
<dependency
<groupIdorg.apache.openjpa</groupId
<artifactIdopenjpa</artifactId
<!-- set the version to be the same as the level in your runtime --
<version${openjpa.version}</version
</dependency
</dependencies

exception in thread main java.lang.classformaterror: absent code attribute in method that is not native or abstract in class file javax/persistence/persistence


Problem

Maven project to run JPA stuff, using:

<dependency>
   <groupId>javax</groupId>
   <artifactId>javaee-api</artifactId>
   <version>6.0</version>
</dependency>


 Or:

<dependency>
   <groupId>javax</groupId>
   <artifactId>javaee-web-api</artifactId>
   <version>6.0</version>
</dependency>



Causes the following exception:

  Exception in thread "main" java.lang.ClassFormatError: Absent Code attribute in method that is not native or abstract in class file javax/persistence/Persistence


Solution

Use an implementation jar, because the jars above are just compilation jars.
Instead see example below.

Why?

 This dependency provides you with the Java EE APIs, not the implementations.
 While this dependency works for compiling, it cannot be used for executing code (that includes tests).

See more at:
https://community.jboss.org/wiki/WhatsTheCauseOfThisExceptionJavalangClassFormatErrorAbsentCode


Example


HSQLDB: org.apache.openjpa.persistence.PersistenceException: There were errors initializing your configuration: java.lang.NoSuchMethodError: org.hsqldb.DatabaseURL.parseURL(Ljava/lang/String;ZZ)Lorg/hsqldb/persist/HsqlProperties;



Problem

Running HSQLDB and openJPA (or whatever JPA implementation) you get the following message:

- short message:
org.apache.openjpa.persistence.PersistenceException: There were errors initializing your configuration: java.lang.NoSuchMethodError: org.hsqldb.DatabaseURL.parseURL(Ljava/lang/String;ZZ)Lorg/hsqldb/persist/HsqlProperties;

- full message:
<openjpa-2.1.1-r422266:1148538 nonfatal general error org.apache.openjpa.persistence.PersistenceException: There were errors initializing your
configuration: java.lang.NoSuchMethodError: org.hsqldb.DatabaseURL.parseURL(Ljava/lang/String;ZZ)Lorg/hsqldb/persist/HsqlProperties;



Solution

The HSQLDB's url must be fixed.
Go to persistence.xml or whatever, and check it.
The org.hsqldb.DatabaseURL.parseURL() method rejected it.
In the code of org.hsqldb.DatabaseURL class, you get some examples of HSQLDB's urls:

parseURL:
JDBC:hsqldb:hsql://myhost:1777/mydb;filepath=c:/myfile/database/db",true);
parseURL("JDBC:hsqldb:../data/mydb.db", true);
parseURL("JDBC:hsqldb:../data/mydb.db;ifexists=true", true);
parseURL("JDBC:hsqldb:HSQL://localhost:9000/mydb", true);
parseURL(JDBC:hsqldb:Http://localhost:8080/servlet/org.hsqldb.Servlet/mydb;ifexists=true",true);
parseURL("JDBC:hsqldb:Http://localhost/servlet/org.hsqldb.Servlet/",true);
parseURL("JDBC:hsqldb:hsql://myhost", true);

eclipse: java: SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder" or Exception in thread "main" java.lang.NoClassDefFoundError: org/slf4j/impl/StaticLoggerBinder

  >PROBLEM Using Eclipse, you try to run a simple logging test using "org.slf4j.Logger" like the sample below: package Test; im...