how to create java project with command? - java

I'm a beginner, when I create a java project using the command pallate in vscode ctrl-shift-p -> java: Creat java project, only created the lib, src and readme files, I see on the vscode website there must be a .settings, bin, src folder .classpath .project
is there anything to configure again? thank you
my create project
create project on vscode web

Those files you mention (.settings, .classpath, .project) are just metadata files from the IDE, and java does nothing with them, they are not part of a java project, the only thing you need to create a java program its a .java file. If you want to create a project, there are better ways, for example using maven https://maven.apache.org once you installed it, you can create a new project using the QuickStart archetype
mvn archetype:generate -DarchetypeGroupId=org.apache.maven.archetypes -DarchetypeArtifactId=maven-archetype-quickstart -DarchetypeVersion=1.4
It will create a standard structure for your project, and will save you a lot of work with the structure of your project, dependencies and build configurations.

To store project metadata some IDEs use additional files:
Eclipse uses .settings, .project, .classpath
Intellij uses .idea, .iml, .ipr, .iws
You don't need any of these for your project to work. If you use VSCode you don't need them at all.
Most modern java frameworks have quite comprehensive code generators for new projects which makes it easier to get started e.g.:
Quarkus
Micronaut
Spring

Related

Ship an eclipse dynamic web project as a pure maven project (possible?)

I have a maven project in eclipse (was originally a dynamic web project, which was converted to a maven project that has the web-app arch type).
Whenever I upload the project to Github, I, of course, upload the source java and web files, pom.xml, but I also need to upload the .project, .settings, and .classpath files which are Eclipse IDE specific (right?), so that later I can import it directly using eclipse from Github. If the latter files are not uploaded, I cannot import the project later on in eclipse. After importing, I use maven with the respective pom.xml file to download the dependencies and build the war file.
Is there a way to export my project in a form independent from eclipse, i.e., something like a pure maven project? So that, later, it can be imported using e.g., say Intellij or Netbeans only using maven? Or just tell Eclipse to import a maven project from Git, rather than an Eclipse project as it is now. Is there such a thing? If so, how to create it and commit it to Github from Eclipse? Which files/directories do I (not) need?

How to create a Java Spring WebApp Folder Structure using Gradle

I am making a Java Web App project using Gradle. Now, for building a Gradle web app plenty of resources are available over the net.
But, my issue is a bit different. Suppose, I want to initiate a Gradle based project and make a web app suitable project folder structure just like we do in maven. Is there any specific way to create so in Gradle. I have found something about templates. Is there any way to do it or do I have to create a folder structure manually and then attach to Gradle so that it can build a war out it properly.
You can use maven to create the project and then create gradle build from it:
mvn archetype:generate -DgroupId=com.example -DartifactId=java-web-project -DarchetypeArtifactId=maven-archetype-webapp -DinteractiveMode=false
Then:
gradle init --type pom
You didn't mention your IDE, but I will answer for IntelliJ IDEA and for Eclipse the steps are similar.
Go to File --> New --> Project, choose Gradle from the left menu and choose both Java and Web options (see image below).

IntelliJ Idea doesn't create manifest.mf, pom.xml, pom.properties

I am quite new to Java, although I worked with some projects. I use IntelliJ IDEA, and I have issue with my web project.
Whenever I RUN the project from IntelliJ and when it's made and built - my localizations texts are not shown, but everything is ok if I use mvn install and deploy the war file manually.
What I found is that jars built with IntelliJ don't have MANIFEST.MF generated and couple of other files.
This is IntelliJ jar
This is jar when I run mvn install from console:
Can somebody help with this, why this happens? I have same maven used for compiling as I use for console run:
If you have a Maven project, then you can choose one on the tasks on the right of the editor.
jar or package should generate a JAR file.
Maven is a software tool that helps manage a project and automate builds. By default, however you have to select Maven as the desired type of project when you go to create a new project.
Basically, create a Maven project! :)

what is the difference between maven-archetype-webapp and eclipse dynamic web project

why do I need to apply: mvn eclipse:eclipse command?
are they equivalent to application container/server?
Is there a file for which customizing is necessary besides web.xml?
when you create a web project using maven, like maven-archetype-webapp. It creates the folder structure as recommend by Maven for a webapp like shown here .
Now when you try to import these folders in Eclipse, it still would look like folders but eclipse cannot understand the nature of these folders. Eclipse relates folders and contents within them to an Eclipse dynamic web project only through its .project , .settings files
So in order for your maven project to be understood by Eclipse, you run the goal mvn eclipse:eclipse. After executing this goal, maven generates the .project, .settings files necessary for eclipse to understand the project as Web project.
This is however optional. You can still import the project as Maven projects within eclipse and continue to use them but you cant rely on Eclipse's features like clean/ build / build automatically.
Though I use eclipse, I dont rely on Eclipse's build feature. I have installed Maven eclipse plugin and that allows me to run maven goals and commands within Eclipse which is as good as running Eclipse's build feature. Hope this helps.

Eclipse Maven project to Dynamic Web Project layout

I am used to the layout provided by the Dynamic Web project in eclipse where you have all your Java code under the src folder, your JSP files, etc under the WebContent folder and the WEB-INF resides right under the WebContent folder. Also, the Output folder is hidden from the project tree. Maven has its own format which I find somewhat confusing, it creates its now target folder and source/main/java folder and some test folder under target...
Is there a way to create a Maven project and have it use the Dynamic Web project project tree layout?
I tried changing the Deployment Assembly entries to match that of the Dynamic web project and have also update the Java Build Path src and output to match the Dynamic Web project one but I get strange, cryptic unfriendly errors when I do a Run/Install. Can you provide me with details on how to go about doing this cleanly?
What you need to get used to using is the concept of archetypes in Maven.
The concept is like project templates ready for you to use that are automatically understood by Maven.
mvn archetype:generate
will get you an interactive listing of all the available archetypes
What you want to look for is maven-archetype-webapp this will give you a basic skeleton framework of what Maven is expecting a webapp to look like.
There are others that include support for different frameworks and what not.
mvn archetype:generate | grep webapp
will filter out all the choices that are webapp archetypes
Then it is a simple mvn clean package and you get an exploded dir and a .war in the target directory, you can even enable the Tomcat plugin to automatically deploy to Tomcat. Other J2EE servers are supported as well.
Then you use the Maven plugin for eclipse to load the project based on the pom.xml file.
You could create your own non standard layout and get it working by manually configuring everything thing and create an archetype out of it but that kind of defeats the purpose of a single way of doing things with a tool like Maven.
Using m2e 1.3+ and m2e-wtp 0.16.0+, you can just :
create a new Dynamic Web project
right-click on the project > Configure > Convert to Maven...
Fill in the Maven coordinates of your project and finish
It'll mavenize your project, keeping the standard Eclipse project layout.
See http://wiki.eclipse.org/M2E-WTP/New_and_Noteworthy/0.16#New_project_conversion_participants for more information

Categories