Call from OSGI bundle Datasource - java

Following this tutorial http://netbeans.org/kb/docs/javaee/maven-osgiservice-cdi.html
I have managed to create a simple OSGI bundle and a client web application. I placed a managed bean into the web application client. The managed been calls a interface placed into the OSGI bundle. I successfully compile the code.
Now the interesting part is can I place a data into the OSGI bundle which can make queries to the database. This is the code that I placed into the OSGI bundle:
package com.test;
import javax.ejb.Remote;
/** include default packages for Beans */
import java.io.Serializable;
import javax.enterprise.context.SessionScoped;
// or import javax.faces.bean.SessionScoped;
import javax.inject.Named;
/** include package for SHA-256 encryption */
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
/** include SQL Packages */
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.sql.DataSource;
import javax.annotation.Resource;
// or import javax.faces.bean.ManagedBean;
#Remote
public interface SL_43Remote {
#Resource(name="java:/Oracle")
private DataSource ds;
}
Betbeans 7.1 shows error: "modifier private is not allowed" and "= expected".
Maybe I'm missing some libraries or maybe OSGI bundles don't allow source code for working with databases.
Any idea how to fix the problem?
Kind Regards.
Peter

Private fields are not allowed on interfaces in Java.
This problem has nothing to do with OSGi, just the fundamentals of Java.

Related

What dependency from com.google.firebase firebase-admin when using Firebase Cloud Messaging do I really need?

I added the dependency com.google.firebase:firebase-admin:9.0.0 to our Java projects to use FirebaseMessaging and send FCM push notifications.
Now I recognized this added about 40MB of dependencies to our application. This feels like dependency hell for me :-(
So I'm asking myself - do I really need all this transitive dependencies? I don't want to start randomly excluding them. Is there any documentation what is really needed?
We're using the following imports from com.google:
import com.google.api.client.http.HttpTransport;
import com.google.api.client.http.javanet.NetHttpTransport;
import com.google.auth.oauth2.GoogleCredentials;
import com.google.firebase.FirebaseApp;
import com.google.firebase.FirebaseOptions;
import com.google.firebase.messaging.FirebaseMessaging;
import com.google.firebase.messaging.FirebaseMessagingException;
import com.google.firebase.messaging.Message;
import com.google.firebase.messaging.Notification;

where to get java SDK for BusinessObjects

I want to import the packages, for example:
import java.io.PrintWriter;
import java.text.DateFormat;
import java.util.Date;
these packages have already existed so it doesn't pop up any error messages.
When I want to import others packages:
import com.businessobjects.rebean.wi.DocumentInstance;
import com.businessobjects.rebean.wi.Prompt;
import com.businessobjects.rebean.wi.Prompts;
import com.businessobjects.rebean.wi.ReportEngine;
import com.businessobjects.rebean.wi.ReportEngines;
import com.crystaldecisions.enterprise.ocaframework.ServiceNames;
import com.crystaldecisions.sdk.exception.SDKException;
import com.crystaldecisions.sdk.framework.CrystalEnterprise;
import com.crystaldecisions.sdk.framework.IEnterpriseSession;
import com.crystaldecisions.sdk.framework.ISessionMgr;
import com.crystaldecisions.sdk.occa.infostore.IInfoObject;
import com.crystaldecisions.sdk.occa.infostore.IInfoObjects;
import com.crystaldecisions.sdk.occa.infostore.IInfoStore;
import com.crystaldecisions.sdk.plugin.desktop.folder.IFolder;
It will say "the import cannot be resolved", but where I can get the jar files to resolve these problems?
I tried to search these jar files in the java lib folder but was not able to get them.
Can anyone tell the exact folder path for these jar files, if it is there?
Or where can I download those packages.....
I found the website (https://help.sap.com/doc/javadocs_bip_42/4.2/en-US/bip/en/com/crystaldecisions/sdk/exception/package-summary.html) but I still don't know how to import it......
You'll need rebean.wi.adapter.jar and cecore.jar. They are located in the following directory with BO client or server software is installed:
C:\Program Files (x86)\SAP BusinessObjects\SAP BusinessObjects Enterprise XI 4.0\java\lib
Note that these are not available publicly -- you will need to install the software.

Eclipse, Java, import suddenly stopped being recognize

I have a java project with several packages.
com.xxx.simulator
ThreadManager.java
Simulator.java
com.example
Config.java
Simulator and Config both import ThreadManager. I did not have any problem until now. I opened Eclipse and had this errors showing:
The import com.xxx.simulator.ThreadManager cannot be resolved
and
ThreadManager cannot be resolved
This is ThreadManager:
package com.xxx.simulator;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ThreadFactory;
import org.json.JSONObject;
public class ThreadManager implements ThreadFactory { }
This is Config
package com.example;
import java.math.BigDecimal;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import org.json.JSONObject;
import com.xxx.simulator.Simulator;
import com.xxx.simulator.ThreadManager; <----- The import cannot be resolved
import com.xxx.simulator.config.Configuration;
#Path("config")
public class Config {
// some stuff
ThreadManager.getInstance().getAllThreadStatus(); <----- ThreadManager cannot be resolved (on ThreadManager only)
}
To fix ThreadManager cannot be resolved, I am proposed to import ThreadManager from com.xxx.simulator. But it already is imported with the Import cannot be resolved error.
How can I solve this ? Any solution proposed by Eclipse is not working.
Edit: The problem is for Config.java AND Simulator.java.
Edit 2: ThreadManager is the only class causing this problem from com.xxx.simulator.
Try a clean build of the project in eclipse. If it is a maven project, then try running mvn eclipse:eclipse through command line.
Reasoning:
Sometimes eclipse lands in a state where it is no longer able to identify / find the generated class files / jars. So, we usually do a clean build or mvn eclipse:eclipse to get all the dependencies (classes/jars) correctly set up. This is essentially rebuilding the project so that all relationships, dependencies, metadata is correctly set up to recognize the dependencies successfully.

import of java classes cannot be resolved

I am using eclipse for core java and its working fine. Now I downloaded another eclipse for java ee and I am using tomcat server but in my new eclipse java files are not getting loaded
Below mentioned imports are showing the error of import cannot be resolved while they are working fine in my old eclipse(I think there is some problem with build path ) -
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
While the below-mentioned imports do not show any error-
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import com.mysql.jdbc.ResultSet;
Sample Image of error:
A package at the top should be used, a deep src sub-directory like: src/aaa/bbb/ccc.
package aaa.bbb.ccc;
import ...
Reason: using the default package (immediately under the root) is actually
never done since java 1.2. For that I find the missing package suspicious.
The following is wrong:
import com.mysql.jdbc.ResultSet;
It should be:
import java.sql.ResultSet;
Reason for JDBC using database vendor specific libraries is bad style.
Entirely sure on a cause for your errors in eclipse I am not sure. A refresh, Alt+F5 might be useful if the error was a fluke.
If the JDK is actually java 9 I would expect import problems too, as then you would need to gather the JDK modules piecewise. That does not seem to be the case here.
Check if you have set the JDKs correctly in your IDE and in the project.

package java.sql does not exist error in j2me

Is J2ME supports to connect mssqlserver database like java????
I shows following error in imports,
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
error: package java.sql does not exist import java.sql.Connection;
You cannot connect directly to an SQL-server with JavaME.
There might be 3rd party libs available that'll let you do it, but most developers use a middle-link instead:
Have your MIDlet call a server-side script (PHP or ASPX or a Servlet).
http://www.example.com/sqlinterface.php?action=insert&name=John&address=Home
Then your server-script will insert the entry into the database.
Here's an example using a Servlet:
http://www.java-tips.org/java-me-tips/midp/connecting-to-databases-like-mysql-sql-server-or-oracle-on-j2me-de.html

Categories