eclipse loading src folder weirdly - java

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.

Related

Where should the git directory be in a IntelliJ IDEA file hierarchy?

I am learning java and using JetBrains' IntelliJ IDEA as IDE. I am working on a small project which I would like to track via git/GitHub, as I am also learning how to use it.
My question is: where should I place the git directory (i.e. where should the .git folder go)?
As you might be aware, IntelliJ automatically creates the following folder structure when you create a project:
.idea folder created by IntelliJ
out folder containing compiled classes
src folder containing the source code (.java files)
projectName.iml file created by IntelliJ
I am hesitating between putting it in the root folder of the project or in the src folder. My gut feeling would push for the latter, as this is what I'm mostly interested in sharing, but I would like to know what the best practice is.
Generally, You should really keep it in the root folder and simply create .gitignore with all the folders that you are not interested in putting to Your repo.
This is because You really want your root folder to be the git repository, because of practical reasons. If You would keep it in the src folder then you would basically leave out everything that is in the root folder, like for example pom.xml or build.gradle or other files. What is more You would make it harder for other people to use such project, due to the fact that most of the IDEs actually uses the format with src/main and src/test folders.
The best practice is to put root directory to git and list everything you don't want to push to git in .gitignore file. You can use ay open source java project as example, i.e. https://github.com/apache/jmeter
You can see the .gitignore content: https://github.com/apache/jmeter/blob/trunk/.gitignore

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.

How does one export and then import an exact copy of a java project jar?

I have tried various things starting with Java Maven project to get a jar which when imported looks exactly like the original but I have found that I can't for example get the src/main/resources folder to appear in the imported project. The goal is simple: so that on the new machine for example that the project can be run and worked on just like the original. Not sure what I am missing. I have tried importing existing project from archive which seems like it should work. On the original machine I select all files and folders but this still leaves out some things. I have tried to create an empty folder in Eclipse but this can't be done and various permutations.
A jar file usually contains compiled code and whatever else you drop in there which in turn enables you to run the code.
An eclipse, maven, intellij, ... project structure may be completely different. In the end a transformation will happen from that project structure to the jar content structure. In the case of Maven this will not be the same as the project structure.
The intent of a jar is running the compiled code, an intent of a project structure is to edit the source code.
If you want to copy an eclipse workspace to work on then do so. Copy the workspace folder.
user392486 basically showed what to do. The key is to export the file not as a jar but as a zip and the import it as an existing project which has an archive option. that works just as one would want, an identical project. how i could not already know this is beyond me...

dynamic web project package structure

I have download a sample project and saw the below package structure.
src/main/java
src/main/resources
JRE System Library
Referenced Libraries
src
main
webapp
css
user
WEB-INF
target
Is it a best way to create the package structure. Normally when we create a dynamic project in eclipse it has one src folder and the WebContent folder in project root. The WEB-INF would be under the WebContent. But here we can identify two source folders and instead of WebContent we find webapp under the source folder not in root.
Despite its correct package structure or not i try to create the same in eclipse. But i cant rename the src folder to something like src/main/java know. It gives me an error
Cannot nest source folder "src/main/java" inside source folder "src".
in eclipse when create a dynamic project
This structure is maven based web base project and mostly for maven base project this structure is used, and as for as new conventions Maven is most popular deployment tool, so I myself recommend the maven base architecture.
If maven drives this organization a maven plugin exists, its goal is to generates eclipse projet.
A second plugin (an eclipse plugin) exists to faciltate the integration into eclipse.
The src/main/java folder is an automated updated duplicate of src folder. (These are the build paths configured in your project)
You should edit your files in src and the changes will be updated by eclipse to their symlinks.
First of all, its only one src folder. Eclipse displays them in such a way to make it easier to access different parts of the project. Webapp is main WebApplication Folder which contains all the goodies. The other most important folder is WEB-INF this is folder which is read protected from the client side so, you have your Java Class files and any thing which you want to protect from the client inside this folder. This folder also, contains a lib directory to contain the JAR files. This is the main overlay for the directory structure.

Categories