The purpose of this project is to make it easier to work with LBJava and Maven. This is a plugin written for Maven. To use this, you need to modify your pom.xml file to depend on this plugin (see POM file section). You may also need to modify your project layout to be Maven compatible (see Project setup). Instructions for usage are in the Usage section.
Note: Make sure to change the pom.xml parameter LBJAVA-VERSION
to the latest version of LBJava.
Put the following into your pom.xml:
<build>
<plugins>
...
<plugin>
<groupId>edu.illinois.cs.cogcomp</groupId>
<artifactId>lbjava-maven-plugin</artifactId>
<version>LBJAVA-VERSION</version>
<configuration>
<dFlag>lbjava/class/output/</dFlag>
<gspFlag>path/to/intended/lbjavasrc/output</gspFlag>
<sourcepathFlag>path/to/src</sourcepathFlag>
<lbjavaInputFileList>
<param>path/to/lbjavafile.lbj</param>
<param>path/to/second/lbjavafile2.lbj</param>
<param>etc/etc.lbj</param>
</lbjavaInputFileList>
</configuration>
</plugin>
...
</plugins>
</build>
Parameters are:
dFlag
: corresponds to the -d flag in LBJava (optional, default is target/classes)gspFlag
: corresponds to the -gsp flag in LBJava (optional, default is src/main/java)sourcepathFlag
: corresponds to the -sourcepath flag in LBJava (optional, default is src/main/java)lbjInputFileList
: each param is a path to the LBJava input file you want to compile
Note that some parameters are optional and have default values. Note also that these are simply the flags given to LBJava's Main class. These are documented in the LBJava User Guide.
NB: In case you get a repository error you should add edu.illinois.cs.cogcomp as a plugin repository:
<pluginRepositories>
...
<pluginRepository>
<id>CogcompSoftware</id>
<name>CogcompSoftware</name>
<url>http://cogcomp.cs.illinois.edu/m2repo/</url>
</pluginRepository>
...
</pluginRepositories>
Here's an example without the optional parameters. This is as simple as it gets, folks.
<build>
<plugins>
...
<plugin>
<groupId>edu.illinois.cs.cogcomp</groupId>
<artifactId>lbjava-maven-plugin</artifactId>
<version>LBJAVA-VERSION</version>
<configuration>
<lbjavaInputFileList>
<param>lbjava/MyClassifier.lbj</param>
</lbjavaInputFileList>
</configuration>
</plugin>
...
</plugins>
</build>
To compile your LBJava file and execute the LBJava code, run the following:
mvn lbjava:compile
This will compile all Java files pertinent to the .lbj file, then generate Java
files from the .lbj file. These generated Java files are put in a location which is
determined by two things: the gspFlag
parameter, and the package at the top of the .lbj file.
For example, if gspFlag
is src/main/java (the default), and the package is "my.package" then the
generated Java files are put in ./src/main/java/my/package/
The model files (*.lc, *.lex) are put in the directory determined by the dFlag
parameter.
By default, this is target/classes.
If you only want generate the Java translations of the LBJava code but not execute it, you can run:
mvn lbjava:generate
Then to compile all classes run:
mvn compile
If you want to remove the Java files generated by running "mvn lbj:compile", then run the following:
mvn lbjava:clean
(Of course, to remove target/classes, you run mvn clean
. This is standard maven practice)
NB: If the generated Java files already exist (from a previous run of lbjava:compile
or lbjava:compile-only
) you need to run lbjava:clean
before compiling again.
If you want to include the plugin execution during the mvn compile phase you can change the plugin definition as follows:
<plugin>
<groupId>edu.illinois.cs.cogcomp</groupId>
<artifactId>lbjava-maven-plugin</artifactId>
<version>LBJAVA-VERSION</version>
<configuration>
<lbjavaInputFileList>
<param>lbjava/MyClassifier.lbj</param>
</lbjavaInputFileList>
</configuration>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>clean</goal>
<goal>compile</goal>
</goals>
</execution>
</executions>
</plugin>
This plugin assumes you have set up your project in the normal maven style. That is, something like the following:
.
├── pom.xml
├── README.txt
├── src
│ └── main
│ ├── java
│ │ └── edu
│ │ └── illinois
│ │ └── cs
│ │ └── cogcomp
│ │ └── [java files]
│ ├── lbjava
│ │ └── MyLBJClassifier.lbj
│ └── resources
│ └── [resource files]
└── target
└── classes
└── edu
└── illinois
└── cs
└── cogcomp
└── [generated class files]
The way it works is simple: under the hood, the plugin calls
java ... edu.illinois.cs.cogcomp.lbjava.Main ...
with parameters defined in the pom.xml (see POM file section).
Because of innumerable classpath issues, this was the easiest way I could find to do this.
This should work in eclipse with no extra hassle.
NB: This applies only if you are using the option. In the latest incarnation of m2e (Maven for Eclipse) you need to explicitly define that the plugin should be allowed to execute. To do this add the following:
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.eclipse.m2e</groupId>
<artifactId>lifecycle-mapping</artifactId>
<version>1.0.0</version>
<configuration>
<lifecycleMappingMetadata>
<pluginExecutions>
<pluginExecution>
<pluginExecutionFilter>
<groupId>edu.illinois.cs.cogcomp</groupId>
<artifactId>lbjava-maven-plugin</artifactId>
<versionRange>LBJAVA-VERSION</versionRange>
<goals>
<goal>clean</goal>
<goal>compile</goal>
<goal>generate</goal>
</goals>
</pluginExecutionFilter>
<action>
<execute />
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
- Stephen Mayhew: Nov 22, 2013 (v1.0)
- Christos Christodoulopoulos: Mar 20, 2015 (v1.2)