|
From: Van P. <van...@gm...> - 2017-01-19 16:17:22
|
The widespread use of Maven to distribute packages, and the inherited dependencies that they impose, make it really helpful to use Maven to manage dependencies in Repast Simphony (RS) projects. Building on David Momper's launcher hack (https://sourceforge.net/p/repast/mailman/message/34207741/), and with thanks to David and Nick for patiently helping me work through details, here's the recipe that works for me. NB: as David has emphasized in recent posts, we are using Maven only to manage dependencies, not to manage the build cycle. Repast still takes care of building, but it will now be able to link in dependencies defined in Maven. 1. Go to the Eclipse marketplace, and install the m2e Maven Integration for Eclipse plugin. 2. Create a new RS (Repast Simphony) project. 3. Add the Maven nature: in the package explorer, right click on the project, Configure --> Convert to Maven Project. You will now have pom.xml visible at the top level of your project directory. 4. It's a well-known bother that Maven insists on resetting the JRE library and compiler preference to version 1.5. If you're not using 1.5, a. In pom.xml, set the source and target in the maven-compiler-plugin to 1.8 (or whatever you're using). The <build> section of the POM should look like this: > <build> <sourceDirectory>src</sourceDirectory> <plugins> <plugin> > <artifactId>maven-compiler-plugin</artifactId> <version>3.1</version> > <configuration> <source>1.8</source> <target>1.8</target> > </configuration> </plugin> </plugins> </build> b. Right click on the project, Maven --> Update Project to set the JRE System Library consistent with the setting in the POM. 5. Add your dependencies to the POM. You'll now have a "Maven Dependencies" folder containing them. 6. Apply David Momper's hack to the model.launch file in the "launchers" directory: in the section that begins <listAttribute key="org.eclipse.jdt.launching.CLASSPATH">, insert the following, ALL AS ONE LINE: > <listEntry value="<?xml version="1.0" > encoding="UTF-8" > standalone="no"?> <runtimeClasspathEntry > containerPath="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER" > path="3" type="4"/> "/> 7. Code away. You can import classes from any of the Maven dependencies, just as you would from Repast or Java. You'll see that Maven has added a "Maven Dependencies" folder with all of the dependencies you added to the POM. 8. Now you want to run your program. Each time you save your files, Repast updates the class files. Without Maven, Repast puts its class files in the bin/<packageName> directory, and that's where Eclipse expects to find them when you select the run configuration. But with the Maven nature, the files end up in target/classes/<packageName>, which you can't even see in the Eclipse package explorer. (You can see them in the PROJECT explorer, if you change the default filters.) To allow the run configuration to find the class files, edit <projectName>.rs/user_path.xml. The default Repast version contains this element: > <classpath> <agents path="../bin" /> <entry path="../lib" /> </classpath> Change the agents path entry to <agents path="../target/classes" />, and now your run configuration will find and run your masterpiece. -- H. Van Dyke Parunak, Ph.D. President, ABC Research, LLC <http://www.abcresearch.org> Superior solutions through Agent-Based and Complex systems 1027 Ferdon Road Ann Arbor, MI 48104-3630 email: van...@gm... cell: 734 395 3253 www.ABCResearch.org <http://www.abcresearch.org> |