Can't execute war - file: "no main manifest attribute" - java

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.

Related

java -jar classpath refers jar inside ear

I have one big app.ear file which contains all my jar. now i am having another healthcheck.jar which will check the database up or not by connecting to database. now database client is inside the ear file, again i don't want to put the client jars(database client, hibernates jars etc) into healthcheck.jar.
is their a way so that i can exclude packaging database client jar from healthcheck.jar and refer it while run time from inside app.ear i'e
java -jar healthcheck.jar -classpath app.ear/hibernate.jar
Both are stored in common folder.
Instead of bundling in the jar file you could add app1jar.jar as an endorsed jar to the container. It's then available to all installed apps.
https://docs.oracle.com/cd/E17904_01/web.1111/e13706/libraries.htm#WLPRG332

Creating war from its component folders

I have deployed my war file on a remote linux server. I run this war using jetty-runner. Its not feasible for me to push this war multiple time. Its size is huge and it takes aprrox 45 min to push a fresh war onto the server. To handle this issue I thought of using the following steps(with commands) :
unzip:Unzip war to its corresponding files/folders : WEB-INF, META-INF, index.jsp.
Updating new class file in WEB-INF.
zip:Repacking these folder into a war again.
But the newly created war does not work. Is there a standard/correct way to pack these files into a war. Also, jar command is not available on the server.
Please suggest.
P.S. Already looked into various SO questions but didn't find any useful solution.
The zip command does not work as expected. The war packed by that command did not work. Instead, we have to use the JAR command.
I was able to generate the war after modifying the contents by using :
jar -cvf webproject.war index.jsp META-INF/ WEB-INF/
Note: If the jar command is not available on the server, specify JAR path using installed java on the server:
PATH_TO_JAVA/bin/jar -cvf webproject.war index.jsp META-INF/ WEB-INF/

How to call a class in war file from another class outside the war file?

how to call a class in war file from another class outside the war file. Iam getting problem when accessing that class from war file how to overcome that problem.
WARs are specifically intended to live in isolation from the other jars/ejbs in the package, they have their own classloader and the wars do not by default reside in the path in any other war, jar, or ejb.
If there is a common functionality this should be moved into a jar that is shared between the artifacts.
You don't... Unless the War refers to a jar that is in both wars...
A war is a collection of jars, as a sort of wrapper...
So make more jars, and import those in different wars
Try to only create classes in a War that are needed for that webservice only... Not helper classes, since they might be necessary for other applications/services
Jar: collection of Java Classes, property files, so that a collection of classes can be ran from within a computer (Wiki on jar https://en.wikipedia.org/wiki/JAR_(file_format))
java -jar xxx.jar
War: Web ARchive (Wiki on war https://en.wikipedia.org/wiki/WAR_(file_format))
is meant to be put inside a webserver (like Tomcat/Jetty) with has a collection of Jars, and configuration information necessary for link with internet... Like REST, JSP, Html...
Ear: Enterprise ARchive (wiki on ear https://en.wikipedia.org/wiki/EAR_(file_format))
Has a collection of War and Jar, run in Application servers like JBoss and GlassFish
Additional War vs ear see .war vs .ear file

How to set a Tomcat webapp classpath

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.

java.lang.ClassNotFoundException: javax.servlet.Servlet

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.

Categories