You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: tutorials/scala-with-maven.md
+34-11Lines changed: 34 additions & 11 deletions
Original file line number
Diff line number
Diff line change
@@ -153,25 +153,45 @@ By default the jar created by the Scala Maven Plugin doesn't include a `Main-Cla
153
153
</build>
154
154
</project>
155
155
156
-
After adding this, `mvn package` will also create `[artifactId]-[version]-jar-with-dependencies.jar` under `target`.
156
+
After adding this, `mvn package` will also create `[artifactId]-[version]-jar-with-dependencies.jar` under `target`.*Note: this will also copy the Scala library into your Jar. This is normal. Be careful that your dependencies use the same version of Scala, or you will quickly end up with a massive Jar.*
157
157
158
158
### Useful commands
159
159
-`mvn dependency:copy-dependencies`: copy all libraries and dependencies to the `target/dependency` folder
160
160
-`mvn clean`
161
161
-`mvn package`: compile, run tests, and create jar
162
162
163
163
### Integration with Eclipse
164
-
There are instructions at the [Scala Maven Plugin FAQs][23], but I took the lazy route with manually linking the source folder and dependencies. It's working fine for me, but you may want to invest more time into the "official" approach if you're working on a medium-large project.
164
+
There are instructions at the [Scala Maven Plugin FAQs][23], but I thought I'd expand a bit. The [maven-eclipse-plugin][33] is a core plugin (all plugins prefixed with "maven" are, and are available by default) to generate Eclipse configuration files. However, this plugin does not know about our new Scala source files. We'll be using the [build-helper-maven-plugin][34] to add new source folders:
165
165
166
-
1. Install the [Scala IDE for Eclipse][24]
167
-
2. Open the Scala perspective and create a new Scala project
168
-
3. (Save the project in the default location/your workspace --- not in your project folder, especially if you're using a VCS)
169
-
4. Hit "Next"
170
-
5. Click "Link additional source" and find your project `src` folder. In the dialog, you'll have to name this linked source folder something else, such as `src-repo` (I couldn't figure out how to delete the default source folder, but maybe you can)
171
-
6. Under "Libraries", click "Add external JARs..." and add junit, scalatest, and specs2, plus any dependencies you added
1. Run `mvn eclipse:eclipse` - this generates the Eclipse project files (which are already ignored by our archetype's `.gitignore`)
190
+
2. Run `mvn -Dv=eclipse.workspace="path/to/your/eclipse/workspace" eclipse:configure-workspace` - this adds an `M2_REPO` classpath variable to Eclipse
191
+
3. Run `mvn package` to ensure you have all the dependencies in your local Maven repo
192
+
4. In Eclipse, under "File" choose "Import..." and find your project folder
173
193
174
-
You won't be able to run from Eclipse without classes/objects that extend [`scala.App`][25]. However, [this is only good for debugging purposes][26]. In the mean time I've just been packaging and running the jar each time.
194
+
In Eclipse, you can only run classes/objects that extend [`scala.App`][25]. However, [this is only good for debugging purposes][26]. In the mean time I've just been packaging and running the jar each time. If you find a better way, feel free to [contribute][32]!
175
195
176
196
## Adding Dependencies
177
197
The first thing I do is look for "Maven" in the project page. For example, Google's [Guava] page includes [Maven Central links][28]. As you can see in the previous link, The Central Repository conveniently includes the snippet you have to add to your `pom.xml` on the left sidebar.
@@ -218,4 +238,7 @@ I'm not going to explain all of Maven in this tutorial (though I hope to add mor
0 commit comments