I receive this exception when I try to run a jar file
java.lang.ClassNotFoundException: javax.servlet.Servlet
The file servlet-api-2.5-6.1.14.jar lives in the same dir as the jar im trying to run.
servlet-api-2.5-6.1.14.jar contains the class javax.servlet.Servlet
Any ideas ?
Thanks
You need to include its path in the Class-Path entry of the MANIFEST.MF file of the JAR you're running. Assuming that both JAR's are in the same folder:
Class-Path: servlet-api-2.5.6.1.14.jar
I only wonder how it's useful to have the Servlet API as a dependeny of a plain Java application.
you would need the servlet apis and any dependent libraries in a web application.
To run a web applicaton, you will "deploy" it on a servlet container or application server like tomcat, jboss, jetty so on. All the libs to run your web app., which you would need in this way are included in your container/container classpaths. You don't have to define them explicitly in your application configs.
If you are working on exclusively an application like an application server, and want to develop a server on yourself, you need to add the servlet library into your app.'s classpath.
Related
i have created a jsp project with webservice in netbeans and i have created a war file to implement it in the AWS but while executing the command "java -jar filename.war it is showing some error
no main manifest attribute, in Hurling_Server.war
root#ip-172-31-21-53:/home/ubuntu# java -jar Hurling_Server.war
no main manifest attribute, in Hurling_Server.war
How you can execute/use the WAR file depends on what it contains and how you have packaged it. WAR files are web archives meant to be deployed in server containers like Tomcat, Jetty, etc.
If this is a regular WAR, deploy it in a server like Tomcat, Jetty and access the web application.
Have you bundled an embedded server like Tomcat or Jetty in the WAR? If yes then most likely it is already executable depending on how you have created the WAR in the first place. If not embedded nay server then, you have to add the MANIFEST.MF under META-INF/. And in the manifest file you have to specify the main class name like:
Main-Class:mypackage1.mypackage2.MyExecutableClass
The WAR structure should look like:
mypackage1/mypackag2/MyExecutableClass
WEB-INF/lib
WEB-INF/classes
META-INF/MANIFEST.MF
With embedded Jetty the MANIFEST and executable main class are placed the following way in WAR:
jetty/bootstrap/JettyBootstrap.class
jetty/bootstrap/LiveWarClassLoader.class
META-INF/MANIFEST.MF
So, why your WAR file is not executing depends on several factors mentioned above. Please check.
I developed a web application using jsp, servlets, oracle database and javascript in eclipse. Now, I am trying to convert its JAR to EXE file using launch4j. Since my application has no main class, while executing EXE it is giving error "no main manifest attribute". What should i do? Help me!
I assume your web application is the standard 'war' format, with a WEB-INF and everything. It can have a web.xml, but not necessary.
You need to write an embedded launcher. Jetty is great for this.
You might even be able to use their start.jar, but writing your own embedded launcher is pretty easy.
https://www.eclipse.org/jetty/documentation/9.3.x/embedding-jetty.html
You write a 'main' function in a launcher class, and set that as your entry point in a runnable jar. You can do this from eclipse using "Export... / Java / Runnable Jar"
Hello I have a webapp in Tomcat server on linux
I need to be able to tell it in what order to load the jars located in WEB-INF/bin.
I tried to set it up in the META-INF/MANIFEST.MF under Class-Path but it didn't work, and I've searched the web for a solution and did not find any.
(My project is not inside a war file)
(The solution to chane the jar filename to "aaaaaaaRealName.jar" is unacceptable)
(I'm using Tomcat 7 (I think its v7.0.27))
Ido
The tomcat loads jars in the following order (extract from here: http://tomcat.apache.org/tomcat-8.0-doc/class-loader-howto.html):
bootstrap (JRE/lib/ext folder)
system (can't used to add yours)
webapp libraries (first WEB-INF/classes, then WEB-INF/lib)
common libraries (check the common.loader property , then tomcat instance/lib, then common tomcat folder/lib)
So if you want to specify the order, just put the jars in the right place.
How I can set a war in an embedded jetty in a way that it can load from a classpath. Following is my current code snippet
webAppContext.setWar("hello.war");
Context :-
I want to secure my code other than obfuscation.so, I used Jetty to create a runnable jar and subsequently i used winrun4j to create an exe wrapper. The exe works fine when war file is found at same level but not otherwise even though i've embedded the war in winrun4j exe.
Problem:-
Is there any way that i can set the war in a way that it can pick it up from classpath rather than some pre-defined path.
Hope i communicated the problem statement in a lucid way.
Thankyou.
I came around the same and I always extract the war to a temporary location and then use the absolute path;
webAppContext.setWar("/path/to/temp/tmp262622522.war");
In any case Jetty will extract the war to a temporary location too, when starting the web app.
I'm trying to use bacnet4j with JSF.
I build an application in .java which turn on/off a lamp, but if I try to call the same method from a JSF page (which communicates with my manage bean) , gives me :
type Exception report
message
descriptionThe server encountered an internal error () that prevented it from fulfilling this request.
exception
javax.servlet.ServletException: com/serotonin/bacnet4j/type/Encodable
root cause
java.lang.NoClassDefFoundError: com/serotonin/bacnet4j/type/Encodable
root cause
java.lang.ClassNotFoundException: com.serotonin.bacnet4j.type.Encodable
But I'm pretty sure that the class is there, because if not my java application don't work, right ?
Any idea why this is happening ?
The JAR file containing this class should go in webapp's /WEB-INF/lib folder.
A plain Java Application does not use the same classpath as a Java Web Application. For a plain Java Application the classpath is usually specified by -cp or -classpath argument in java command, or if unspecified, by %CLASSPATH% environment variable, or if being a JAR, by Class-Path entry in JAR's /META-INF/MANIFEST.MF. For a Java Web Application the classpath covers by default the webapp's /WEB-INF/lib and /WEB-INF/classes folder and server's /lib (and more) folders and any custom folders which you can specify in server-specific configuration, such as shared.loader property of /conf/catalina.properties in case of Tomcat.
NoClassDefFound means that the class was available at compilation but not at runtime. You need to add the jar-file with the appropriate class to your war (or add it to the application server classpath)