Using m2eclipse for multiple projects with parent pom.xml - eclipse

I have multiple maven projects with their individual pom.xml's an a parent pom.xml.
my_workspace
├── application-project
│ ├── pom.xml
│ └── src
│ ├── main
│ └── ...
│ └── test
│ └── ...
├── common-project
│ ├── pom.xml
│ └── src
│ ├── main
│ └── ...
│ └── test
│ └── ...
└── pom.xml
Now, from Eclipse, I can right click on common-project or application-project, I see Run As Maven... options there. But when I need to run a specific goal for all the projects, i.e. which is in the parent pom.xml, I don't understand how to go about it, if not using command line?

I guess you have appropriate plug-in, if not already having, install m2eclipse plugin first
Run > Run Configuration > Maven Build
Double click[*], choose the project, put down the goals, put down profile if any.
Fron next time use this (will be available in drop down) to execute your own goals.
[*] The form that opens here has all the capability to construct a maven command that you can run from command line. You might need to play around a bit to get what you actually wanted.
Updated as question was modified:
OK, so your parent project is your workspace folder. worry not.
Run > Run Configuration > Maven Build
Double click, browse filesystem and select the workspace folder, put down the goals, put down profile if any. I have just tested it. It works.
Yet another way, as OP found out, that you can click variables... button beneath the text-field for Base Directory and choose workspace_loc to point to your workspace directory as the base directory for Maven build.

Related

why should i create package for my own flutter project

I'm learning bloc state management in flutter but I saw code here made me to ask some questions like ,
why they separated the repository as an external package, then use it in the bloc? . why didn't just create repository auth in the project lib folder like this
├── android
├── ios
├── lib
│ └── authentication_repository
└── test
and what is the benefit of this approach when should I use it in my future projects?

Installing scala from coursier: where is the `scala` command?

I installed scala from https://www.scala-lang.org/download/scala3.html using the coursier option:
cs install scala3-compiler
cs install scala3-repl
After these two steps, I have two binaries in my $PATH: scala3-compiler and scala3-repl.
I am learning scala from the Programming in Scala book, and in Chapter 4, it said I should compile and run a scala application with the following commands:
scalac ChecksumAccumulator.scala Summer.scala
scala Summer of love
I replaced scalac with scala3-compiler in the first command, and it produced an org directory of the following structure:
org/
└── stairwaybook
└── classesandobjects
├── ChecksumAccumulator$.class
├── ChecksumAccumulator.class
├── ChecksumAccumulator.tasty
├── Summer$.class
├── Summer.class
└── Summer.tasty
But I cannot find any scala command installed in my system, and do not know how to run the compiled bytecodes. Any thoughts or suggestions?
Try to install:
cs install scala3
Then you should write:
scala3-compiler ChecksumAccumulator.scala Summer.scala
scala3 Summer of love
It should work

How to run Main method in Scala in Intellij

I am trying to get a main method to run in Scala in Intellij, but it is not working, and I don't know why.
File structure looks like this...
.
├── cse116.iml
├── pom.xml
├── src
│   ├── Main.scala
└── target
└── classes
Main.scala looks like this...
object Main {
def main(args: Array[String]): Unit = {
println("Hello, world!")
}
}
When I try to do "Run" on Intellij, I get the following error:
Error: Could not find or load main class Main
I am not sure what configuration is messed up. What may be some common reasons for this happening?
Try to right click on your mouse when you are in Main.scala file and select "run 'Main.main()'" option with green triangle
Assuming you are running a recent version of intelliJ, have the Scala plugin installed and your dependencies for Scala is correct in your pom file. You should see a tiny green arrow either on the left hand side of your main class or when right clicking within that class. Also, if you are on macOS there is the ctrl+shift+r to run the file as shown in the image below.
If that is not the case, consider creating a new Scala project from the IDE itself. You'd then choose an sbt project. sbt is the equivalent of maven in the Scala world. This one "should" work, if it doesn't it is very likely to give you a better Scala specific error message(s)

How to convert JavaFx project to Gradle project?

I'm building a JavaFx project using Eclipse and I have a file structure like this:
Project
│ .classpath
│ .gitignore
│ .project
│ build.fxbuild
│ README.md
│ (sqlite).db (*local database this project operates on)
│
├───.settings
│ ...
│
├───bin
│ ...
│
├───lib
│ ...
│
└───src
├───application
| ...
│ Main.java
│
├───controllers
│ ...
│
├───css
│ ...
│
├───fxml
│ ...
│
└───resources
123.jpg
How do I convert this into a gradle project? I'm totally new to gradle and I have hard time finding documentation to get started.
*I'm using JavaFx 8 and jdk-9.
I have hard time finding documentation to get started.
Gradle is well-documented, if you google you find a lot of beginner's tutorials as well, and there's lots of examples on GitHub.
See https://guides.gradle.org/building-java-applications/
The documentation is quite overwhelming, and you need to familiarize yourself with a bunch of concepts too. As a starter, you need to grasp following concepts:
Project structure
Gradle uses the default folder structure introduced by Maven:
src/main/java for Java sources
src/main/resources for resources (get bundled into the JAR/WAR/EAR)
src/test/java for Java test sources
src/test/resources for test resources
Build file
The build.gradle file defines your project and how it should be built. Each project/artefact has a groupId, artefactId and version.
Build tasks
Gradle projects use plugins (such as the 'java' plugin for building Java projects). Learn about the build tasks (clear, test, build, deploy, execute gradle tasks to list all tasks.
Dependencies
External libraries you use shouldn't be downloaded and put into the project lib folder, but rather you declare dependencies to libraries (browse for them on Maven Central. Gradle will take care of the dependency management and download libs and transient dependencies automatically.
External resource loading
You project contains a file-DB. Is it read-only? Bundle it as resource and load it over the class loader, not a file. Is it writeable? Keep it outside the project, and access it over a URL or file path. Consider to make the URL/path configurable (command line args).
Here's the generic build.gradle which I use as a starter for my projects (with a cleaner approach to managing dependencies), for JDK 9/10/11+ you can change the compatibility java version to 9/10/11+:
defaultTasks 'clean', 'build'
apply plugin: 'java'
description = 'Example Java Project'
group = 'org.test'
version = '1.0.0-SNAPSHOT'
sourceCompatibility = 1.8
targetCompatibility = 1.8
compileJava.options.encoding = 'UTF-8'
repositories {
jcenter()
}
ext.libs = [
testbase: [
"junit:junit:4.12"
],
loggingAPI : [
"org.slf4j:slf4j-api:1.7.25"
],
loggingImpl : [
"org.slf4j:jcl-over-slf4j:1.7.25",
"org.slf4j:jul-to-slf4j:1.7.25",
"ch.qos.logback:logback-classic:1.2.3"
]
]
dependencies {
testCompile libs.testbase
compile libs.loggingAPI
compile libs.loggingImpl
}

IntelliJ SBT directory structure

I created a new SBT project HelloScala, then I created a package called week6 and then a Scala worksheet under it. Eventually, I got the following directory structure:
~/HelloScala/.idea
~/HelloScala/project
~/HelloScala/src/main/scala
~/HelloScala/src/main/scala-2.12/week6/hello.sc
However, when I put package week6 in the worksheet hello.sc, IntelliJ warns that Project names doesn't correspond to directories structure. My questions are:
What should be the correct directory structure IntelliJ/SBT expects? Is it specified in some .xml file?
Notice that IntelliJ created two scala subdirectories, scala and scala-2.12. Is it correct? Or IntelliJ somehow failed to recognize the scala which had already existed but download and install another scala?
Thank you!
I don not use IntelliJ that often, but usually Scala packages should go into src/main/scala.
The structure of a Scala project is nothing too different from a Java one. Minimally you will need:
myproject
├── build.sbt
└── src
└── main
└── scala
└── mypackage
which is a project with a single package, a SBT script and nothing else.
For a more complex example, a Scala project could look like:
project
├── build.sbt
├── project
├── target
└── src
├── main
│ ├── java
│ ├── resource
│ └── scala
└── test
├── java
├── resource
└── scala
in which the project folder is used by SBT for various purposes, the target folder contains the compiled .class files and .jar packages.
To answer your questions:
The above structure is used implicitly by the SBT plugin. Maybe it is customizable, but in most cases it is suggested against doing this.
Your Scala source code should go into src/main/scala. I have no idea where does the other directory come from.
#sgu It seems I misunderstood your question and unfortunately I cannot leave a comment. The file "hello.sc" you are trying to deal with is treated by IntelliJ as a "Scala worksheet". I guess it is a REPL behind IntelliJ which evaluates as you edit. However it is not treated the same as a "Scala source file", so adding package xxx gives you the warning. If you want to create a package, the source files should be in ".scala" extension.
You should put all your source code under "main/scala" directory. "Scala-2.12" is the directory, that would be created with sbt under "project/target" after you compile/build it.
Have you tried clicking the Make project option on top of the scala sheet in Intellij Idea? I use that option when I need to import oher packages into one scala worksheet.