Trying to install glassfish-3 for Java EE 6 tutorial examples - java-ee-6

I am trying to install glassfish-3 with NetBean. The tutorial page below asks me to install Java EE 6 SDK first, which I did.
http://docs.oracle.com/javaee/6/tutorial/doc/gexaj.html
But I am unable to find the location of Java EE 6 on my PC. Any idea how I might find it?

Download Glassfish from here https://glassfish.java.net/downloads/3.1.2.2-final.html
download a version of choice , on Netbeans , under Services, right click server, and add server,choose glassfish and select install location,admin ports and http port. jee6 comes shipped in Glassfish module if you are using an ANT project. I will advice you use maven project , add this your dependency pom as this using maven allows you to use specific jee dependency.
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>7.0</version>
<scope>provided</scope>
</dependency>

Related

Apache Beam maven dependencies: jdbc package is not downloaded in skd jar file

Downloaded maven dependecies in eclipse using
<dependency>
<groupId>org.apache.beam</groupId>
<artifactId>beam-runners-direct-java</artifactId>
<version>0.3.0-incubating</version></dependency>
<dependency>
Only org.apache.beam.sdk.io,Only org.apache.beam.sdk.io.range are downloaded.
but .io.jdbc is not being downloaded in dependencies.
Is there any other specific artifactId I have to use for this other than the above mentioned?
Apache Beam (incubating) publishes several convenience binaries to Maven Central Repository with every release.
There isn't an artifact that captures the whole project. Instead, you should be using specific components that you actually need (perhaps core SDK, any additional libraries, and a runner).
Specifically, if you'd like to use Beam's JDBC connector, depend on the following artifact (among other things):
<dependency>
<groupId>org.apache.beam</groupId>
<artifactId>beam-sdks-java-io-jdbc</artifactId>
<version>${some_version}</version>
<dependency>
Also, we are currently adding Quickstart to our webpage, which will cover some of this information. At this moment, this is still work-in-progress.
You can Directly Download the jar file and put it into your project library. The link to download is-
Org.apache.beam.sdk.io.java.jdbc

How to run jersey-examples-helloworld-webapp in netbeans 7.4

I did as oracle documentation said...build and run...but it asked me to select deployment server.
Then I selected glassfish server 4.0(The only choice); however this project couldn't run.
I found it newly created a glassfish-web.xml in folder WEB-INF(the project already had web.xml there before).
I thought may be it just didn't connect the project with the server well.
for me it helped to update the pom.xml to omit 2.x compatibility and restart the glassfish domain.
Thanks
Richard
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<!--artifactId>jersey-container-servlet-core</artifactId -->
<!-- use the following if you don't need servlet 2.x compatibility -->
<artifactId>jersey-container-servlet</artifactId>
</dependency>
Removing the jersey-container-servlet-core.jar from the web-inf/lib folder solved this problem for me.

The import javax.persistence cannot be resolved

I'm currently working on a project that requires EntityManager EntityManagerFacotry and Persistence each from the javax.persistence package. It seems to be for the database service, but the current code is not very well documented. By searching google it seems that there should be an xml file that comes along with this, but there isn't one of those either. I guess my question is simply how do I make these unresolved imports go away? Do I have to add another jar to the build path? It seems that I shouldn't have to since it's been around since 1.5.
Any help is greatly appreciated.
I ran into this same issue and realized that, since I am using spring boot, all I needed to do to resolve the issue was to add the following dependency:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
Yes, you will likely need to add another jar or dependency
javax.persistence.* is part of the Java Persistence API (JPA). It is only an API, you can think of it as similar to an interface. There are many implementations of JPA and this answer gives a very good elaboration of each, as well as which to use.
If your javax.persistence.* import cannot be resolved, you will need to provide the jar that implements JPA. You can do that either by manually downloading it (and adding it to your project) or by adding a declaration to a dependency management tool (for eg, Ivy/Maven/Gradle). See here for the EclipseLink implementation (the reference implementation) on Maven repo.
After doing that, your imports should be resolved.
Also see here for what is JPA about. The xml you are referring to could be persistence.xml, which is explained on page 3 of the link.
That being said, you might just be pointing to the wrong target runtime
If i recall correctly, you don't need to provide a JPA implementation if you are deploying it into a JavaEE app server like JBoss. See here "Note that you typically don't need it when you deploy your application in a Java EE 6 application server (like JBoss AS 6 for example).". Try changing your project's target runtime.
If your local project was setup to point to Tomcat while your remote repo assumes a JavaEE server, this could be the case. See here for the difference between Tomcat and JBoss.
Edit: I changed my project to point to GlassFish instead of Tomcat and javax.persistence.* resolved fine without any explicit JPA dependency.
If anyone is using Maven, you'll need to add the dependency in the POM.XML file. The latest version as of this post is below:
<dependency>
<groupId>org.hibernate.javax.persistence</groupId>
<artifactId>hibernate-jpa-2.1-api</artifactId>
<version>1.0.0.Final</version>
</dependency>
hibernate-distribution-3.6.10.Final\lib\jpa : Add this jar to solve the issue. It is present in lib folder inside that you have a folder called jpa ---> inside that you have hibernate-jpa-2.0-1.0.1.Final jar
When I ran into this problem, I tracked down enough to fix my problem and move on.
The short version is:
At some point in time Oracle open-sourced J2EE code and the Eclipse foundation took it over.
The transition took a while so information came out during the transition which was transitory in nature. As a result, you might find articles that were only useful during the transition.
The javax.persistence package was moved to a newly named dependency (jakarta.persistence. The persistence package is part of the larger JPA (Java Persistence API). See Intro to JPA.
The Java Persistence API was first released as a subset of the Enterprise JavaBeans 3.0 specification (JSR 220) in Java EE 5. It has since evolved as its own spec, starting with the release of JPA 2.0 in Java EE 6 (JSR 317). JPA was adopted as an independent project of Jakarta EE in 2019. The current release as of this writing is JPA 3.1.
There were issues with SpringBoot pulling in multiple javax.persistence dependencies, Spring-Boot Issue 21220.
Spring and SpringBoot updated their dependencies to use the new location. From Infoq.com, Nov 24, 2022
VMware released the long-anticipated Spring Framework 6 and Spring Boot 3. After five years of Spring Framework 5, these releases start a new generation for the Spring ecosystem. Spring Framework 6 requires Java 17 and Jakarta EE 9 and is compatible with the recently released Jakarta EE 10
If you are on this page looking for answers, most likely it's because your code doesn't compile because it can't find javax.persistence. If this is the case, then you'll either need to:
add the dependency to jakarta.persistence.
Or use older versions of Java and JPA dependencies define classes in the javax.persistence package.
In the future or if you choose to you can rename references from javax.persistence to jakarta.persistence. The same class files in javax.persistence also exist in the jakarta.persistence package.
To fix my problem I added the following dependency:
<dependency>
<groupId>jakarta.persistence</groupId>
<artifactId>jakarta.persistence-api</artifactId>
</dependency>
I was using SpringBoot 2.2.2.RELEASE af the time which picked up version 2.2.3 of the jar file (jakarta.persistence-api-2.2.3.jar).
This jar file contained (at least) the following packages:
javax.persistence
javax.persistence.criteria
javax.persistence.metamodel
javax.persistence.spi
based on what my IDE is telling me.
The following articles were helpful for me to get to the solution I needed:
The SO question about this and the answer - https://stackoverflow.com/a/60024749/3281336 which pointed to links I've also included below. Thanks to #Krisz for that.
Explanation of why javax.persistence package was moved to jakarta dependency - https://blogs.oracle.com/javamagazine/post/transition-from-java-ee-to-jakarta-ee This article is good because it gives old dependencies along with the newer dependencies that are needed
SpringBoot 3 & Spring Framework 6 use Jakarta EE 9 - https://www.infoq.com/news/2022/11/spring-6-spring-boot-3-launch/
My solution was to select the maven profiles I had defined in my pom.xml in which I had declared the hibernate dependencies.
CTRL + ALT + P in eclipse.
In my project I was experiencing this problem and many others because in my pom I have different profiles for supporting Glassfish 3, Glassfish 4 and also WildFly so I have differet versions of Hibernate per container as well as different Java compilation targets and so on. Selecting the active maven profiles resolved my issue.
I solved the problem by adding the following dependency
<dependency>
<groupId>javax.persistence</groupId>
<artifactId>persistence-api</artifactId>
<version>2.2</version>
</dependency>
Together with
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jdbc</artifactId>
</dependency>
If you are using Gradle with spring boot and spring JPA then add the below dependency in the build.gradle file
dependencies {
compile group: 'org.springframework.boot', name: 'spring-boot-starter-data-jpa', version: '2.1.3.RELEASE'
}
In newer hibernate jars, you can find the required jpa file under "hibernate-search-5.8.0.Final\dist\lib\provided\hibernate-jpa-2.1-api-1.0.0.Final". You have to add this jar file into your project java build path. This will most probably solve the issue.
Add this to your dependency if your using maven
<dependency>
<groupId>javax.persistence</groupId>
<artifactId>javax.persistence-api</artifactId>
<version>2.2</version>
</dependency>
If you are using Hibernate as a JPA implementation and you are not using Maven/Gradle, the easier way is to download whole bundle instead of jar file one by one.
Go http://hibernate.org/orm/downloads/ and download the latest library, extract the jar from the required folder.
Sad and ashamed to say that after spending 1 hour on same problem (unable to resolve #Entity and javax.persistence) occurring on STS/Eclipse and with all the imports (implementation 'org.springframework.boot:spring-boot-starter-data-jpa'). Turns out it was issue with STS/Eclipse IDE because exactly same code worked on IntelliJ IDE. If nothing works give another IDE a go.
If you are not using Maven/Gradle to import the dependency, simply just download this jar from maven repository and set in build path on Eclipse or your preferred IDE.
https://mvnrepository.com/artifact/javax.persistence/javax.persistence-api/2.2

Tomcat goes to .m2 directory for the jsp, servlet, etc. jars and crashes

I am having trouble getting Tomcat to run JSPs on my maven-enabled project (Eclipse 3.7 with latest m2 plugin on Tomcat 6, running as a server in Eclipse Java EE):
java.lang.NullPointerException
at org.apache.jsp.index_jsp._jspInit(index_jsp.java:22)
This error indicates that the Tomcat-supplied jars for JSP, servlet, etc. are clashing with project jars. It does appear that everything is set up properly, though:
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>jsp-api</artifactId>
<version>2.1</version>
<scope>provided</scope>
</dependency>
If I turn on class tracing on the VM, I see that upon startup the jsp jar from Tomcat's lib directory is being used for JspFactory:
[Loaded javax.servlet.jsp.JspFactory from file:/C:/tomcat-6.0.28/lib/jsp-api.jar]
When the server is up and I'm ready to hit the jsp page for the first time, however, I get a different result:
[Loaded javax.servlet.jsp.JspFactory from file:/C:/Users/alice/.m2/repository/javax/servlet/jsp/jsp-api/2.1/jsp-api-2.1.jar]
So, for some reason that is beyond me, the jsp jar from the m2 repo is being used by the web application, even though the scope in the pom.xml is set to provided. I've exhausted google searching. What other configuration issues might be causing this problem?
Over the last several years, I've regularly seen all sorts of configuration-related issues with the Tomcat Eclipse plugin.
I'd suggest doing yourself a huge favor - dump the plugin. Run a standalone Tomcat.
It's not that hard to do.
It's also easy to configure Tomcat to point to the war file that Eclipse builds, so that you don't have to explicitly deploy it.
It's also really easy to set up debugging of a standalone Tomcat instance.
The upside is that you don't have to deal with vagaries of the plugin, and generally speaking, stuf just works. As far as I can tell, there is no downside.

Maven and dependency

I cannot quite understand what we need maven for and what dependency is.
Could anyone explain in simple words what means? Where does it look for them?
When writing:
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>eclipselink</artifactId>
<version>2.0.0</version>
</dependency>
It tells:
Missing artifact org.eclipse.persistence:eclipselink:jar:2.0.0
What does it mean?
I have 2 versions of maven installed on my system - one for the cmd, the second one as a plugin for eclipse. What is the difference? Which way is it more common to use Maven - from the cmd or from eclipse?
And I read somewhere that maven needs connection to the internet - what is that for?
I guess you are newbie to Maven, I would suggest you to go through the following links
What is Maven?
DeveloperWorks article
Article in Java World
More Maven articles
Maven is a build tool (like ant) which can pull specific versions of libraries and other dependencies from an online server. If you want to use methods which are in a library (even an older version of it) you don't need to install the library on your computer, maven will grab the specified version and store it for you. You can even have two projects which use two different versions of the same library and not have any conflicts, as maven will handle all the libraries for you.
The code you have specifies that you will be using version 2.0.0 of the eclipselink library. Maven will search for that version of that library, first in its cache of libraries and then in the online database, and compile your code along with the library, so your classes have access to the library methods.
I don't think either the command line or eclipse plugin are more popular - I use mostly command line but have both installed.
As to why maven is indicating that your dependencies is missing, you can use http://mvnrepository.com to find dependencies in the maven central repository. Searching for "org.eclipse.persistence" reveals that might actually be needing:
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>javax.persistence</artifactId>
<version>2.0.0</version>
</dependency>