package.properties not deployed by maven - java

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?

Related

maven does not include fxml file

I try to create a maven project of a java program, which includes two java classes and a fxml file, which are all located in the same directory (src/main/java/package).
When i install the project with maven it does not copy the fxml file into the .jar file so that the program does not work any more. A few hours ago I basically created an equivalent project and everything worked fine.
How can I fix that?
The Maven convention is that Java files go in src/main/java. Any non-Java files go in src/main/resources.
The Eclipse emulation of Maven does not make this distinction. Both directories are source folders which is incorrect but "good enough" to handle correct Maven projects.
So, move your file to the correct location.

The xml files are not compiled into classes folder in Intellij

I have a maven project which has many modules, I imported it to my Intellij as a maven project.
In the project settings, I changed the Project compiler output to xxx/src/main/webapp/WEB-INF/classes, the absolute path of my project. And also, I changed the Compiler output of all the other modules to this location. But when I check the classes folder at this location, I found two things which I think are not right:
The xml files are not compiled into the related path under the
classes folder, which are under the java folder instead of the
resource folder in source code.
There's a production folder under the classes folder, the classes
of other modules in it as the path they should be.
I'd be appreciated if anyone can help me understand this. Thank you in advance.
I'd recommend the following changes:
Your project compiler output folder should not follow the WAR standard. Make it /target, separate for all your artifacts. IntelliJ will create a /production and /test folder and put the .class files there.
Your XML files should be under /resources in the Maven convention.
You need to create an artifact for your deployment. That is where the WAR standard comes into play.
If you follow the conventions correctly IntelliJ will build and run your application perfectly.

Why isn't my war file containing all of the contents?

I have a web application. I have created a war file out of the "export" option from Eclipse. However, the war file only contains the META-INF and the WEB-INF folders. There are no .java or .class files at all.
I also tried another method using the Maven "clean install" goals. This one also gives me the exact problem as above. Where am I going wrong? Can someone help me out?
Thanks.
Please chcek if you have your code in default src path for maven (src\main\java)
If your project is an Eclipse project you need to make sure you created it as a 'Dynamic Web Project' so Eclipse attaches the right Facets so it knows how to build the .war.
If it's a maven project, you at least include
<packaging>war</packaging>
so Maven knows how to package your app.
If you run 'mvn package', assuming your pom.xml is configured correctly, you should get a .war file created in the target dir.
Sounds like something is not configured right - can you share more info about your source project structure and how it is configured?

Maven war plugin - including other files in WAR

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?.

how to package the .class under the web-inf/classes as a jar and put it to the web-inf/lib dir

I have a java web application name webapp,when I export it to a war,the source codes will be compiled to the WEB-INF/classes.
Now I want these classed be compressed to a jar,and put into the WEB-INF/lib.
I have tried this:
create a new java project named webapp_jar.
Copy all the source codes under the webapp/src to the webapp_jar/src,configurate the build path to make the project work.
Add the webapp_jar reference to webapp project.
However ,when I run the webapp,it seems that the classes defined at webapp_jar can not be found.
Is this possible?
BTW,I use the eclipse ee ide.
have you try ant https://ant.apache.org/ ?
you could make a jar and copy it to folder you want and build the war after.
But , if I anderstand, you would package all the app to a jar ?
I think your webapp can't work without a servlet or two ...
This is really easy to do with maven by creating two subject projects, one to build the war, and the other as a jar project and then use the jar project as a dependency on your war project which would put the jar inside the lib directory when packaging the war.
No I use the Web Deployment Assembly settings in eclipse. I worked.
You can find details here.

Categories