The xml files are not compiled into classes folder in Intellij - java

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.

Related

eclipse loading src folder weirdly

I am using git with fellow student, now I've noticed that if I load a branch of another student it imports the src folder weirdly.
what could be the problem?
Eclipse is not recognizing your src directory as a source folder, and therefore not displaying the underlying directories as packages.
You need to define the source folders in your project, typically src/main/java and src/test/java (Maven convention).
If someone else's branch uses different source folders than you, then you get this problem when you switch. It might be useful to either follow the same project structure if you work together, or use separate Eclipse projects.

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.

Path in Intellij Vs. Eclipse

My company is attempting to make a transition from Eclipse to Intellij Idea and I have a (might be silly) question regarding the paths.
I have a library in the root of the eclipse project and a spring configuration file which simply points to it by "folderName/file.txt". It works fine in Eclipse since it recognizes the folder. In IntelliJ however it seems to not pick the folder at all.
I've tried to mark the folder as a resource/test resource folder but it seems to simply take the contents of the folder and dump it directly into the target folder without the folder itself, just the contents.
Is there a way to configure IntelliJ to work with the folder just like in Eclipse? This is important because some are still using Eclipse, some IntelliJ, so we need a solution that will work for both.
I am guessing your are using maven since you mention the "target folder"
What happens is that since your imported the project from the maven pom.xml intellij build it by following maven.
In maven the default project structure is
this
This in maven everything you copy in the resources folder, will be copied to your root classpath. so if you make for
resources/myFolder/my.txt then in the build you will have copied to your classpath myFolder/my.txt
Anyway if you are not using maven all you have to do is go to
Project structure (ctrl+alt+shift+s) - Modules - go to your module - mark the folder that your want to add as resource

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.

What's in an Eclipse .classpath/.project file?

We recently had an issue with an Eclipse project for one of our team members. Tomcat was not deploying JARs of the application.
We eventually noticed the .classpath Eclipse file was not the same as for the team members where the project was OK. We replaced the .classpath file with one from a project that was OK and the Tomcat deploy was complete.
Just out of curiosity and to know at what to look in the future if something is wrong, what is inside the .classpath and .project files. What can I add in there, what does it all mean?
Eclipse is a runtime environment for plugins. Virtually everything you see in Eclipse is the result of plugins installed on Eclipse, rather than Eclipse itself.
The .project file is maintained by the core Eclipse platform, and its goal is to describe the project from a generic, plugin-independent Eclipse view. What's the project's name? what other projects in the workspace does it refer to? What are the builders that are used in order to build the project? (remember, the concept of "build" doesn't pertain specifically to Java projects, but also to other types of projects)
The .classpath file is maintained by Eclipse's JDT feature (feature = set of plugins). JDT holds multiple such "meta" files in the project (see the .settings directory inside the project); the .classpath file is just one of them. Specifically, the .classpath file contains information that the JDT feature needs in order to properly compile the project: the project's source folders (that is, what to compile); the output folders (where to compile to); and classpath entries (such as other projects in the workspace, arbitrary JAR files on the file system, and so forth).
Blindly copying such files from one machine to another may be risky. For example, if arbitrary JAR files are placed on the classpath (that is, JAR files that are located outside the workspace and are referred-to by absolute path naming), the .classpath file is rendered non-portable and must be modified in order to be portable. There are certain best practices that can be followed to guarantee .classpath file portability.
.project
When a project is created in the workspace, a project description file is automatically generated that describes the project. The sole purpose of this file is to make the project self-describing, so that a project that is zipped up or released to a server can be correctly recreated in another workspace.
.classpath
Classpath specifies which Java source files and resource files in a project are considered by the Java builder and specifies how to find types outside of the project. The Java builder compiles the Java source files into the output folder and also copies the resources into it.
Complete reference is not available for the mentioned files, as they are extensible by various plug-ins.
Basically, .project files store project-settings, such as builder and project nature settings, while .classpath files define the classpath to use during running. The classpath files contains src and target entries that correspond with folders in the project; the con entries are used to describe some kind of "virtual" entries, such as the JVM libs or in case of eclipse plug-ins dependencies (normal Java project dependencies are displayed differently, using a special src entry).
This eclipse documentation has details on the markups in .project file: The project description file
It describes the .project file as:
When a project is created in the workspace, a project description file is automatically generated that describes the project. The purpose of this file is to make the project self-describing, so that a project that is zipped up or released to a server can be correctly recreated in another workspace. This file is always called ".project"

Categories