简体   繁体   中英

putting a .java file into .war

My professor asks us to submit out projects in WAR files, and he says my project will get a 0 if the WAR doesn't include my .JAVA file.

I see it includes the .CLASS file but he said thats not enough, how can i get the .WAR file to pack with the .JAVA inside of it?

EDIT: To compress the file i'm using the clean and build option in Netbeans. the WAR file appears in the build folder

If this is in Eclipse, you will include source under the export WAR option.

Update

In the war export panel, there should be an "Excluded file types" make sure to remove *.java

WAR file is just an archive, understandable with any ZIP archiver, like 7-zip. You can put anything you want into WAR.

Look for section "Including Source Files in the WAR File"

http://users.cis.fiu.edu/~downeyt/webdev/netbeans.html

quoted from the link:

From the properties screen, select Build -> Packaging. Edit the Exclude From WAR File box and remove * / .java,.

What are you using to create the WAR file? If you use apache ant then add a copy task to your build.xml and then reference it in the default target eg with <target name="dist" depends="copy-source"/>

The task might look something like:

<target name="copy-source">
  <echo>Copying source files...</echo>
  <copy todir="${app.dir}/src">
    <fileset dir="${javasrc.dir}">
      <include name="**/*.java"/>
    </fileset>
  </copy>
</target>   

ps. It is best to define the variables in an external build.properties file and never use hard-coded values in build.xml . Also, have a look at http://ant.apache.org/manual/Tasks/war.html and http://ant.apache.org/manual/Tasks/copy.html

In Netbeans.Right click your project. Select Project Properties.It will open a Project properties window. Select Build->Packaging from the Categories Tab. In the window that appears on right hand side, there is a text field: Exclude from WAR file. In that text field default value is: / .java, / .form. In that text field remove the * / .java value and click Ok. Now clean and build project. Now you will find the war file exported with .java sources under dist directory of your project.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM