How to change the classpath or add classpath for Jetty - java

I am deploying a web application in a Jetty container and I need to know how to add a classpath for Jetty to be able to load resources from a testing directory.

I think it's best to not modify the Jetty CLASSPATH; use what you know about the defaults for your web app.
All the JARs in WEB-INF/lib are your web app's CLASSPATH; so are all paths relative to WEB-INF/classes. If you put a directory /test-resources under WEB-INF/classes and load it as a resource stream from the context you'll be able to access those test files without having to alter the Jetty startup scripts.

I find it much easier to keep my test jars in a separate folder where they are built by a different process or IDE.
I extracted start.config from the Jetty jar and added my classpath to it as documented at
http://docs.codehaus.org/display/JETTY/A+look+at+the+start.jar+mechanism

Related

what happens when add to classpath in eclipse or intellij

Can somebody please explain what happens when add some jars to classpath in eclipse or intellij. Is this classpath only for this project/application/jvm?
Thanks.
I know it's for the application to be able to use classes in the jars. What I don't understand is what this classpath is. Is it the same as the classpath in the system environment variables? Is this classpath only for this project/application/jvm? Is it possible for other projects/applications to use this classpath?
I'm working on a project which is based on Grails. And I saw this line in the configuration file.
<import resources="classpath:META-INF/............xml" />
What is the classpath here?
When you add jars to classpath, your application starting with this jars in -cp(classpath) argument. And you will not get ClassNotFoundException when use classes from external jars, that you add to classpath of your project.
When you create web application, jars that you add to classpath, will copy to lib folder of installed application and load by jmv that start your web application.
you get the file name,
When you add jars to classpath, your application starting with this jars in -cp(classpath) argument. And you will not get ClassNotFoundException when use classes from external jars, that you add to classpath of your project.
When you create web application, jars that you add to classpath, will copy to lib folder of installed application and load by jmv that start your web application.
As you can see in this answer

Classpath in java and spring

I am majorly confused about where the classpath is. I understand when we create a spring mvc, resources folder, or inside web-inf is considered classpath. And we can use "classpath:" inside xml files to declare the folder. However, where is this classpath exactly? How is it set ? I have been reading about it for a long time, i still couldnt manage to get a real clear image in my head how the classpath is initially determined etc.
For example when we create a war file, and deploy it on a tomcat server, all the resource files can still be read via given paths with "classpath:" in the xml files. How does this work?
Thanks.
Ok, if it's web application, the classpath begins in WEB-INF/classes. Also, jar files in WEB-INF/lib are also on the classpath.
The Classpath is where the JVM will look for class files and other resources. Since you are using Spring MVC, I assume you are deploying a Web application (ie WAR file). This means that the classpath is set by the container which is following the Servlet spec.
The classpath for a WAR file includes the WEB-INF/classes and WEB-INF/lib folders. The Java EE/Servlet container where the WAR file is deployed will also include other common folders in the classpath.
Here is how Tomcat works.
You might also want to try this StackOverflow article/answer

How do I make tomcat include libs from the current project?

I've read somewhere as a good practice, that it's better to have the required libs included in each project, then just add all the libs you'll ever need to the tomcat folder. Well right now Tomcat seems to need all the required libs to be in lib folder of Tomcat. How can I make it use the libs from the build path of the project? i'm using tomcat 7.032 in through Eclipse.
The libraries of a webapp must be in the WEB-INF/lib directory of the deployed web application directory or war file.
Every jar file in this directory will be in the classpath of the webapp, and won't be in the classpath of the other deployed webapps. You indeed shouldn't put webapp libraries into Tomcat's classpath.

Class Not Found Exception in WebLogic, Fine in TomCat

I am using two servers one is tomcat and other one is WebLogic.
I developed two application, one is Main-Application and second is commons-application.
I added quartz JAR into the commons-application and export it as a JAR and add it in the Main-Application.
For importing quartz JAR into the commons-application I made a lib folder and give the path of it in build path configuration.
Now when I run Main-Application it gives me error that class not found that is associated with quartz.
So I add quartz JAR into the Main-Application too, and run again so it executed fine.
But when I run same configuration in WebLogic it gave me same error(class no found). What am I missing? Do I need to do something else for WebLogic?
Not sure about main method apps, but in web apps we have to provide a preference to our classpath jars.
Weblogic being an app server provides its own jars and other services.
And by default it prefers to use its own jars. So if you want to use your own jars which are in your project's class path then you specifically have to mention so.
Tomcat being a servlet container doesn't have its own jars, so it will by default refer to your libraries.
See the prefer web inf classes.
http://docs.oracle.com/cd/E24329_01/web.1211/e21049/weblogic_xml.htm
<container-descriptor>
<prefer-web-inf-classes>true</prefer-web-inf-classes>
</container-descriptor>
Similar classpath settings should be available for main class apps, I guess.
Also, more importantly, jars should not be embedded into other jars. (I think you are embedding quarts inside other common jar. Main application should have two jars: commonsapp.jar and quartz.jar in its classpath.)

WAR loads differently on weblogic when inside an EAR, why?

How does WebLogic 11g load libraries in an EAR file? I have this problem with a web application, that when deployed as a WAR (with libraries it depends on in WEB-INF/lib), it works just fine. However, when it's inside an EAR file, WebLogic does not find those libraries unless I put them in APP-INF/lib. Does that mean that if I'm deploying as an EAR I'd have to pull out all JAR files from the WEB-INF/lib directory and place them in APP-INF/lib ? or is there a configuration that can be done in WebLogic to avoid this?
Thanks!
If you have JAR files that you need to share between multiple WAR files or between WAR files and EAR files then you will need to package them in the EAR.
If WAR#1 has a JAR in its WEB-INF/lib and is packaged in an EAR with WAR#2, then WAR#2 will not be able to see the JAR files in WAR#1/WEB-INF/lib.
Solving your problem will take some understanding of how Java EE classloading works in a container. You should look at this link to get an understanding, but the basic problem is that when you package your application as an EAR, you've introduced another classloader (the application classloader) into the class loading hierarchy. You can configure WebLogic to load from your webapp by using the prefer-web-inf-classes element.

Categories

Resources