I am building an Maven based Java web-app. In my src/main/java/package folder I have a .xml file and a .properties file that needs to be included as a part of my war. However when I look at the war file that gets generated (using a maven install) this does not include the .xml and the .properties file. It only contains the .class files from the package.
Is there anyway of including these files in the war ?
In addition, I also checked under the target/classes folder, here again the .xml and .properties files are not included.
Put your .xml file and .properties file in resources folder of your project, by default Maven will pick it up from there.
Little more googling around stackoverflow got me the answer. I just had to change the default resources folder for maven as outline in the following stackoverflow question Why does maven not copy the properties files during the build process?.
Related
I am new to project environment setup. Below is my project structure in eclipse
Project Name
--> .settings
--> .bin
--> lib
--> resources
--> src
--> .classpath
--> .project
I am attempting to export src folder as jar.
When i export to jar, all the above folders & files are created in jar. But i need to convert only src folder as.
Also when i export to executable jar, all the third party libraries are exported as class files in jar. is it right.
What is the best practice to export project. Only src folder or everything.
Which i need to use jar/runnable jar. My requirement is to write start/stop bat file to call jar and execute java program.
Please advice me. Thanks in advance.
First it's important to know what these folders actually do. Following are the workings of several of these files.
.settings -> This file records project specific settings and workspace preferences.
.bin -> folder is usually where the compiled files are copied to.
lib -> contains external libraries that are used in your project (like Apache Commons)
resources -> the resources like images, text, pdf, audio, video are usually copied here
src -> the folder where the project's source files are located.
.classpath -> It contains information that the JDT feature needs in order to properly compile the project: the project's source folders, the output folders , and classpath entries.
.project -> This file is maintained by the core Eclipse platform, and its goal is to describe the project from a generic, plugin-independent Eclipse view.
So you can see that if you exclude some of the files like lib, resources, bin etc... Your jar file will probably stop working. Your jar file needs compiled files and their dependencies.
For example: All your compiled .class files are in bin folder. And your jar works because of these .class files and NOT .java files that are in src. If you delete this bin folder then your jar will probably stop working.
Also, your project may be using some external library supplied by someone else. Like Apache Commons or google/guava and these are usually in lib folder. So you can't delete this folder as well.
However, if you no longer expect to use .java code, then you can exclude files that were created by eclipse to manage this project. See this post.
see also:
1. What's in an Eclipse .classpath/.project file?
2. exclude files from jar or war in eclipse
I created a miniTennis program,with Sounds files included in it. But when I am trying to build it from NetBeans (Creating jar file) , those sound files are automatically deleted from my classes folder and also they are not included in .jar file.
I have no idea ,what's the problem?
You probably have the usual (my src/ folder only should contain java sources) rule in your ant file.
Create a resources folder and mark it respectively. It should then be picked up when building a jar file.
I am using a package.properties file in my eclipse project (struts2). When running the application from eclipse, formatting date and time works fine but when I am deploying this project with maven to tomcat7, it seems that this file is not being included in war file and thus the formatting doesn't work. Can anyone please help?
Try placing the package.properties file at path src/main/resources of your maven project, Maven picks the files in resources directory.
Refer to this link to understand where to place the properties file:
Struts 2 – Resource bundle example
Alternatively if you don't want to place the files in resources directory then you can refer to this below link to understand how to pick properties file from src/main/java :
In maven how can I include non-java src files in the same place in the output jar?
I have a Android project with some classes that I would like to compress to a JAR.
I create the JAR by right clicking my project - export - JAR - and the JAR gets created without any warnings.
I can access all classes from the JAR in my code but when I try to build the project get this exception :
java.lang.NoClassDefFoundError: name.of.class.in.package
Does anyone know what resources should be exported with the JAR? The options you get is
.class path
.prject
AndroidManifest.xml
proguard.cfg
project.properties
Right now I have included all of the above.
Making the JAR into a library project is not an option. And just to make it clear I don't have anything in the RES folder of my JAR project.
Open the project properties -> Java Build Path -> Order and Export and check item Android Dependencies are checked to be exported to the result APK.
And if .jar exist in Library tab under Android Dependencies item.
If you have .jar in the "libs" folder it should be included by default.
Just add your JAR to classpath or build your project with Maven and include dependencies
Try generating the jar in a different way. Basically jar is a zipped file of all class files with an extension of .jar.
Select all your class files that needs to be included in a jar file.
Right click and send to compressed (Zip File).
you will have a zipped file which will contain all the class files.
Rename this zipped file with having an extension .jar
Now include this jar file into your project whichever you want to use.
Or if you want to zip all the files by a different method then make sure all the files are zipped together without a folder. So when you unzip the files you should get all the files without contained in a folder.
It looks similar with this topic. Follow the very clear instructions written by Russ Bateman.
I would like to update an open-source war file in Maven with some additional class files and jar files. I also need to replace one configuration file with my own.
The simplest way I see to do this is copy over the Java source files and configuration files from the base war file and check them into my source repository. This would work, but it requires that I duplicate both source and configuration files. Thus, what I would like to do is build the base war file, check in only that war file, then run a maven build which adds my class files, extra jar files, and replaces one configuration file in the base war. The output of the Maven build would be one war file.
Does anybody have any suggestions as to how I can do this with Maven?
By the way, the base file is from jUDDI - it is juddi-war. I think the answer to the problem does not depend on the particular war file though.
You'll want to use an overlay. It's intended to add files to an existing WAR.