Cannot import javax.ejb.* packages - java

I am having trouble in building an EJB session bean.
The following packages cannot be found:
import javax.ejb.LocalBean;
import javax.ejb.Stateful;
import javax.ejb.TransactionManagement;
import javax.ejb.TransactionManagementType;
Some solutions implied adding the libraries j2ee.jar and javaee.jar to the java build path.
I am using jdk-7u75-windows-x64 and java_ee_sdk-7-windows-ml and cannot find any of these libraries at the given location($JAVA_HOME\lib). I am using eclipse(kepler) on a Windows 7 x64 machine

javaee.jar ships with neither eclipse nor java(jdk). The file must be manually downloaded and added to the project build path. The java ee 7 api can be found here.
Alternatively, a maven dependency can be used:
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>7.0</version>
</dependency>

The EJB API is found in the JavaEE libraries which are, as you correctly pointed out, distributed with the j2ee.jar library. If you're using Eclipse, its classpath may be pointing to the standard Java libraries and not the Enterprise libraries. You can try two things:
Compile and run your code from the command line. Set %JAVA_HOME% to point to the installation directory of java_ee_sdk-7-windows-ml and add %JAVA_HOME%/bin to the %PATH%.
Find the Enterprise library and add it to your CLASSPATH in Eclipse. The CLASSPATH is set by going to the project properties and selecting the option "Add an external library/jar file". Add any jar files found in the EE installation directory to the build path.

Related

Importing Libraries not working in eclipse

I have a project that requires me to import a library, and I am doing it in eclipse. I have imported the library, and it doesn't seem to recognize that I have the library imported.
My user libraries.
The build path for the project.
A picture of my java project. The part highlighted corresponds to the import statement.
How can I make it so that eclipse can see that I have the library imported?
I tried changing java versions and also changing the build path as well.
Adding the below Dependency in pom.xml for importing the libraries.
<dependency>
<groupId>org.openpnp</groupId>
<artifactId>opencv</artifactId>
<version>3.2.0-0</version>
</dependency>

how to setup a sqoop2 application project in eclipse?

I'm referencing Sqoop Client API Guide. Inside the guide, it says:
It requires Sqoop Client JAR and its dependencies.
It then lists the maven dependency:
<dependency>
<groupId>org.apache.sqoop</groupId>
<artifactId>sqoop-client</artifactId>
<version>${requestedVersion}</version>
</dependency>
Does that mean I need to setup a maven project with the dependency above? If not, where do I find and download the Sqoop Client JAR and its dependencies?
Thanks much!
This is how I setup right now and it works for now but I highly doubt this is the "official recommended" way:
Download all the required jar files from this link. The link points to jar-download.com and claims to offer sqoop client JAR and dependencies for 1.99.6
unzip the downloaded zip file from above
create a java project in eclipse and "configure build path" then "Add External JARS ..." to include all the jars from downloaded zip file.
So far, I can import the sqoop java api class (i.e., import org.apache.sqoop.client.SqoopClient;) but I haven't tried to build the app.

How to install & import Java "HttpClient" Library

So I'm a C++ Programmer who is trying to learn Java in order to write a client-side https receptor application, corresponding to a particular website.
My Problem:I found this wonderful-looking Java library online, called "HttpClient" (See https://hc.apache.org/httpclient-3.x/tutorial.html).
Unfortunately, the only way to install the library is manually (download a .zip file with all the .jar files in it). I understand that the include paths are meant to look something like this
import org.apache.commons.httpclient.*;
import org.apache.commons.httpclient.methods.*;
import org.apache.commons.httpclient.params.HttpMethodParams;
But I have no idea how to configure the "CLASSPATH" Environment Variable in order to reflect this (please note that I know HOW to set the variable, just not WHAT to set it to).
My Question:
Could someone please explain to me (in laymen's terms) how to download & setup this library onto my Windows 10 PC such that I can implement the above include statements in my code?
You should install a build/dependency management tool such as maven (there are others). Then you will simply need to add the following to your project pom.xml and maven will handle the rest.
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.2</version>
</dependency>
If you'd like to manually handle adding the .jar (and it's dependencies) you can specify "CLASSPATH=path/to/your.jar" or when running use "java -cp path/to/your.jar
If your project is maven then you can add dependencies in pom.xml as say above
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.2</version>
</dependency>
If your project is not a maven type then simply download the jar and add this jar file to the lib Folder. Your dependency will automatically resolved. No bug will raised due to dependency.
all you need to do is put the jar in your project's classpath..This can be done in multiple ways depending upon whether you are using any build tools like maven,gradle etc.
But since you are new to java,I suggest you download the jar from here and extract it and put it into any folder which is added to your classpath.
If you have created a webproject then by default WebContent->WEB-INF->lib is already in your calsspath. So just paste the .jar file into this file and you will be good to go.
If you are using maven or gradle or ivy then refer here: http://mvnrepository.com/artifact/org.apache.httpcomponents/httpclient/4.5.2
N.B.:you don't need to add anything to your windows classpath or modify any path variables of your OS. these are all project specific classpaths. So do it your project. Use a build tool like maven if you wish to access these more easily. Also recommended is to use eclipse or netbeans or some other mordern IDE
Just make sure that each of the .jar files it comes with are in your CLASSPATH.
e.g.
export MY_INSTALL_DIR=/some_dir/httpcomponents-client-4.5.2/lib
export CLASSPATH=$MY_INSTALL_DIR/commons-codec-1.9.jar:$MY_INSTALL_DIR/commons-logging-1.2.jar
and so on... I did the first two CLASSPATH elements above, and you ultimately need one element for each of 10 or so JARs I see in the dist.
Think of the .jar files as something like .so or .dll files - the compiled binaries. Think of this as the equivalent of putting .so or .dll files in your PATH.
In my example, I set the CLASSPATH via environment properties, like a .bashrc file or the like. Since you're on Windows, you would use the Windows environment variables available via the Advanced System Settings control panel. You can also set them via the command line (javac -classpath and java -classpath), via your build tools, or other ways. I found a couple of helpful links that discuss this: this one and this other one.
Long-term, you should learn how to use Maven, like the other answers here suggest, but first get to grips w/ Java basics. Just so you know, Maven is something like nmake from your world, plus the ability to automatically download and manage 3rd party dependencies, plus a whole lot of other features.

How can I import javax.json in eclipse

I have installed eclipse ide for EE developers and I am receiving an import error for
import javax.json.Json;
import javax.json.JsonReader;
etc.
I have right clicked on project folder -> clicked properties -> clicked Java build path -> add library -> JRE System Library,
but the dependencies that show up are already imported. How can I import the javax.json package?
If using Maven, add this dependency to your pom.xml
<dependency>
<groupId>javax.json</groupId>
<artifactId>javax.json-api</artifactId>
<version>1.0</version>
</dependency>
For Gradle, add this to your build.gradle
compile 'javax.json:javax.json-api:1.0'
Going to assume that you are not using Java 7 and thus need to add the JAR file directly to your project path:
Here's the link to the
JAR
And where it came from:
http://jsonp.java.net/
Download and add to your project build path.
You need to get a hold of the Jar from https://java.net/projects/jsonp/
Then got to project folder -> clicked properties -> clicked Java build path -> Add External Jars...
From here you can import the downloaded Jar (library) into your project.
Using javax.json group (what is in the accepted version) doesn't work for me. I get this:
javax.json.JsonException: Provider org.glassfish.json.JsonProviderImpl not found
Instead, what does work for me is the following (put this in the dependencies section of build.gradle if you're using Gradle):
implementation "org.glassfish:javax.json:1.1.4"
To find the latest version of the library, see the library's search.maven.org page.
You will have to download the Jar from https://java.net/projects/jsonp/ as they are not yet part of main Java runtime, download the jar and add it to your classpath and it should work
JSR http://jcp.org/en/jsr/detail?id=353

Android+Ant external jar library

I'd like to try org.apache.commons.lang.StringUtils in my Android project. I have downloaded commons-lang3-3.1.jar and placed it in my project's libs directory. However importing it fails with the library not being found. I have used many variations of
import org.apache.commons.lang.StringUtils;
with no success. My environment is the linux console and I'm using ant to compile, no Eclipse. My understanding is that Ant picks up any library in the project libs directory.
Please help. Android/java coding noob.
Lang 3.0 (and subsequent versions) use a different package (org.apache.commons.lang3) than the previous versions (org.apache.commons.lang), allowing it to be used at the same time as an earlier version. ref: http://commons.apache.org/lang/
import org.apache.commons.lang3.StringUtils;
Just put the jars in the libs/ directory. Silly me, I was putting them in the lib/ directory until I ran into the same issue and found the answer here:
How to build an android app with external libraries using ant?

Categories