Visar inlägg med etikett java. Visa alla inlägg
Visar inlägg med etikett java. Visa alla inlägg
tisdag, maj 13, 2008
Integrating Java & .Net
Had a discussion yesterday about Java & .Net integration. Of course, the usual suspects came up; JNI, J-Integra , JNBridge, JuggerNET, OOJNI etc. However if you do not only need to convert the objects, but also need to have the objects cached for fast transparent access from both Java and .Net, using Coherence is definitely an option.
Coherence provides transparent conversion to and from Java and .Net data types, including custom application user types. This enables .Net applications to access cached Java objects as native .Net objects and Java applications, including data grid members and Java clients, to access cached .Net objects as native Java objects.
Here you can find more details about Coherence for .Net. It is available for download on OTN. The download includes a .Net demo. To run this demo you either need Visual Studio, or you can use SharpDevelop (an open source IDE for the .Net platform).
Coherence provides transparent conversion to and from Java and .Net data types, including custom application user types. This enables .Net applications to access cached Java objects as native .Net objects and Java applications, including data grid members and Java clients, to access cached .Net objects as native Java objects.
Here you can find more details about Coherence for .Net. It is available for download on OTN. The download includes a .Net demo. To run this demo you either need Visual Studio, or you can use SharpDevelop (an open source IDE for the .Net platform).
torsdag, juni 14, 2007
Running a JAR File that Includes Another JAR From the Command Prompt
Today I got a question from a colleague on how-to run a JAR file that includes another JAR file directly from the command prompt, he couldn't get this to work - it just ended up with java.lang.NoClassDefFoundError exception. At first glance this seemed quite trivial, but it turned out to be more complicated than I first thought. My initial attempts also resulted in java.lang.NoClassDefFoundError, so I started to search around a bit for further information about the topic. This led me to this site http://one-jar.sourceforge.net/, and (as always) it turned out that someone else already solved the problem.
As I use JDeveloper (of course...) it needs to be added a few steps in addition to using one-jar to get the whole process to work, this is documented below.
1. First I created a new Workspace in JDeveloper with 2 projects 'mainproject' and 'subproject'.
2. In the 'subproject' there is a single dummy that have one method that just writes something to the System.out. There is also a JAR deployment profile that includes the mentioned class. The target JAR file I just called sub.jar.
3. Now it's time to create the 'mainproject'. As I am using the One-JAR in the end there are 2 restrictions I need to take into account for this project:
a. The main class needs to be named 'Main'
b. The target JAR file needs to be called 'main.jar'
I created a new class called 'Main' in the 'mainproject', added a dependency in the Project Properties to 'subproject' and created a dummy method in this class that uses the class created under 2. I ran the Main class inside JDeveloper to ensure that it worked before proceeding.
After that I created a JAR deployment profile. I made sure to name the target JAR file to 'main.jar'. Also checked the 'Include Manifest File (META-INF/MANIFEST.MF)' box and pointed the 'Main Class' to my 'Main' class. Next I made sure NOT to include my classes from the 'subproject' into this JAR file. This as they will be provided in a separate JAR file.
4. Next, it was time to download and install One-JAR. One-JAR can be downloaded from http://sourceforge.net/projects/one-jar. I created a new empty folder on my file system and placed the one-jar-boot-0.95.jar file there and renamed this to one-jar.jar. In my newly created folder I also added 2 subfolders 'main' and 'lib'. Once done I deployed my 2 JAR filed from JDeveloper, main.jar and sub.jar and placed them in the respective folders (main.jar in main and sub.jar in lib). The archive now has a structure similar to what is shown below:
As I use JDeveloper (of course...) it needs to be added a few steps in addition to using one-jar to get the whole process to work, this is documented below.
1. First I created a new Workspace in JDeveloper with 2 projects 'mainproject' and 'subproject'.
2. In the 'subproject' there is a single dummy that have one method that just writes something to the System.out. There is also a JAR deployment profile that includes the mentioned class. The target JAR file I just called sub.jar.
3. Now it's time to create the 'mainproject'. As I am using the One-JAR in the end there are 2 restrictions I need to take into account for this project:
a. The main class needs to be named 'Main'
b. The target JAR file needs to be called 'main.jar'
I created a new class called 'Main' in the 'mainproject', added a dependency in the Project Properties to 'subproject' and created a dummy method in this class that uses the class created under 2. I ran the Main class inside JDeveloper to ensure that it worked before proceeding.
After that I created a JAR deployment profile. I made sure to name the target JAR file to 'main.jar'. Also checked the 'Include Manifest File (META-INF/MANIFEST.MF)' box and pointed the 'Main Class' to my 'Main' class. Next I made sure NOT to include my classes from the 'subproject' into this JAR file. This as they will be provided in a separate JAR file.
4. Next, it was time to download and install One-JAR. One-JAR can be downloaded from http://sourceforge.net/projects/one-jar. I created a new empty folder on my file system and placed the one-jar-boot-0.95.jar file there and renamed this to one-jar.jar. In my newly created folder I also added 2 subfolders 'main' and 'lib'. Once done I deployed my 2 JAR filed from JDeveloper, main.jar and sub.jar and placed them in the respective folders (main.jar in main and sub.jar in lib). The archive now has a structure similar to what is shown below:
5. Now it's time to test this, and if it works correctly then the result should look something like:
D:\home\Demos\OneJARDemo\deploy>java -jar one-jar.jar
Hello from Main
Hello from sub project!
måndag, mars 19, 2007
Exposing a Java Service Facade for an EJB 3.0 Entity as a Web Service
A few days ago I tried to expose a Java Service Facade for an EJB 3.0 entity as a Web Service using JDeveloper. At first, I had a problem with this, however, once I found the culprit, it was quite obvious. Here are the steps I took:
2007年03月07日 13:46:35.434 ERROR OWS-04046 Caught exception while handling request:
java.lang.NullPointerException java.lang.NullPointerException
So, what was the problem? This problem occurs when the persistance.xml file point to a datasource rather than a direct JDBC connection. Since the JavaServiceFacade class is plain J2SE class, using a datasource in the persistance.xml can be used with EJB application only. For example you can create a EJB SessionFacade and publish this as a Web Service. Once I had re-defined the persistance.xml to point to a direct JDBC connection, it worked, like:
...
<persistence-unit name="WebServicesMetaData">
<class>webservicesmetadata.Countries</class>
<properties>
<property name="toplink.jdbc.driver" value="oracle.jdbc.OracleDriver"/>
<property name="toplink.jdbc.url"
value="jdbc:oracle:thin:@myHost:myPort:mySID"/>
<property name="toplink.jdbc.user" value="hr"/>
<property name="toplink.jdbc.password" value="hr_password"/>
<property name="toplink.target-database" value="Oracle"/>
<property name="toplink.logging.level" value="FINER"/>
</properties>
</persistence-unit>
...
- Created Entity Objects - by using the Wizards in JDeveloper, this went very smooth.
- Created the JavaServiceFacade Exposing the Entity, no problems here either.
- Expose the Java Service Facade as a Web Service using the Wizards. So far so good.
- Configure the persistence.xml file.
2007年03月07日 13:46:35.434 ERROR OWS-04046 Caught exception while handling request:
java.lang.NullPointerException java.lang.NullPointerException
So, what was the problem? This problem occurs when the persistance.xml file point to a datasource rather than a direct JDBC connection. Since the JavaServiceFacade class is plain J2SE class, using a datasource in the persistance.xml can be used with EJB application only. For example you can create a EJB SessionFacade and publish this as a Web Service. Once I had re-defined the persistance.xml to point to a direct JDBC connection, it worked, like:
...
<persistence-unit name="WebServicesMetaData">
<class>webservicesmetadata.Countries</class>
<properties>
<property name="toplink.jdbc.driver" value="oracle.jdbc.OracleDriver"/>
<property name="toplink.jdbc.url"
value="jdbc:oracle:thin:@myHost:myPort:mySID"/>
<property name="toplink.jdbc.user" value="hr"/>
<property name="toplink.jdbc.password" value="hr_password"/>
<property name="toplink.target-database" value="Oracle"/>
<property name="toplink.logging.level" value="FINER"/>
</properties>
</persistence-unit>
...
Prenumerera på:
Kommentarer (Atom)