5

So I was given a WAR 'file', but upon downloading it I noticed that it is actually a folder, not a WAR file. Trying to open this folder in Netbeans is not working, because it is expecting a war file, not a folder.

I attempted "War-ing" the folder, which worked. Netbeans can now open the file, however none of the files can be edited.

kz3
  • 785
  • 2
  • 10
  • 23
  • What are you trying to achieve? – Bhesh Gurung Dec 22 '11 at 22:39
  • The ability to run the website= in the glassfish server installed with Netbeans – kz3 Dec 22 '11 at 22:47
  • You have the war and if all you are trying to do is deploy it on the Glassfish server then why are you messing with Netbeans. You can do it using Glassfish's admin console. – Bhesh Gurung Dec 22 '11 at 22:55
  • Going directly though glassfish yeilds a "JDK not found" exception. I have checked every setting, every config file, etc. and cannot solve that problem. I recall having the issue before but cannot remember the solution, but I know when I run WAR files through Netbeans it does work. I also need to be able to edit a few files once I have it running, so Netbeans would be a bonus there. – kz3 Dec 22 '11 at 22:59
  • But it's not a project right. It's a war file so, I don't think that Netbeans will be able to convert that into a project. When does it say "JDK not found". – Bhesh Gurung Dec 22 '11 at 23:02
  • Upon launching the application from the Glassfish admin panel – kz3 Dec 22 '11 at 23:11

2 Answers2

6

This was tested using apache's ode.war in NetBeans 8.0:

  1. Unzip the war file
  2. In the unzipped folder, you will see WEB-INF/, META-INF/, etc., create a sub-folder named web in the unzipped folder.
  3. Put everything else into web (now they will be web/WEB-INF/, web/js/, ...)
  4. Go to netbeans, new project -> java web -> web application with existing sources
  5. Pretty much just press next all the way through. voilà, it's done.
kguest
  • 3,804
  • 3
  • 29
  • 31
Vince L
  • 151
  • 2
  • 2
  • On Doing this I get an Option Saying "Do you want to delete existing class files as netbeans will generate class files in build folder".On Selecting "YES" all of my classes are lost and on selecting "No" it Imports class files in Source Packages.Example I see SourcePackages -> Controller -> XYZ.class,I want Java Files here what should I do @kguest ? – Anil Uttani Dec 29 '18 at 14:46
  • @AnilUttani there is an additional step. You will have to use a decompiler like, http://jd.benow.ca/ . Just open the JD decompiler and browse a class file from the extracted folder. You should see the folder structure in JD. Tap the class files to see source code. Good luck! – Arunchunaivendan Jan 09 '19 at 19:02
3

If you don't have eclipse handy, just place the war file into the webapps folder of Tomcat, go to the bin folder of Tomcat and run startup. Tomcat will automatically extract the war file for you. Now go to the webapps folder and you'll find another folder there, with the same name as your war.

I couldn't find an option to import a war directly into Netbeans (strange. Perhaps someone could create this feature and submit it as a patch to Netbeans). The folder which gets extracted into the Tomcat folder can be used as the Netbeans project. It's advisable to copy it to some other folder first. Import by File > New Project > Web application with existing sources.

Eclipse has an option to export a war and include the sources with it too, so there's a chance that the source files are in the war too.

Nav
  • 19,885
  • 27
  • 92
  • 135