I'm not sure what i'm doing wrong here... i downloaded this sample project which is basically the simplest possible working example of an annotation based controller. I downloaded Tomcat and started the server no problem in eclipse. I downloaded Spring 4.3.7 from here (i'm not using Maven nor do i want to). Added as external JARs under libraries.
When i go run the application i get a ClassNotFoundException for the ServletDispatcher class so i followed the instructions here to resolve this. But when i add the Spring JARs then my server times out with the following error sure enough in the deployment assembly there are being deployed to WEB-INF. So i removed the JARs, and i added them one by one based on the ClassNotFoundException. First i added spring-beans, then context, then webmvc and it seems when i add core this is when the error switches from the ClassNotFoundException to the server timeout error... I'm not sure what to do?
EDIT: Found out that my compiler was set to 1.7 while my JDK was set to 1.8. I changed this and now get a java.lang.NoClassDefFoundError: org/springframework/core/env/EnvironmentCapable error. I tried adding the core JAR but then i continue to get the server timing out error.
In Project Properties.
Check your java build path it should contain
JRE system library: JDK 1.7 or above
Server Run time: Tomcat
Check your Java Compiler
It should be 1.7 or above
You need to add the Java build path in the Deployment Assembly
1) Right click on your project, select Properties
2) Select Deployment Assembly. Click Add button.
3) Click on "Java Build Path Entries"
4) Select yours jars
5) click Finish
Clean build your project and restart tomcat.
Related
I downloaded Eclipse Luna and Tomcat 8.0.24 some months ago but I started using it. I've been creating a web app without Maven. I downloaded manually Jersey 2.23, Jersey media moxy 2.23, java-son 1.0 , jdbc mysql 5.x and sql2o 1.5.4. I'm starting to learn Angular and I successfully created one page without any issue.
I remember have added my jars manually in the Build Path of my project and I was forced to add them in the Deployment Assemblies also. Fine.
Since 2 weeks I didn't shutdown my laptop, just in sleep mode. But yesterday I did shutdown. Since then I suffered to make it work again. I use postman chrome to test my restful services and I received after the shutting down the 404 error.
I realized that I started to see the exception in the console:
java.lang.ClassNotFoundException: org.glassfish.jersey.servlet.ServletContainer
I deleted my folders of tomcat and eclipse to start again from scratch desperately. However, I got the same issue. The last thing that I remember I was playing with, were these modified options.
Double click in server from servers tab
Change from Use workspace metadata to Use Tomcat installation
Properties in Server
Switch Location from metadata to localhost.server
It was thanks to these questions that I solved my issue:
org.glassfish.jersey.servlet.ServletContainer ClassNotFoundException
java.lang.ClassNotFoundException: org.glassfish.jersey.servlet.ServletContainer
Now, after "reinstalling" eclipse and tomcat, when I add the jars in the library tab, they are now added in deployment assemblies automatically. (Surprised)
According to the previous attached questions, I added all the jars in WEB-INF/lib from my workspace as also in the tomcat/wtpwebapps/myproject/WEB-INF/lib. If I don't do this, I won't be able to make it work. Postman finally gives me the desired output.
Nevertheless, I realized when I copy the jars manually through windows explorer, the console in Eclipse displays the tomcat restarting again. BUT I still see the exception: java.lang.ClassNotFoundException: org.glassfish.jersey.servlet.ServletContainer. At least I can run my project in the browser or in postman without any issue. Very strange.
I want to add a new User Library in Windows > Preferences > Java > Build Path > User Libraries, but my list is EMPTY!!! So...
Finally, my questions:
What's going on with Eclipse?
Why am I not able to see my user libraries previously added?
Why do I still see the exception of glassfish.jersey in the console if I added the jars in the web-inf folder which makes it work apparently.
Why do I need to add the jars in web-inf, if when I see all the jars included in the Tomcat library all my jars are there because I forgot to mention that I added a folder called External in lib of my Tomcat folder.
For all these changes, I restarted Eclipse
Instead of adding jars manually, use maven and let the maven manage dependency of jars.
ClassNotFoundException occurs when you don't have a jar in the classpath. Maybe the package you are deploying on the server is not bundled correctly. Make sure you have jar bundled in your package or present in the classpath.
Another reason could be you have duplicate class files in two jars and the class your programme picking is not suitable.
I am trying to connect to mysql database using java on windows7. In spite of adding the complete url of jdbcdriver jar file in CLASSPATH, java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
is thrown. Could anyone tell me what i am missing here? It works if I add the jar file in project library but I want to do it by CLASSPATH itself.
My classpath looks like this-
C:\jython2.5.1\javalib\mysql-connector-java-5.1.12-bin.jar
I want to make it clear that this is not the actual project i am working on. I am actually using Django with Jython, which requires the JDBC driver to access the database. That is the reason why I have to do it using CLASSPATH only.
The CLASSPATH environment variable is only used by the java.exe command and even then only when used without any of the -cp, -classpath, -jar arguments. It is ignored by IDEs like Eclipse, Netbeans and IDEA.
That environment variable is in real world also considered a poor practice since it breaks portability. I.e. program X will run successfully while program Y won't run without altering the CLASSPATH. It's only "useful" for Sun Oracle to prevent that starters get tired of typing the same classpath again and again in the -cp or -classpath arguments when following Java tutorials. In real world, batch/shell files are preferred where just the entire command with -cp/-classpath argument is specified.
In your case you're using an IDE. The classpath is there called the "Build Path". In plain Java projects, it represents both the compiletime and runtime classpath. You can configure it in the project's properties. You can add a complete folder, you can add individual/external JAR files, you can link projects, etcetera. Make use of it. Forget about using the CLASSPATH environment variable. It was a mistake by Sun Oracle. They thought to convince starters, but it ended up to be only more confusing to starters as they incorrectly interpret that environment variable as the classpath.
See also:
How to add JAR libraries to WAR project without facing java.lang.ClassNotFoundException? Classpath vs Build Path vs /WEB-INF/lib
What finally helped me out was to copy the mysql-connector-java-5.1.15-bin.jar to \jre\lib and to \jre\lib\ext both(!) even though I did all the classpathing circus Java offers :) Environment was pure notepad/commandline though.
What worked with me using Netbeans was:
Run > Set Project Configuration > Customize.
Under Libraries > Add Library. Added MySQL JDBC Driver (I assume it appeared in list because I copied the jar file to the jre\lib\ext folder.
And it worked seamlessly.
I tried setting classpath but that did not work. I am using Netbeans 7.0
simply do a right click on your project in "Netbeans" select properties then click on "libraries " then click on "add library..." button then select "MySQL JDBC Driver" and click on "add library" button then on "OK" button
I also had this problem before, but after I put/added mysql-connector-java-5.1.34-bin.jar (Download it from here) into the apache-tomcat-8.0.15\lib folder, and then ran my project, it really did work.
Note : Even after adding the jar file the error persists, then restart the Tomcat server and rerun you project again.
Open Netbeans IDE
Right-click your Project.
Select Properties.
On the left-hand side click Libraries.
Under "Compile" tab - click Add Jar/Folder button.
Select Downloaded "mysql-connector-java-5.1.25-bin.jar" file (Download Connector/J from dev.mysql.com)
Click OK
Run Again... Its work.
If you are using maven, add the dependency to pom.xml should solve the problem.
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.36</version>
</dependency>
In Netbeans IDE just Check the properties of Project on which you working on,in properties window go to 'library' tag, in diolog box just add your mysql-connector-java-**.jar file.
I had this same problem in Netbeans. Because I was using a tomcat connection pool as defined in context.xml I needed to add the jdbc jar to both the project (Properties->Libraries) and to the lib/ folder within my Tomcat server so it could be seen on startup.
I have a java based web application, which has certain java files and due to some need, i have added some jar files with in the project and made it project specific.
Now, While deploying them in production, I see, that the web file server (tomcat6) already has those jar files in its global library. Now, How do i remove reference of that jar file it, with out disturbing my code(which is working fine).
I saw in other article saying we just have to change the build path to refer the global library instead of local library.
Finally I have 2 questions.
How to do this?
If i'm working on windows and using path while configuring the build path, will it not be a problem if i deploy it in Unix environment.?
Please suggest. Also, its the problem with servlet-api.jar.
I use eclipse IDE. So how to perform these changes in eclipse?
Open your web project in eclipse and right click on the project. click on Properties and then choose build path and remove the jars you want to remove under the tab 'Libraries' and then export the war and deploy it in your tomcat6 server. if you want to run your web application in eclipse, you have to configure the server libraries by clicking 'Add Library' button in build path and then choose server runtime and choose the tomcat6 server configured in eclipse. Hope this helps
I am getting an error when I try to build my project in NetBeans. I am using JBoss 5.1.0 server and have attached that to my project. The error is -
The following error occurred while executing this line:
.../myPath/build-impl.xml:176: The Java EE server classpath is not correctly set up - server home directory is missing.
Either open the project in the IDE and assign the server or setup the server classpath manually.
For example like this:
ant -Dj2ee.server.home=<app_server_installation_directory>
I am using Mac OS X Lion.
I was missing a library. When I right clicked the project and went to libraries, it showed me library missing. I added the library and did a clean and build and the error disappeared
Clean builds did not help me, either. I took a look at project.properties and found that j2ee.server.home was not set anywhere, although j2ee.platform.classpath depends on it.
I do have Weblogic Server set up under /home (on a Linux machine).
So, I closed the project and added a line to project.properties:
j2ee.server.home=/home/blister/wls/wlserver
(where wlserver = the server name)
And reopened the project. Presto, the app now builds. It still doesn't know where the app server is, but at least I can built my jar and can worry about deploying it later. (I tell it to build a war which deploys nicely to Weblogic.)
If you are using netBeans Ide, then right click on the project. click properties. in the properties menu select Run. in that the first text box is server. There select the server. with which u want to run the project. If the server details are not configured before. configure server details and try. it wil help you to solve the above problem.
This worked for me.
Right click on the Project -> Properties -> Run
And Change the server Setting from the current server to another sever and click OK.
Wait for any background scanning to finish.
Repeat the processes 1 to 3 again this time selecting the actual server you want to run the code on.
Then try Re-Running your application.
I also had this error. However despite adding servers in the Run section of the Properties window, repeatedly no servers showed as being available to add to the Project ( again within the Run section ). The solution to being able to see a server in this server list was to run Netbeans as an admin ( which I saw Rotunba referencing in this thread..It was then possible to add a server and the project built successfully..
I solved it like this, I added in the ANT properties field
"j2ee.server.home=http://localhost/"
tolls>options>java>Ant
this in linux netbeans
It could also be as simple as not running your IDE i.e. netbeans as an administrator on your machine. I had the same problem. Wasted some time.
I am trying to connect to mysql database using java on windows7. In spite of adding the complete url of jdbcdriver jar file in CLASSPATH, java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
is thrown. Could anyone tell me what i am missing here? It works if I add the jar file in project library but I want to do it by CLASSPATH itself.
My classpath looks like this-
C:\jython2.5.1\javalib\mysql-connector-java-5.1.12-bin.jar
I want to make it clear that this is not the actual project i am working on. I am actually using Django with Jython, which requires the JDBC driver to access the database. That is the reason why I have to do it using CLASSPATH only.
The CLASSPATH environment variable is only used by the java.exe command and even then only when used without any of the -cp, -classpath, -jar arguments. It is ignored by IDEs like Eclipse, Netbeans and IDEA.
That environment variable is in real world also considered a poor practice since it breaks portability. I.e. program X will run successfully while program Y won't run without altering the CLASSPATH. It's only "useful" for Sun Oracle to prevent that starters get tired of typing the same classpath again and again in the -cp or -classpath arguments when following Java tutorials. In real world, batch/shell files are preferred where just the entire command with -cp/-classpath argument is specified.
In your case you're using an IDE. The classpath is there called the "Build Path". In plain Java projects, it represents both the compiletime and runtime classpath. You can configure it in the project's properties. You can add a complete folder, you can add individual/external JAR files, you can link projects, etcetera. Make use of it. Forget about using the CLASSPATH environment variable. It was a mistake by Sun Oracle. They thought to convince starters, but it ended up to be only more confusing to starters as they incorrectly interpret that environment variable as the classpath.
See also:
How to add JAR libraries to WAR project without facing java.lang.ClassNotFoundException? Classpath vs Build Path vs /WEB-INF/lib
What finally helped me out was to copy the mysql-connector-java-5.1.15-bin.jar to \jre\lib and to \jre\lib\ext both(!) even though I did all the classpathing circus Java offers :) Environment was pure notepad/commandline though.
What worked with me using Netbeans was:
Run > Set Project Configuration > Customize.
Under Libraries > Add Library. Added MySQL JDBC Driver (I assume it appeared in list because I copied the jar file to the jre\lib\ext folder.
And it worked seamlessly.
I tried setting classpath but that did not work. I am using Netbeans 7.0
simply do a right click on your project in "Netbeans" select properties then click on "libraries " then click on "add library..." button then select "MySQL JDBC Driver" and click on "add library" button then on "OK" button
I also had this problem before, but after I put/added mysql-connector-java-5.1.34-bin.jar (Download it from here) into the apache-tomcat-8.0.15\lib folder, and then ran my project, it really did work.
Note : Even after adding the jar file the error persists, then restart the Tomcat server and rerun you project again.
Open Netbeans IDE
Right-click your Project.
Select Properties.
On the left-hand side click Libraries.
Under "Compile" tab - click Add Jar/Folder button.
Select Downloaded "mysql-connector-java-5.1.25-bin.jar" file (Download Connector/J from dev.mysql.com)
Click OK
Run Again... Its work.
If you are using maven, add the dependency to pom.xml should solve the problem.
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.36</version>
</dependency>
In Netbeans IDE just Check the properties of Project on which you working on,in properties window go to 'library' tag, in diolog box just add your mysql-connector-java-**.jar file.
I had this same problem in Netbeans. Because I was using a tomcat connection pool as defined in context.xml I needed to add the jdbc jar to both the project (Properties->Libraries) and to the lib/ folder within my Tomcat server so it could be seen on startup.