NoSuchMethodException while deploying application in jdeveloper

Tags

, , ,

In Jdeveloper, I’ve created an application for Hibernate to provide DB Service using annotation to map class with DB, and I created jar of that and used in other project WebService. When i run the Hibernate Project Separately it works fine.

while deployment the web service application it reports NoSuchMethod Exception.

Error 500--Internal Server
java.lang.ExceptionInInitializerError
Caused by: java.lang.NoSuchMethodError: javax.persistence.Table.indexes()[Ljavax/persistence/Index;
         at org.hibernate.cfg.annotations.EntityBinder.processComplementaryTableDefinitions(EntityBinder.java:936)
         at org.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.java:824)
         at org.hibernate.cfg.Configuration$MetadataSourceQueue.processAnnotatedClassesQueue(Configuration.java:3788)
         at org.hibernate.cfg.Configuration$MetadataSourceQueue.processMetadata(Configuration.java:3742)
         at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1410)
         at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1844)
         at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1928)

After some research, its known that

The libraries used by the application after deployment is different than the library that is attached to the application in case of deployed application. The ClassLoader loads the class from different location.

The following code tells from which jar the class gets loaded.

Table.class.getProtectionDomain().getCodeSource().getLocation()

Using this its been found that while running as an application it uses the right library (hibernate) from right location /WEB-INF/lib/hibernate-jpa-2.1-api-1.0.0.Final.jar.

In deployed web service it uses older version of library which doesn’t have this method support. (its introduced in later versions) and its location was web logic /User_Home/Oracle/Middleware/modules/javax.persistence_1.0.0.0_1-0-2.jar (or the location of the weblogic libraries)

To solve this we can tell the weblogic to prefer the library from web-inf (our project libraries), if you don’t have one create it under WEB-INF directory.
by Adding the following in weblogic-application.xml (Application Resources)

<prefer-application-packages>
 <package-name>javax.persistence.*</package-name>
<prefer-application-packages>

To understand reason behind this issue check this resource http://docs.oracle.com/cd/E15051_01/wls/docs103/programming/classloading.html

Advertisements

Adding postgres to iterm2 in Mac

Tags

, , ,

I’ve used the following link to setup my mac.

https://github.com/nicolashery/mac-dev-setup

But after the setup and installing the postgres i wanted to access postgres using iterm2 but

when i say psql it reported no command found!

we can do

export PATH = “/Applications/Postgres.app/Contents/Versions/version/bin:$PATH”

http://postgresapp.com/documentation/

or if u want it to forever and for each terminal instance add it to zshrc if  u have setup zsh

add the line to ~/.zshrc and you are done.

close this terminal instance and open new one it works great.

Aaron Swartz

Tags

, ,

i’m amazed about this. But we never think about this. We don’t care and we don’t take responsibility.

There are some persons who care,

By virtue of being students at a major U.S. university, I assume that you have access to a wide variety of scholarly journals. Pretty much every major university in the United States pays these sort of licensing fees to organizations like JSTOR and Thomson and ISI to get access to scholarly journals that the rest of the world can’t read. And these licensing fees are substantial. And they’re so substantial that people who are studying in India, instead of studying in the United States, don’t have this kind of access. They’re locked out from all of these journals. They’re locked out from our entire scientific legacy.

This is aaron’s speech internet activist,

 

But this is what happened to him who thought to bring liberty,

 

Github Untracking File from Git still keeping file in Remote Repository

Tags

,

Recently i faced with a situation where i need to have the file in repository but we don’t want the changes to be pushed. The situation was this our application makes use of a server and that file is for server connection. so when we try to run it locally we need to change the configuration IP address in that file. But i don’t want that changes to be pushed. Because i’ll use my system ip address and others ‘ll change it to their’s. but still we need that file in repository.

This command does that awesome thing

git update-index --assume-unchanged <filename>

This command simply sets a bit “assume unchanged”, which if set git won’t track the modifications pushing won’t take this

But the issue is everyone who cloned your repository or working on the repository have to run this command, if not when they push it it’ll be affecting file in remote repository.

To view the files like these, that is untracked [assuming unchanged]

git ls-files -v | grep '^[[:lower]]'

git-ls-files shows information about files in the index and the working tree

-v option tells the command to use lowercase letters for ‘assume unchanged’ files.

Normally git ls-files lists all files in tree. you can do git ls-files and search for first letter ‘h’ results in the file. you can also use ‘^[a-z]’ or ‘^h’ for grep finding pattern that filters the result.

when you want to remove the file from untracking

git update-index --no-assume-unchanged <filename>

This unsets the “assume unchaged” bit and git starts tracking it.

More Information:

Ubuntu Add new device to run your application

Tags

, ,

For cordova application, which i’ve an android platform

cordova run

runs the application in mobile directly in MAC OS. when i tried to connect mobile in ubuntu and ran, it didn’t work! adb devices showed nothing in list of devices attached.

we have to define rules so that to connect to that device.

use lsusb command to list devices. This will result in many devices connected,

 Bus 002 Device 037: ID 0fce:019e Sony Ericsson Mobile Communications AB

ofce is idVendor and 019e is idproduct

or download the file for 51-andorid.rules from http://www.joescat.com/linux/android_rules.html

sudo udevadm control --reload-rules

Now remove the mobile and reconnect it. and try

adb devices

if you still see this

List of devices attached 
???????????? no permissions

Edit the file 51-android.rules to /etc/udev/rules.d [temporary rules directory] and add the line

ATTRS{idVendor}==”0fce”, ATTRS{idProduct}==”519e”, ENV{adb_matched}=”yes”

change the last but third line from GROUP=”usb” to

SYMLINK+="android_adb", MODE="0664", GROUP="plugdev"

now reload rules and reconnect mobile. It should list a device with its id in adb devices.

it worked without adb kill-server and adb start-server, but if still didn’t update you can do that.

More info:

http://manpages.ubuntu.com/manpages/karmic/en/man7/udev.7.html

http://developer.android.com/tools/device.html

Making Connection via Proxy in JAVA

Tags

Ever tried to connect a url and failed? if there’s proxies and if you connect without considering proxies. it will fail. you cannot bypass the proxy and connect.

List<Proxy> proxyList = ProxySelector.getDefault().select(new URI("http://www.google.com")); 

This will give the list of proxies if available. [It’s possible to have more than one proxies!]

Then connect to the URL using the proxy [connect through the proxy]


URL googleUrl = new URL("http://www.google.com");

List<Proxy> proxyList = ProxySelector.getDefault().select(googleUrl.toURI());

for (Proxy proxy : proxyList) {
InetSocketAddress proxyAddress = (InetSocketAddress) proxy.address();
if (proxyAddress != null) {
System.out.println("Host: " + proxyAddress.getHostName() + " Port: " + proxyAddress.getPort());
URLConnection googleUrlConn = googleUrl.openConnection(proxy);
System.out.println("waiting");
System.out.println(googleUrlConn.getPermission());
googleUrlConn.connect();
Object content = googleUrlConn.getContent();
System.out.println(content);
} else {
System.out.println("No proxy available");
}

for more information check this:

http://docs.oracle.com/javase/7/docs/technotes/guides/net/proxies.html

Setting Author Name in IDEs (NetBeans, Eclipse, IntelliJ IDEA 13 CE)

Tags

, , , , , , ,

NetBeans

(Tested on netbeans 7.2.1)

NetBeans does partially solve the problem by using a User.properties file, but it fails to identify tags for c/c++ files.

1st Method: Change the Author property in Templates

It is a direct solution but changes should be made for each template.

2nd Method: Using User.properties file:

  • Click on: Tools –> Template (from the toolbar)
  • You should get a Template Manager window. Now click on the Settings button.
  • User.properties file should now be open. Un-comment the last line and insert your name.
  • What ever name you choose in this file overrides the default name(system name) given during initialization.

3rd Method: For a more permanent solution :-

  • Go to your NetBeans installation directory

Example:

C:\Program Files\NetBeans X.Y.Z\
  • Go into the etc folder and open netbeans.conf file using any editor (advanced text editors Notepad++ would format the text in windows and make it more comfortable)
  • Find the netbeans_default_options key
netbeans_default_options="-J-client -J-Xss2m...."
  • Now add the following to this line
-J-Duser.name=NAMEHERE

OR

-J-Duser.name="NAME HERE"
  • Save the configuration file and start NetBeans

Eclipse

(Tested on Eclipse Juno)

Changing ‘eclipse.ini’ file:

  • Go to Eclipse folder (which has the eclipse.exe file)
  • Open ecilpse.ini file
  • Add this after -vmargs option:
-Duser.name=NAMEHERE
  • Save the file and start Eclipse

IntelliJ IDEA 13 Community Edition

(Tested on IntelliJ IDEA 13 CE)

Changing the ‘idea.exe.vmoptions’ file:

  • Go to your IntelliJ installation folder
C:\Program Files(x86)\JetBrains\IntelliJ IDEA Community Edition...
  • Go into bin folder
  • Open the file named idea.exe.vmoptions (or idea64.exe.vmoptions) and add the following property
-Duser.name=NAMEHERE
  • Save the file and you are done.

 

Hope it helped and please share if liked!!

Java Bit version

Tags

,

To know the Java Bit version (64 or 32 Bit) you are using, you can use the command prompt

Java [-options] class [args]

-d32 use a 32-bit data model if available

-d64 use a 64-bit data model if available

Java command runs the .class file. It can take –d32 and –d64 as options.

To check whether a 64 bit data model is available, enter the command

Java –d64 -version

If it is not available you’ll get an error

Error: This java instance does not support a 64-bit JVM.

Please install the desired version.

If it is installed you’ll get the version.

Incase if you have 32 bit installed and in need of 64 bit. Install the 64 bit  jdk-7u45-windows-x64 from oracle. (x86 means 32 bit jdk-7u4-windows-i586)

http://download.oracle.com/otn-pub/java/jdk/7u45-b18/jdk-7u45-windows-x64.exe

In Netbeans IDE to change the bit version, go to projects window from window menu (shortcut : Ctrl+1).

Choose the project you want to build it using other version. Right click project and go to properties.

Images to change jvm required bit version

In project properties window choose Libraries and select Manage platforms.

manage platforms

The dropdown box shows current jdk data model (64 or 32 bit) and other jdk if available.

In java platform manager windows click on Add platform to add a new platform.

Browse the folder where you installed the required version and choose it. Give a name to the new platform and  click finish and close the window.

Now select the required java platform from drop down box and click OK.

The project will run using the given new java platform.

Java: Compound Assignment Operator

Tags

Contextual difference between compound assignment and normal assignment.

var += x;  with respect to

var = var + x;

byte byteVar = 1;
shortshortVar=Short.MAX_VALUE;
System.out.println(byteVar+ " , "+shortVar);
System.out.println("Binary Representation: "+Integer.toBinaryString(byteVar)+" : "+ Integer.toBinaryString(shortVar));
byteVar+=shortVar; //try replacing with other expression
System.out.println("After adding values");
System.out.println(byteVar+ " , "+shortVar);
System.out.println("Binary Representation: "+Integer.toBinaryString(byteVar)+" : "+ Integer.toBinaryString(shortVar));

If you add this statement in place of statement 9 the following error results.

byteVar=byteVar+shortVar;

java.lang.RuntimeException: Uncompilable source code – possible loss of precision

JLS 15.26.2 says

            A compound assignment expression of the form E1 op= E2 is equivalent to E1 = (T) ((E1) op (E2)), where T is the type of E1, except that E1 is evaluated only once.           

byteVar+=shortVar;

is computed as

byteVar=(byte) byteVar+shortVar;

short x = 3;
x += 4.6;

and results in x having the value 7 because it is equivalent to:

short x = 3;
x = (short)(x + 4.6);

The compound assignment operator is simple and use it if operand types are same.

If it deals with different operand types use it with care.

Don’t use it with

operand1+= operand2

if operand2 size is greater than operand1. Eg. Operand1 is byte or short and operand2 is int

operand1 is of type integer and operand2 is of type float,long,double.

Java funny program

Tags

A simple java program to make us think.

System.out.println(Long.toHexString(0x100000000L  + 0xcafebabe));

Try it first!

we expect the output to be 1cafebabe. but its quite interesting that we get

cafebabe

as output.

The hexadecimal number 0xcafebabe is considered as a negative number -889275714

its binary equivalent is 11001010111111101011101010111110. The 32nd bit is set and considered as negative.

so try adding decimal numbers (decimal equivalent) 0xcafebabe (-889275714) and 0x100000000 (4294967296) then convert it to hexadecimal. result is 3405691582 i.e 0xcafebabe

As you can see in the code 0xcafebabe has no suffix added to it, so it is considered to be an Integer primitive. In the expression 0x100000000 is a long primitive. This beckons for a Numerical Promotion (widening) of 0xcafebabe from integer to long.

This is where the magic happens, the now converted ‘cafebabe’ in binary has the following representation:

 1111111111111111111111111111111111001010111111101011101010111110

You can verify this by using the “Long.toBinaryString() ” method with the said converted number.

The negative sign bit has been carried to the remaining bit positions of the widened type. Now it simply a matter of adding two 64-bit numbers.

1111111111111111111111111111111111001010111111101011101010111110
0000000000000000000000000000000100000000000000000000000000000000
                                11001010111111101011101010111110
(alt. in Hexadecimal)                                   CAFEBABE

More on CAFEBABE:

 

 

If debugging is the process of removing software bugs, then programming must be the process of putting them in.  – Edsger Dijkstra