Skip to content

Commit 2b78953

Browse files
committed
updated eclipse, maven-assembly-plugin info
1 parent 118e694 commit 2b78953

File tree

1 file changed

+34
-11
lines changed

1 file changed

+34
-11
lines changed

tutorials/scala-with-maven.md

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -153,25 +153,45 @@ By default the jar created by the Scala Maven Plugin doesn't include a `Main-Cla
153153
</build>
154154
</project>
155155

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.*
157157

158158
### Useful commands
159159
- `mvn dependency:copy-dependencies`: copy all libraries and dependencies to the `target/dependency` folder
160160
- `mvn clean`
161161
- `mvn package`: compile, run tests, and create jar
162162

163163
### 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:
165165

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
172-
7. Click "Finish"
166+
...
167+
<plugin>
168+
<groupId>org.codehaus.mojo</groupId>
169+
<artifactId>build-helper-maven-plugin</artifactId>
170+
<executions>
171+
<execution>
172+
<id>add-source</id>
173+
<phase>generate-sources</phase>
174+
<goals>
175+
<goal>add-source</goal>
176+
</goals>
177+
<configuration>
178+
<sources>
179+
<source>src/main/scala</source>
180+
</sources>
181+
</configuration>
182+
</execution>
183+
</executions>
184+
</plugin>
185+
...
186+
187+
After adding that to your `pom.xml`:
188+
189+
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
173193

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]!
175195

176196
## Adding Dependencies
177197
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
218238
[28]: http://search.maven.org/#artifactdetails%7Ccom.google.guava%7Cguava%7C14.0.1%7Cbundle
219239
[29]: https://github.com/scopt/scopt
220240
[30]: http://search.maven.org/#search%7Cga%7C1%7Cscopt
221-
[31]: http://mvnrepository.com
241+
[31]: http://mvnrepository.com
242+
[32]: http://docs.scala-lang.org/contribute.html
243+
[33]: http://maven.apache.org/plugins/maven-eclipse-plugin/
244+
[34]: http://mojo.codehaus.org/build-helper-maven-plugin/

0 commit comments

Comments
 (0)