In response to a number of queries about running Maven projects, please find a sample Maven project for CSC8110 available for download here.
You may use this project as the starting point for your CSC8110 coursework.
Note
|
You will see yourname mentioned in the directory structure, and in the pom.xml file. Before submission you will want to change this to be your own name (e.g. your university email address without any full stops). This will require you to rename two folder in the directory structure (csc8110/src/main/java/uk/ac/ncl/yourname and csc8110/src/test/java/uk/ac/ncl/yourname ) and lines 4 and 57 of your pom.xml file. This will also slightly change the commands for running your Maven project; where yourname appears in a command will be updated. If in doubt, ask a demonstrator for help renaming your project during the third week of the module, and we’ll be happy to help. :-)
|
Type the following command at the terminal / command prompt:
mvn clean package
This will create two JAR files in your target/
directory, one called csc8110-1.0-SNAPSHOT.jar
and the other csc8110-1.0-SNAPSHOT-jar-with-dependencies.jar
.
-
csc8110-1.0-SNAPSHOT.jar
is a Java ARchive file containing the source code you have created. -
csc8110-1.0-SNAPSHOT-jar-with-dependencies.jar
is a Java ARchive which also includes the code for any libraries your project depends on (in this example, the Azure Service Bus library). This is thejar
file you are going to want to use to run your project.
To run your application from the command line, type the following command at the terminal / command prompt:
java -cp target/csc8110-1.0-SNAPSHOT-jar-with-dependencies.jar uk.ac.ncl.yourname.csc8110.App
…where…
-
java
is the command to run your application. -
-cp target/csc8110-1.0-SNAPSHOT-jar-with-dependencies.jar
adds your Java ARchive file to the classpath so Java knows what it should be running.
-
uk.ac.ncl.yourname.csc8110.App
is the name of the class containing amain(String[] args)
method.
Simply download the sample project, inspec the pom.xml
file and copy everything between <build>…</build>
into your project. This will mean everything will run smoothly.
An existing bug in the Azure library for Java may lead to a Service or property not registered
error when running your application on the command line through Maven.
If you encounter an error message such as the following, please run rm -r target
to remove your target directory, then run mvn clean package
twice, and this should fix the issue for you.
It is important to note that if you receive the message below, this is due to the Azure bug and cannot be caused by errors in your code. Persevere repeating the steps above and this should fix the issue for you.
Exception in thread "main" java.lang.RuntimeException: Service or property not registered: com.microsoft.windowsazure.services.servicebus.ServiceBusContract class com.sun.jersey.api.client.Client at com.microsoft.windowsazure.core.DefaultBuilder.build(DefaultBuilder.java:198) at com.microsoft.windowsazure.core.DefaultBuilder$1.create(DefaultBuilder.java:138) at com.microsoft.windowsazure.core.DefaultBuilder.build(DefaultBuilder.java:200) at com.microsoft.windowsazure.core.DefaultBuilder$1.create(DefaultBuilder.java:138) at com.microsoft.windowsazure.core.DefaultBuilder.build(DefaultBuilder.java:200) at com.microsoft.windowsazure.Configuration.create(Configuration.java:113) at com.microsoft.windowsazure.services.servicebus.ServiceBusService.create(ServiceBusService.java:51) at uk.ac.ncl.yourname.AzureBusHandler.<init>(AzureBusHandler.java:42) at uk.ac.ncl.yourname.Producer.main(Producer.java:25)