Showing posts with label FAQ. Show all posts
Showing posts with label FAQ. Show all posts

13 May 2013

Unsupported major.minor version 51.0

Problem: Unsupported major.minor version 51.0.

Cause: The compiled application is not compatible with the JDK version of the application server.

Solution: Compile the source code again using the correct JDK version as of the application server.

The reported major numbers are:

J2SE 8 = 52,
J2SE 7 = 51,
J2SE 6.0 = 50,
J2SE 5.0 = 49,
JDK 1.4 = 48,
JDK 1.3 = 47,
JDK 1.2 = 46,
JDK 1.1 = 45

8 May 2013

Eclipse is running in a JRE, but a JDK is required

Problem: Eclipse is running in a JRE, but a JDK is required.

Cause:

  1. The ServiceReference can be null if no HelloService is registered, resulting in NullPointerException on line 6.
  2. The HelloService object cannot be got, due to missing permissions, possible timing issues if the HelloService unregisters between lines 5 and 6, causing NullPointerException on line 6.
  3. The HelloService may have become unusable, resulting in any RuntimeException subclass, most likely IllegalStateException on line 6.

Solution: Add the following at the beginning of eclipse.ini
-vm C:\Program Files\Java\jdk1.6.0_31\jre\bin\server

-vm C:\Program Files\Java\jdk1.6.0_31\jre\bin\server -startup plugins/org.eclipse.equinox.launcher_1.3.0.v20120522-1813.jar --launcher.library plugins/org.eclipse.equinox.launcher.win32.win32.x86_64_1.1.200.v20120913-144807 -product org.eclipse.epp.package.jee.product --launcher.defaultAction openFile --launcher.XXMaxPermSize 256M -showsplash org.eclipse.platform --launcher.XXMaxPermSize 256m --launcher.defaultAction openFile -vmargs -Dosgi.requiredJavaVersion=1.5 -Dhelp.lucene.tokenizer=standard -Xms40m -Xmx512m -XX:MaxPermSize=256m

Failed to lazily initialize a collection of role: could not initialize proxy - no Session

Problem: When lazy loading in used in Hibernate, it fails to initialize a collection of role.

failed to lazily initialize a collection of role: could not initialize proxy - no Session org.hibernate.LazyInitializationException: could not initialize proxy - no Session

Cause: The session was closed, so it can't load the actual contents of the collection.

Solution: add an @Transactional annotation to it, or the entry point from which it is called.

26 Mar 2013

How to fix the PermGen Space (Out of Memory) Error in Eclipse

Problem: PermGen Space (Out of Memory)

Cause: PermGen is the permanent generation of objects in the VM (Class names, internalized strings, objects that will never get garbage-collected).
The memory limit is too small that the Eclipse quickly runs out of memory, causing the aforesaid error.

Solution: Increase the permanent generation space available to Eclipse by adding the following in eclipse.ini
-XX:MaxPermSize=256m

-vm C:\Program Files\Java\jdk1.7.0_15\jre\bin\server -startup plugins/org.eclipse.equinox.launcher_1.2.0.v20110502.jar --launcher.library plugins/org.eclipse.equinox.launcher.win32.win32.x86_64_1.1.100.v20110502 -product org.eclipse.epp.package.jee.product --launcher.defaultAction openFile --launcher.XXMaxPermSize 256M -showsplash org.eclipse.platform --launcher.XXMaxPermSize 256m --launcher.defaultAction openFile -vmargs -Dosgi.requiredJavaVersion=1.5 -Xms40m -Xmx512m -XX:MaxPermSize=256m

21 Mar 2013

java.lang.NullPointerException: A null service reference is not allowed.

Problem: When trying to get a service from the BundleContext, NullPointerException is found.

public class Activator implements BundleActivator { ServiceReference helloServiceReference; public void start(BundleContext context) throws Exception { System.out.println("Hello World!!"); helloServiceReference= context.getServiceReference(HelloService.class.getName()); HelloService helloService =(HelloService)context.getService(helloServiceReference); System.out.println(helloService.sayHello()); } public void stop(BundleContext context) throws Exception { System.out.println("Goodbye World!!"); context.ungetService(helloServiceReference); } } org.osgi.framework.BundleException: Exception in com.javaworld.sample.helloworld.Activator.start() of bundle com.javaworld.sample.HelloWorld. at org.eclipse.osgi.framework.internal.core.BundleContextImpl.startActivator(BundleContextImpl.java:734) at org.eclipse.osgi.framework.internal.core.BundleContextImpl.start(BundleContextImpl.java:683) at org.eclipse.osgi.framework.internal.core.BundleHost.startWorker(BundleHost.java:381) at org.eclipse.osgi.framework.internal.core.AbstractBundle.resume(AbstractBundle.java:389) at org.eclipse.osgi.framework.internal.core.Framework.resumeBundle(Framework.java:1131) at org.eclipse.osgi.framework.internal.core.StartLevelManager.resumeBundles(StartLevelManager.java:559) at org.eclipse.osgi.framework.internal.core.StartLevelManager.resumeBundles(StartLevelManager.java:544) at org.eclipse.osgi.framework.internal.core.StartLevelManager.incFWSL(StartLevelManager.java:457) at org.eclipse.osgi.framework.internal.core.StartLevelManager.doSetStartLevel(StartLevelManager.java:243) at org.eclipse.osgi.framework.internal.core.StartLevelManager.dispatchEvent(StartLevelManager.java:438) at org.eclipse.osgi.framework.internal.core.StartLevelManager.dispatchEvent(StartLevelManager.java:1) at org.eclipse.osgi.framework.eventmgr.EventManager.dispatchEvent(EventManager.java:230) at org.eclipse.osgi.framework.eventmgr.EventManager$EventThread.run(EventManager.java:340) Caused by: java.lang.NullPointerException: A null service reference is not allowed. at org.eclipse.osgi.framework.internal.core.BundleContextImpl.getService(BundleContextImpl.java:586) at com.javaworld.sample.helloworld.Activator.start(Activator.java:20) at org.eclipse.osgi.framework.internal.core.BundleContextImpl$1.run(BundleContextImpl.java:711) at java.security.AccessController.doPrivileged(AccessController.java:251) at org.eclipse.osgi.framework.internal.core.BundleContextImpl.startActivator(BundleContextImpl.java:702) ... 12 more

Cause:

  1. The ServiceReference can be null if no HelloService is registered, resulting in NullPointerException on line 6.
  2. The HelloService object cannot be got, due to missing permissions, possible timing issues if the HelloService unregisters between lines 5 and 6, causing NullPointerException on line 6.
  3. The HelloService may have become unusable, resulting in any RuntimeException subclass, most likely IllegalStateException on line 6.

Solution: Use ServiceTracker instead.

References

  1. OSGi Service

Missing Constraint: Import-Package: org.osgi.framework

Figure 1: Missing Constraint: Import-Package
Problem: When running a configuration to run a bundle, error message is shown.
Missing Constraint: Import-Package: org.osgi.framework;version="1.3.0"
Solution: Include the bundle in the "Run Configuration".
Figure 2: Add Bundles

28 Feb 2013

org.springframework.jdbc.UncategorizedSQLException: Error setting null parameter.

Problem: org.springframework.jdbc.UncategorizedSQLException: Error setting null parameter. Most JDBC drivers require that the JdbcType must be specified for all nullable parameters.

Cause: The JdbcType property is not set in the XML mapper.

Solution: Specify jdbcType of the parameter in the mapper.

<select id="selectByYear" parameterType="map" resultMap="BaseResultMap"> SELECT * FROM tbl_calendar WHERE year=#{year,jdbcType=DECIMAL} </select>

22 Feb 2013

java.lang.IllegalArgumentException: Mapped Statements collection does not contain value for

Problem: java.lang.IllegalArgumentException: Mapped Statements collection does not contain value for

Cause: The same namespace is used in 2 different mappers.

Solution: Change the namespace in one of the mappers.

<?mapper namespace="com.blogspot.adaprognotebook.dao.mybatis.CompanyMapper" >

Exception getting JDBC Driver

Problem: When generating the iMbatis mapping files in Eclipse, "Fail to generate mapper files: Exception getting JDBC Driver" error is encountered.

Figure 1: Exception getting JDBC Driver

Cause: Eclipse cannot find the JDBC library file.

Solution: Add <classPathEntry> to the "generatorConfig.xml" to define the class path of the library file.

generatorConfig.xml

<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE generatorConfiguration PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN" "http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd" > <generatorConfiguration> <classPathEntry location="/Users/adaprognotebook/lib/ojdbc6.jar"/> <context id="system" > <plugin type="org.mybatis.generator.plugins.CaseInsensitiveLikePlugin" /> <jdbcConnection driverClass="oracle.jdbc.driver.OracleDriver" connectionURL="jdbc:oracle:thin:@//127.0.0.1:1521/books" userId="ada" password="pass123" /> <javaModelGenerator targetPackage="com.blogspot.adaprognotebook.model" targetProject="books" /> <sqlMapGenerator targetPackage="com.blogspot.adaprognotebook.dao.mybatis.mapper" targetProject="books/src/conf" /> <javaClientGenerator targetPackage="com.blogspot.adaprognotebook.dao.mybatis" targetProject="books" type="XMLMAPPER" /> <table schema="books" tableName="AUTHROS" /> </context> </generatorConfiguration>

20 Feb 2013

How to run Maven with switch

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.7.1:test (default-test) on project lucky-number-ws: There are test failures. [ERROR] [ERROR] Please refer to D:\workspaces\SpringTest\lucky-number-ws\target\surefire-reports for the individual test results. [ERROR] -> [Help 1] [ERROR] [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch. [ERROR] Re-run Maven using the -X switch to enable full debug logging.

Solution: Add the switches after the goal, e.g. test -e -X.

Figure 1: Run Configuration with switch

19 Feb 2013

Unable to access binding information for class. Make sure the binding has been compiled

Problem: Unable to access binding information for class. Make sure the binding has been compiled.

HTTP ERROR 500 Problem accessing /lucky-number-ws/LuckyRequest.wsdl. Reason: Error creating bean with name 'payloadMapping' defined in ServletContext resource [/WEB-INF/spring/applicationContext.xml]: Cannot resolve reference to bean 'luckyServiceEndpoint' while setting bean property 'endpointMap' with key [TypedStringValue: value [{http://localhost:8080/luckyservice/services/}/LuckyRequest], target type [null]]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'luckyServiceEndpoint' defined in ServletContext resource [/WEB-INF/spring/applicationContext.xml]: Cannot resolve reference to bean 'marshaller' while setting bean property 'marshaller'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'marshaller' defined in ServletContext resource [/WEB-INF/spring/applicationContext.xml]: Invocation of init method failed; nested exception is org.springframework.oxm.jibx.JibxSystemException: Unable to access binding information for class com.blogspot.adaprognotebook.message.LuckyResponse Make sure the binding has been compiled; nested exception is org.jibx.runtime.JiBXException: Unable to access binding information for class com.blogspot.adaprognotebook.message.LuckyResponse Make sure the binding has been compiled

Solution: Run "jibx:bind" goal to compile the binding.

[INFO] Scanning for projects... [INFO] [INFO] ---------------------------------------------------------------- [INFO] Building Lucky Number Web Service 0.0.1-SNAPSHOT [INFO] ---------------------------------------------------------------- [INFO] [INFO] --- jibx-maven-plugin:1.2.4.5:bind (default-cli) @ lucky-number-ws --- [INFO] Running JiBX binding compiler (single-module mode) on 1 binding file(s) [INFO] ---------------------------------------------------------------- [INFO] BUILD SUCCESS [INFO] ---------------------------------------------------------------- [INFO] Total time: 1.772s [INFO] Finished at: Tue Feb 19 18:01:43 CST 2013 [INFO] Final Memory: 11M/24M [INFO] ----------------------------------------------------------------

Plugin or one of its dependencies could not be resolved: Failed to read artifact descriptor: Could not find artifact

Problem: Plugin {plugin name} or one of its dependencies could not be resolved: Failed to read artifact descriptor for {plugin name}: Could not find artifact {plugin name}

[INFO] ----------------------------------------------------------- [INFO] BUILD FAILURE [INFO] ----------------------------------------------------------- [INFO] Total time: 0.079s [INFO] Finished at: Tue Feb 05 12:14:23 CST 2013 [INFO] Final Memory: 5M/8M [INFO] ----------------------------------------------------------- [ERROR] Plugin org.jibx:maven-jibx-plugin:1.2.4-SNAPSHOT or one of its dependencies could not be resolved: Failed to read artifact descriptor for org.jibx:maven-jibx-plugin:jar:1.2.4-SNAPSHOT: Could not find artifact org.jibx:maven-jibx-plugin:pom:1.2.4-SNAPSHOT -> [Help 1]

Cause: The repository does not contain the plugin.

Solution: Add the <pluginRepositories> sections in the pom.xml file.

pom.xml

<pluginRepositories> <pluginRepository> <id>sonatype-nexus-snapshots</id> <name>Sonatype Nexus Snapshots</name> <url>https://repository.sonatype.org/content/groups/public/</url> <snapshots> <enabled>true</enabled> </snapshots> </pluginRepository> </pluginRepositories> <repositories> <repository> <id>sonatype-nexus-snapshots</id> <name>Sonatype Nexus Snapshots</name> <url>https://oss.sonatype.org/content/repositories/snapshots</url> <releases> <enabled>false</enabled> </releases> <snapshots> <enabled>true</enabled> </snapshots> </repository> </repositories>

Error assembling WAR: webxml attribute is required.

Problem: Error assembling WAR: webxml attribute is required.

[INFO] ----------------------------------------------------------- [INFO] BUILD FAILURE [INFO] ----------------------------------------------------------- [INFO] Total time: 1.694s [INFO] Finished at: Tue Feb 05 15:21:46 CST 2013 [INFO] Final Memory: 10M/21M [INFO] ----------------------------------------------------------- [ERROR] Failed to execute goal org.apache.maven.plugins:maven-war-plugin:2.1.1:war (default-war) on project {project name}: Error assembling WAR: webxml attribute is required (or pre-existing WEB-INF/web.xml if executing in update mode) -> [Help 1]

Cause: The maven-war-plugin plugin is not configured.

Solution:Add the following section in the pom.xml.

pom.xml

<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-war-plugin</artifactId> <version>2.1.1</version> <configuration> <failOnMissingWebXml>false</failOnMissingWebXml> </configuration> </plugin>

class org.jibx.runtime.JodaConvert not found in classpath.

Problem: class org.jibx.runtime.JodaConvert not found in classpath.

[INFO] --- jibx-maven-plugin:1.2.4.5:bind (default-cli) @ memberservice --- [INFO] Running JiBX binding compiler (single-module mode) on 1 binding file(s) Running binding compiler version jibx_1_2_5-SNAPSHOT [INFO] ----------------------------------------------------------- [INFO] BUILD FAILURE [INFO] ----------------------------------------------------------- [INFO] Total time: 0.640s [INFO] Finished at: Tue Feb 05 16:53:07 CST 2013 [INFO] Final Memory: 5M/14M [INFO] ----------------------------------------------------------- [ERROR] Failed to execute goal org.jibx:jibx-maven-plugin:1.2.4.5:bind (default-cli) on project memberservice: Internal error - class org.jibx.runtime.JodaConvert not found in classpath -> [Help 1]

Cause: Wrong version of JiBX is used.

Solution:Update the version of JiBX dependencies in the pom.xml.

pom.xml

<dependency> <groupId>org.jibx</groupId> <artifactId>jibx-run</artifactId> <version>1.2.4.5</version> </dependency> <dependency> <groupId>org.jibx</groupId> <artifactId>jibx-extras</artifactId> <version>1.2.4.5</version> </dependency>

'build.plugins.plugin.version' for org.apache.maven.plugins:maven-compiler-plugin is missing.

Problem: 'build.plugins.plugin.version' for org.apache.maven.plugins:maven-compiler-plugin is missing.

[WARNING] Some problems were encountered while building the effective model for {project name}:war:1.0-SNAPSHOT [WARNING] 'build.plugins.plugin.version' for org.apache.maven.plugins:maven-compiler-plugin is missing. @ line 83, column 15 [WARNING] [WARNING] It is highly recommended to fix these problems because they threaten the stability of your build. [WARNING] [WARNING] For this reason, future Maven versions might no longer support building such malformed projects.

Cause: Version number is not set for the maven-compiler-plugin plugin.

Solution:Set the version number under the <artifactId>

pom.xml

<plugin> <artifactId>maven-compiler-plugin</artifactId> <version>3.0</version> <configuration> <source>1.6</source> <target>1.6</target> </configuration> </plugin>

File encoding has not been set, using platform encoding Cp1252, i.e. build is platform dependent!

Problem: File encoding has not been set, using platform encoding Cp1252, i.e. build is platform dependent!

[WARNING] File encoding has not been set, using platform encoding Cp1252, i.e. build is platform dependent

Cause: Encoding of the source files is not set.

Solution: Set the encoding of the source files.

pom.xml

<project> ... <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> </properties> ... </project>

The project uses or overrides a deprecated API.

Problem: The project uses or overrides a deprecated API.

[WARNING] Note: D:\workspaces\Test\LuckyNumberWebService\src\test\java\com\blogspot\adaprognotebook\client\TestLuckyServiceClient.java uses or overrides a deprecated API. [WARNING] Note: Recompile with -Xlint:deprecation for details.

Cause: The project uses or overrides a deprecated API.

Solution: Set "-Xlint:deprecation" as compiler argument during compilation.

pom.xml

<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.0</version> <configuration> <source>1.6</source> <target>1.6</target> <compilerArgument>-Xlint:deprecation</compilerArgument> </configuration> </plugin>

Can't resolve Archetype when trying to add one in STS.

Problem: Can't resolve Archetype when trying to add one in STS.
Figure 1: Add Archetype.
Figure 2: Can't resolve Archetype.
Cause: STS cannot resolve the repository even though the Repository URL is specified.
Solution: Set the repository in .m2/settings.xml.
pom.xml
<profiles> <profile> <repositories> <repository> <id>mvn-repository</id> <name>MvnRepository.com</name> <url>http://mvnrepository/</url> </repository> </repositories> </profile> </profiles>

Java.Lang.ClassNotFoundException: Org.Objectweb.Asm.Type

Problem: Java.Lang.ClassNotFoundException: Org.Objectweb.Asm.Type
Caused by: java.lang.NoClassDefFoundError: org.objectweb.asm.Type

WARN:oejw.WebAppContext:Failed startup of context o.e.j.w.WebAppContext java.lang.reflect.InvocationTargetException Caused by: java.lang.ClassNotFoundException: org.objectweb.asm.Type

Cause: asm.jar is missing.

Solution: Add the dependency in the project's pom.xml.

<dependency> <groupId>asm</groupId> <artifactId>asm</artifactId> <version>3.3.1</version> </dependency>

Project configuration is not up-to-date with pom.xml. Run project configuration update.

Problem: Project configuration is not up-to-date with pom.xml. Run project configuration update.

Description Resource Path Location Type Project configuration is not up-to-date with pom.xml. Run project configuration update {Project Name} line 1 Maven Configuration Problem

Cause: Project configuration is not up-to-date.

Solution: Run "Maven" -> "Update Project Configuration...".

Figure 1: Update Project Configuration