I've build a spring-based web project in Eclipse using Maven. Dependencies and class path are correct and the deployment assembly also lists spring-web*.jar correctly. However, when I deploy it using WebSphere 8 from within Eclipse the mentioned JAR file is missing from the created libs folder under .metadata.plugins\org.eclipse.wst.server.core\tmp2*\WEB-INF\lib . This JAR however is listed under the module section as a submodule for the container. I wasn't able to find out, why this JAR is listed there and why it is not copied to the LIB folder.
It works with a Tomcat server, it works when I export the WAR and deploy it manually and it also works when I manually copy the JAR to the lib folder.
Q1: Is this specific to Websphere?
Q2: Why is SPRING-WEB listed as submodule and what effect has this?
Q3: How can I automatically deploy it correctly?
This seems to be a bug in WAS as reported here
You can either copy the missing JARs manually or you can use the "Run server with resources on server" option in the "Publishing settings for WebSphere Application Server" server settings.
Related
I'm developing a web application in JBoss in Eclipse Luna using external jars. I have imported the jars clicking on Project => Properties => Build Path => Add External Jars. Because the web application will need to use those jars, i have placed them in the MyApp.war/WEB-INF/lib folder, so, when the webapp will be finished, i'm sure i can just export the .war folder and deploy it on another server.
1) The problem is that everytime i turn on my pc in the morning, the deployment process gives me a ClassNotFoundException. I see that the external jars are no longer in their place. As far as i know, i'm not using any plugin to manage dependencies (i'm a newbie on webapps)
EDIT:
2) what i do is unpack my zip containing the jars again in the lib folder. Strangely, if i unpack them in a subfolder (for example, i place the jars in lib/httpcomponents/lib) JBoss cannot find the jars. What's the reason?
Try to inserting the external jar files in to jboss server lib directory (jboss\server\default\lib)
I have a project which in the meantime runs locally on Tomcat but I'm planning to deploy to some server in the future.
I have a few questions:
I'm using tomcat-jdbc.jar. How should I include that jar in the project? copy it to WEB-INF/lib or add a library reference to tomcat? is the latter portable? Can I use this jar even if the server I'm deploying to is using jetty?
When I added the JRE, eclipse asked me to point it to the JRE path. The line that was added in the classpath was
classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"
How does eclipse figure out from this line where the JRE is at?
When the project is deployed to the server, how would the project hierarchy look like?
My guess is:
<project name>
----<build> (.class files)
----<WebContent>
--------<META-INF>
------------MANIFEST.MF
--------<WEB-INF>
------------<lib>
----------------external_jar.jar
------------web.xml
---------index.html
Is this correct? if so, how will the runtime know where to find the JRE? or the tomcat-jdbc.jar which is in the Tomcat installation folder?
Your application needs the following three types of "resources"
System Resources: JRE classes, some extensions/libraries provided by the server you deploy on.
Your dependencies: Any libraries you use, say common-utils, poi etc. These JAR files go in your web-inf/lib folder
Your classes. These are deployed with the WAR file at web-inf/classes
So, to answer your questions:
If you are deploying to Tomcat, the tomcat-jdbc.jar will be provided. Take care of the version though. If your prod server will be tomcat but dev is say Jetty, then you need to provide this jar in your local IDE, but not export it in the WAR file. But if you are developing on tomcat and say deploying on some other server, then this jar has to be bundled with your war file (web-inf/lib folder). Dev and Prod servers need not be same, but take care of the JRE version and dependency on Prod server provided libraries.
JRE is a configurable setting for your server and also your IDE (Eclipse)
Project hierarchy is correct, but you will most probably deploy as WAR file, so your build folder is exported in web-inf/classes. You can verify by opening the WAR file with any zip editor.
Regarding the portability of tomcat-jdbc.jar
Unfortunately this depends on the tomcat library and version. There might be more dependencies of this jar file which might cause problems later on. I would recommend not relying on this jar unless you plan to deploy on tomcat.
you should test your application with the same server you're going to use in production.
to see and set the jre properties eclipse->preferences->java->Installed JREs.
If you export a war file, all files in WebContent will be in the war and the .class files from src folder will be in WEB-INF/classes.
When you uses a server like tomcat, it uses the configuration you setted on it.
If you want the application to always reference your jar, put it in the web-inf lib.
As Daniel has mentioned below,eclipse gets the JREs from the installed JREs under the preferences tab. You can have multiple JREs installed and configured in your eclipse and then select individually for a project and also select default.
3.Your project hierarchy is correct. The runtime will get the JRE from the JAVA_HOME environment variable set on the server.
1) Pool connections, it's a service provided by Application Server (Tomcat in this case). IMHO you have to avoid bind your application with specific implementation, in that case use generic javax.sql.DataSource for expample, and then "inject" or lookup the implmementation from the server. Then if you use Jetty, configure what you want as connection pool implementation https://wiki.eclipse.org/Jetty/Howto/Configure_JNDI_Datasource
So dont´t include in your web-inf/lib tomcat-jdbc.jar.
2) The "org.eclipse.jdt.launching.JRE_CONTAINER" it's a internal variable of eclipse and the value is what you configure on eclipse properties. It's used for eclipse to compile and run your app.
3) in your project structure ".class" files, must go in "WEB-INF/classes". That it's defined by servlet specification. Eclipse automatically generate the correct structure if you select yor project and with right click run "Export" --> "War file". Or you can use maven.
I have a web project in STS, that iam looking to deploy in Tomcat. The build file for the project is written in GRADLE. Using GRADLE'S build script, a war file is generated in build/libs.
But STS looks for the war file in workspace/metadata/plugins/org.eclipse.wst.server.core/ folder.
Now If I manually copy the generated WAR file from build/libs to this workspace/metadata/plugins folder, and then start the tomcat, everything works fine but I am not able to debug using breakpoints in STS.
How do I make sure that the war file from build/libs gets moved to workspace/metadata/plugins folder?
And, Why is STS looking to find the war in workspace/metadata/plugins folder. As the app-server is tomcat, should it not be looking in Tomcat/webapps folder to find the war?
I am not a eclipse fan nowadays but did you run eclipse plugin? you can add it to the gradle file
apply plugin: 'eclipse'
and then just run
gradle eclipse
check Eclipse Plugin
I don't believe STS deploys/runs your war file directly. That is, if you select the project and say "Run on Server", STS/eclipse will generate an exploded war to the wtp.deploy directory defined. You can control/alter this by editing the "run configuration" for your server. Just go to the "Arguments" tab and change the setting for the "-Dwtp.deploy".
You should really only use this STS mechanism for development purposes - as it is invaluable for that. To deploy an actual warfile to Tomcat you have a variety of options. You can start a tomcat instance with the manager UI enabled and upload the war file from the Tomcat GUI, you can just manually drop the war file into Tomcat's deployment area, or probably your best option - extend your gradle build scripts to include deploying the generated war file to a tomcat server. Hope this helps some.
I have a java web project in eclipse and want to define a tomcat server.
It seems that in the tomcat server I must define again my classpath. How can I tell tomcat to just use the classpath from my project (shouldn't this be obvious?).
Unfortunately my jars are scattered all around and it is an headache to add them one by one to my tomcat configuration and maintain this.
Here you go :
Run -> Run Configurations... -> Classpath
You don't have to tell tomcat to look for jars scattered all around the places. This can be easily taken care by eclipse. Configure your eclipse build path properly. Create Libraries (in eclipse) and group jar together. Try to export the war and check if eclipse is packaging all the required jars in WEB-INF/lib.
No, Tomcat and web apps have a pretty well-defined CLASSPATH. You shouldn't have to specify anything if you package your app properly:
All the packages and .class files in WEB-INF/classes are in CLASSPATH.
So are all the JARs in WEB-INF/lib
You should figure out how to put your JARs in the right place - that's WEB-INF/lib of your WAR file. Maybe Ant or Maven can help you.
Summary
Classes from 3rd party jar files are accessible when added to build path while running a standalone JUnit test, but "ClassNotFoundException" when accessed through plain old java objects from within a dynamic web project.
IDE used: Eclipse
Web Server: Apache 7
Details
My project required a lot of 3rd party jars, namely sqlite, eclipse jdt & jsoup. I had created this project as a standalone project and all the classes from the jars were accessible fine.
But now I have copied the entire "src" folder into a "dynamic web project". I have created a folder "jars" which contains all these 3rd party jars and ensure that all of these are added to the build path by following these steps:
Project properties --> Java Build Path --> Libraries --> Add jars --> Select all the jar files from jars folder.
These jars are accessible fine when I run a standalone JUnit test inside the web project. Note that this junit test does not require a server by any means.
But when I try to "Run on Server.." , I keep on getting ClassNotFoundException like these for all the 3rd party classes:
java.lang.ClassNotFoundException: org.sqlite.JDBC
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1672)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1517)
I'm sure this has got to do something with my lack of knowledge of how applications are deployed on the web.
The runtime classpath can be different from the build classpath. Create an explicit launch configuration. The default will start with the build classpath but you may have to manually tweak it to include those 3rd party jars.
I've run into this problem before with Eclipse and the Web Server Tools project. Check your .settings files and other files for configuring the plugins that you're using with your project. You may have to remove some filters in the Eclipse view. WST constructs its build path differently, so it may not be using the jars that you've included in your project.
I figured it out. I just had to put all the jars in the WEB-INF/lib directory. I assumed that Eclipse would do all the required settings for me when I asked it to use the mentioned jars. But I guess there are somethings that are not automated very well.