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);

HSQLDB, openJPA, org.apache.openjpa.persistence.PersistenceException: There were errors initializing your configuration ... A connection could not be obtained for driver class "org.hsqldb.jdbcDriver" and URL ...




Problem

Running HSQLDB and openJPA, the program throws the following message:

- short message:
org.apache.openjpa.persistence.PersistenceException: There were errors initializing your configuration ... A connection could not be obtained for driver class "org.hsqldb.jdbcDriver" and URL ...

- full message:
org.apache.openjpa.persistence.PersistenceException: There were errors initializing your
configuration: org.apache.openjpa.util.UserException: A connection could not be obtained for driver
class "org.hsqldb.jdbcDriver" and URL "jdbc:hsqldb:HSQL://localhost:9001/testone".
You may have specified an invalid URL.


Solution

Check you database log, for instance you get a message like this:
[Server@7e5e5f92]: [Thread[HSQLDB Connection @519f8603,5,HSQLDB Connections @7e5e5f92]]: database alias=testone does not exist

So, create the database on HSQLDB.

HSQLDB, openJPA, .. nonfatal general error ... org.apache.openjpa.persistence.PersistenceException: invalid schema name



Problem

- short message:
nonfatal general error ... org.apache.openjpa.persistence.PersistenceException: invalid schema name

- full message:
[CREATE TABLE testone.eshop_categories (category_id BIGINT NOT NULL, category_name VARCHAR(70), PRIMARY KEY (category_id))] {stmnt 1548490201 CREATE
TABLE testone.eshop_categories (category_id BIGINT NOT NULL, category_name VARCHAR(70), PRIMARY KEY (category_id))} [code=-4850, state=3F000]



Solution

Depending on the database and how you access it, for instance HSQLDB, the schema shall not be declared.
For instance, change:

@Entity
@Table(name="eshop_categories", schema="testone")
public class Category {

To

@Entity
@Table(name="eshop_categories")
public class Category {

Thursday, July 25, 2013

maven and log4j - log4j:WARN No appenders could be found for logger


Problem

When running a test you get the following warning message:

log4j:WARN No appenders could be found for logger (org.jboss.logging).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.



Solution

To get rid of that warning message,  just set log4's configuration file under the right folder.
Example:






An example of log4.xml configuration file:

<?xml version="1.0" encoding="UTF-8" ?>
<!-- <!DOCTYPE log4j:configuration SYSTEM "log4j.dtd"> -->
<!DOCTYPE log4j:configuration PUBLIC "-//APACHE//DTD LOG4J 1.2//EN" "http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/xml/doc-files/log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">

    <appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender">
        <layout class="org.apache.log4j.PatternLayout">
            <param name="ConversionPattern"
                value="[temp01] %p [%t] %c{1}.%M(%L) | %m%n"/>
        </layout>
    </appender>

    <logger name="net.sf.ehcache">
        <level value="ERROR"/>
    </logger>

    <!-- Suppress success logging from InteractiveAuthenticationSuccessEvent -->
    <logger name="org.acegisecurity">
        <level value="ERROR"/>
    </logger>

    <logger name="org.apache">
        <level value="WARN"/>
    </logger>

    <logger name="org.hibernate">
        <level value="WARN"/>
    </logger>
 
    <!--logger name="org.hibernate.SQL">
        <level value="DEBUG"/>
    </logger-->

    <logger name="org.springframework">
        <level value="WARN"/>
    </logger>

    <!-- Suppress warnings from Commons Validator -->
    <logger name="org.apache.commons.validator.ValidatorResources">
        <level value="ERROR"/>
    </logger>

    <logger name="org.appfuse">
        <level value="INFO"/>
    </logger>
   
    <logger name="br.com.adr">
        <level value="DEBUG"/>
    </logger>

    <root>
        <level value="WARN"/>
        <appender-ref ref="CONSOLE"/>
    </root>

</log4j:configuration>




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

 An example of WRONG place:





---------------------------------------------------------------------------------------------------
EXTRA


Why do I see a warning about "No appenders found for logger" and "Please configure log4j properly"? 
This occurs when the default configuration files log4j.properties and log4j.xml can not be found and the application performs no explicit
configuration.
log4j uses Thread.getContextClassLoader().getResource() to locate the default configuration files and does not directly check the file system.
Knowing the appropriate location to place log4j.properties or log4j.xml requires understanding the search strategy of the class loader in use.
log4j does not provide a default configuration since output to the console or to the file system may be prohibited in some environments.
Also see FAQ: Why can't log4j find my properties in a J2EE or WAR application?.

Why can't log4j find my properties file in a J2EE or WAR application?

The short answer: the log4j classes and the properties file are not within the scope of the same classloader.
The long answer (and what to do about it): J2EE or Servlet containers utilize Java's class loading system.
Sun changed the way classloading works with the release of Java 2.
In Java 2, classloaders are arranged in a hierarchial parent-child relationship.
When a child classloader needs to find a class or a resource, it first delegates the request to the parent.
Log4j only uses the default Class.forName() mechanism for loading classes.
Resources are handled similarly.
See the documentation for java.lang.ClassLoader for more details.
So, if you're having problems, try loading the class or resource yourself.
If you can't find it, neither will log4j.


FROM:

http://logging.apache.org/log4j/1.2/faq.html



Wednesday, July 24, 2013

maven exception: Unsupported major.minor version 51.0



Problem

Tests fail.

Example:

mvn install
or
mvn install -U

Causes:

Caused by: java.lang.UnsupportedClassVersionError: br/com/adr/AppTest : Unsupported major.minor version 51.0






Solution

Check the project's java version and plugins, setting the compatible version in pom.xml file.
Follow by the example below.

--------------------------
Before:

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>


--------------------------
After:

<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<jvm>${env.JAVA_HOME7}/bin/java</jvm>
<!-- <jvm>D:/portables_d/jdk-7u25-windows-x64/bin/java</jvm> -->
</configuration>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>


Now, tests section is working.




Additional Tips

Suppose that jvm element is not correctly configured. For instance, using an absolute path, the "java" was missed:

      <jvm>D:/portables_d/jdk-7u25-windows-x64/bin</jvm>

So, the plugin can not find the path, and it throws a message like this:

'D:\portables_d\jdk-7u25-windows-x64\bin' is not recognized as an internal or external command, an operable program or a batch file.



Or like this:

           The system could not find the specified path.



More at:

http://sampreshan.svashishtha.com/2012/04/01/quicktip-maven-surefire-plugin-unsupported-major-minor-version-51-0/

https://coderwall.com/p/y8yg8w


Tuesday, July 23, 2013

Failed while installing JPA 2.0. org.osgi.service.prefs.BackingStoreException: Resource ... /.settings' does not exist.



The "eclipse-jee-juno-SR1-win32-x86_64" installation was generating the following error message:

Failed while installing JPA 2.0. org.osgi.service.prefs.BackingStoreException: Resource ...
'$RELATIVE_PROJECT_PATH/.settings' does not exist.








This error may have many causes.
Here I gonna show two methods to fix it, and certainly there are many others.

All eclipse configuration is saved under "$WORKSPACE/.metadata" and "$ECLIPSE_INSTALL " folders.

The error may be caused by:


- Plugins incompatibilities,
   or
- Some configuration that became corrupted.


Fixing Plugins incompatibilities



It was installed the following plugins from marketplace - follow by the pictures.



                  Maven Integration for Eclipse WTP (Juno)
  


                  and JBoss Tools:









Inspecting the installation details (menu, help, About Eclipse, Installation Details), I noticed that JBoss also installed maven stuff, and probably would be conflicting with WTP's installation.





The solution was to uninstall one of them.
So, I've decided to uninstall "Maven WTP".
Pressing the button unistall, the procedure begins...






Restarted Eclipse, the problem was gone.



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







Fixing configuration that became corrupted

In this case, you may try to reinstall the plugin.
Uninstall it and install again.

I also got an alternative solution using the workaround described as follows.

Trying to fix the problem, I extracted a new virgin installation and installed just "Maven Integration for Eclipse (Juno and newer)" from marketplace (menu, help, Eclipse Marketplace).

Then I started it using the same workspace when I got the problem.
After, I imported the project which had thrown the error message, but this time the import was successful.
The new installation was closed.

I returned to the previous installation,  where I was getting the JPA error messages,  restarting it, using always the same workspace.
The problem had gone.

So, the new installation had overwritten some improper configuration under $WORKSPACE_PATH/.metadata folder.
Remember that eclipse configuration is saved there.

I always keep a backup file of workspace's .metadata folder.For each expressive change, a new backup is done.
In this case, I had not generated a backup yet since it was the first installation in progress and test.

When a backup is not available, or the old one has problems, it is possible to generate a new workspace from scratch. Go to menu, file, switch workspace and set a new path, of course different from the prior one and press enter to proceed.
The Eclipse is restarted with a new configuration. The old one is gone.

This alternative is useful when it is ineffective an attempt using the usual procedures through the project's properties. When metadata is defective, it usually rejects the configuration adjusted or it causes some malfunction.


Saturday, July 20, 2013

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



Problem
After using the command mvn eclipse:eclipse, the project is imported by Eclipse using the "Existing Maven Projects", which throws the error message:
An internal error occurred during: Importing Maven projects. Unsupported IClasspathEntry kind=4

Solution
Do not use the "mvn eclipse:eclipse" command.
Do a straight import by Eclipse using the "Existing Maven Projects".
An incompatibility is commented here.

TIP
About compatibilities between command line vs. Eclipse's maven plugin, when the "Run Maven Build" option (Shift+Alt+X M) doesn't work properly, use the command line as follows:

cd project_root (where pom.xml is)
mvn install -U

Return to Eclipse and refresh the project (F5 over project).

Wednesday, July 10, 2013

OpenOffice - Importing from text files



To opens a dialog for import setup, there are at least two options:

1. Simple Copy/Paste

Copy the text using Ctrl+C and paste it using Ctrl+V.

or

2. Using a file having a .csv extension.

Rename the original file (or copy it), adding a .csv  extension.
For instance, if you have a file using .diff extension (myfile.diff), without the .cvs suffix, OpenOffice doesn't recognize it as an import, and it doesn't open the import dialog.
This is the trick and certainly there are other extensions that may be used instead .cvs. Test it, renaming the file with another extension and repeating the procedure. If the dialog is opened, that extension is another alternative.

*** NOTE:
Use the F1 to find out other informations about. The help is good.

Saturday, July 6, 2013

Windows 7 slow startup - very long boot



There are two basic stages when a computer starts using Windows.

The first one is the BIOS setup, which shows a screen defined by the BIOS vendor.

The second, and the last, is the Windows startup screen.

The Windows screen has the Windows' logo and the "Windows starting" message.
So, again, the screen that comes before this screen is the BIOS setup.

If your machine freezes on the first screen, the BIOS screen, your problem is about the BIOS boot.
Sometimes, if you reset the BIOS to the default values may solve.
Do not forget to take note of your current values before changing them.
Other times may require other procedures.

This post is about the second screen, when the computer freezes during Windows startup.

Keep in mind that many reasons may lead to this problem, for instance, hardware malfunction.

A simple hardware check may be done using a live CD of another operating system (O.S.), for instance Ubuntu.
You don't have to install the other O.S., since a live CD runs the new O.S. from the CD itself.
That way, if you may run the new O.S. from the live CD as usual, accessing all drives and etc., probably your hardware is working properly.

So, supposing that hardware is Ok, we shall test if Windows is not running chckdsk without previous notice.
This is a bug, which requires a hot fix.

Note: "chckdsk is a check disk utility, a windows native program used for maintenance.



But how can you fix something without having access?
Remember, you do have access, but it takes a long time.

Two choices:
1. wait for the long startup to enable you access and then apply the hot fix, or
2. try to reboot the computer to execute the chckdsk command manually and restart the computer again.

I prefer the first one, because the second may not solve the problem for sure.
If you're a luck guy which have a small problem, it may work.
After all, any choice is a matter of time... : (

To apply the hot fix, go to Microsoft's page at http://support.microsoft.com/kb/975778 and follow the directions, or manually run chckdsk (summary bellow).

CHKDSK /F at Startup

1.Reboot your computer.
2.Press the "F8" key and hold it as the computer boots up.
3. Choose "Safe Mode with Command Prompt" by moving the up and down arrows to highlight the option and pressing "Enter."
4. Type "Chkdsk /f" at the command prompt and press "Enter."

More details at:
http://www.ehow.com/how_6905134_perform-chkdsk-_f-startup.html

http://searchenterprisedesktop.techtarget.com/tip/How-to-run-the-chkdsk-utility-in-Windows-7



Note:

Google search or other search machine returns for searching strings like "windows 7 slow boot/startup" many results pointing to fake solutions that lead us to unreliable sites registered on "virus lists".
I've discovered the problem by myself, and after that I've switched the searching string to "windows 7 starts checkdisk silently", when eventually I've found the Microsoft's page.

How did I discover that?
After I've formatted the boot and system partitions.
After reinstalling windows again, the checdsk tool came back as usual, but the data partitions marked to be checked were still there active, but at this time the operations were shown ostensibly.


The detail is that formatting partitions are not a problem at all if you have at least two things:

1. backup (partition images) which enables to restore the full system in short time.

2. system and data have their own different partitions. One for system, different the other for data.

Good luck!  : )

Friday, July 5, 2013

MySQL - ERROR 1005 (HY000): Can't create table './MyDB/#sql-e4a_c715.frm' (errno: 121)


The following statement

ALTER TABLE testone.lgn_permission ADD CONSTRAINT fk_lgn_permission_r FOREIGN KEY ( role_fk ) REFERENCES testone.lgn_role( id ) ON DELETE NO ACTION ON UPDATE NO ACTION;

was causing this error:

ERROR 1005 (HY000): Can't create table './MyDB/#sql-e4a_c715.frm' (errno: 121)


Below, it's shown part of the script responsible for the error:


CREATE TABLE testone.lgn_role (
    id                   BIGINT  NOT NULL  AUTO_INCREMENT,
    title                VARCHAR(100)  NOT NULL  ,
    code                 INT UNSIGNED NOT NULL  ,
    profile_fk           BIGINT    ,
    CONSTRAINT pk_lgn_role PRIMARY KEY ( id )
 );

CREATE INDEX idx_lgn_role ON testone.lgn_role ( profile_fk );

CREATE TABLE testone.lgn_permission (
    role_fk              BIGINT  NOT NULL  ,
    login_fk             BIGINT  NOT NULL  ,
    resource_fk          BIGINT  NOT NULL 
    -- CONSTRAINT pk_lgn_permission UNIQUE ( login_fk, role_fk )
 ) ENGINE=InnoDB ;

ALTER TABLE testone.lgn_permission ADD CONSTRAINT fk_lgn_permission_role FOREIGN KEY ( role_fk ) REFERENCES testone.lgn_role( id ) ON DELETE NO ACTION ON UPDATE NO ACTION;

ALTER TABLE testone.lgn_permission ADD CONSTRAINT fk_lgn_permission_login FOREIGN KEY ( login_fk ) REFERENCES testone.lgn_login( id ) ON DELETE NO ACTION ON UPDATE NO ACTION;

Solution

One table was declared as InnoDB, the other not.


CREATE TABLE testone.lgn_role (
...
);


CREATE TABLE testone.lgn_permission (
...
 ) ENGINE=InnoDB ;


Note:

Every time you get such error (1005), check your table declarations.
Something wrong you'll certainly find there.
May be difficult because if the database has a huge script there will be much stuff to be checked.

A good strategy is to create a check list.
For instance:
1. Check all table constraints first.
2. Check key types, if they all have the appropriate type.
etc.

 There are also some useful commands:

1. Checking innoDB status

mysql> Show innoDB status;


On the example above, the result of this command shows that there is a pendant issue.

------------------------
LATEST FOREIGN KEY ERROR
------------------------
130705 18:41:47 Error in foreign key constraint of table testone/#sql-d65_ca:
 FOREIGN KEY ( role_fk ) REFERENCES testone.lgn_role( id ) ON DELETE NO ACTION ON UPDATE NO ACTION:
Cannot resolve table name close to:
( id ) ON DELETE NO ACTION ON UPDATE NO ACTION
------------




2. Checking Schema Informations

Useful to find out the existent constraints, etc.

mysql>USE information_schema;
mysql>desc KEY_COLUMN_USAGE;


For instance:

select * from key_column_usage where constraint_name='fk_lgn_permission_resource';



Thursday, July 4, 2013

VMWare suspended machine fails to restart



Problem

Suppose that suspended your vm and when you try to restart it, if fails, freezing the application, including the host, a Windows O.S..

An error message may come telling us that some log was written to disk that shall be reported to the support.

 
Solution

Restart Windows by some way.
Check if the log reported on the error message was really saved.
Sometimes it is not, but if there is one, and this workaround doesn't work to you, maybe the log comes useful to the support.

When the VM is suspended, its state is saved into files under the VM's installl directory, like this:

VM_NAME-A_CODE.vmem
VM_NAME-A_CODE.vmss

For instance:

vmvd5-db61c31a.vmem
vmvd5-db61c31a.vmss


Delete both files.
Pay attention to not delete any other file, except those mentioned above.
Also, delete the lock file or folder, if existent.

 
*** NOTE

If you have a recent VM backup of your working VM, stored as a suspended machine, you can take the advantage of restoring the working VM using the backup's state.
Just copy the .vmem and .vmss files to the working VM and restart it as usual.

 
****** IMPORTANT

Important to note that the state is tied by the system's environment.
You can't switch states among different environments.

virtualbox6: debian: netbeans install issues: "dpkg: warning: 'ldconfig' not found in PATH or not executable" and "pkg-deb: error: archive 'apache-netbeans_....deb' uses unknown compression for member 'control.tar.zst', giving up"

  >PROBLEMS/SOLUTIONS You desire to install  Netbeans  on a Debian O.S. using the VirtualBox v.6 because the VirtualBox v.7 fails on your...