diff --git a/doc/jason-cli/commands.adoc b/doc/jason-cli/commands.adoc index 172f8486..227a2220 100644 --- a/doc/jason-cli/commands.adoc +++ b/doc/jason-cli/commands.adoc @@ -18,6 +18,7 @@ commands to handle applications Commands: create creates the files of a new application compile compiles the java classes of an application (using Gradle) + and produces a jar file with all necessary to run the application add-agent adds the code of a new agent into the application add-gradle adds a Gradle script for the application add-ia adds the source code a new internal action into the application diff --git a/doc/jason-cli/readme.adoc b/doc/jason-cli/readme.adoc index 0bfdaaa5..fbf98779 100644 --- a/doc/jason-cli/readme.adoc +++ b/doc/jason-cli/readme.adoc @@ -6,7 +6,7 @@ The Jason CLI is a command-line interface tool that you use to initialize, devel include::../install.adoc[] -== Create Applications +== Create and Execute Applications New Jason applications can be created and executed with: @@ -23,7 +23,7 @@ The first command creates a Jason application identified by `app1` with two agen [alice] hello world. ``` -This approach uses Gradle to execute the application. Gradle is useful if you are using other packages. However, it you do not have dependencies, the application can be started faster without Gradle: +This approach uses Gradle to execute the application. Gradle is useful if you are using other packages. However, if you do not have dependencies, the application can be started faster without Gradle: ``` jason mas start --mas2j=app1.mas2j diff --git a/doc/release-notes.adoc b/doc/release-notes.adoc index 57397d9f..fb9f0a75 100644 --- a/doc/release-notes.adoc +++ b/doc/release-notes.adoc @@ -16,6 +16,8 @@ * `jason x.mas2h` uses gradle to run the application * `jason mas start --mas2j=x.mas2h` runs without gradle. The classpath might be informed using `--cp` if necessary. + * `jason app compile` uses shadowJar to create a jar file with all files and dependencies to run the application. + - update doc for new Jason web site: https://jason-lang.github.io diff --git a/jason-cli/src/main/java/jason/cli/app/Compile.java b/jason-cli/src/main/java/jason/cli/app/Compile.java index 682dff83..1eebfe75 100644 --- a/jason-cli/src/main/java/jason/cli/app/Compile.java +++ b/jason-cli/src/main/java/jason/cli/app/Compile.java @@ -8,7 +8,7 @@ @Command( name = "compile", - description = "compiles the java classes of the application in the current directory (using Gradle)" + description = "compiles the java classes of the application in the current directory (using Gradle) and produces a jar file with all necessary to run the application" ) public class Compile extends Common implements Runnable { @@ -26,6 +26,9 @@ public void run() { getGradleBuild(connection) .forTasks("compileJava") .run(); + getGradleBuild(connection) + .forTasks("shadowJar") + .run(); if (created) { // delete created files diff --git a/jason-interpreter/src/main/java/jason/infra/local/RunLocalMAS.java b/jason-interpreter/src/main/java/jason/infra/local/RunLocalMAS.java index d0b633e2..9805dd63 100644 --- a/jason-interpreter/src/main/java/jason/infra/local/RunLocalMAS.java +++ b/jason-interpreter/src/main/java/jason/infra/local/RunLocalMAS.java @@ -124,7 +124,7 @@ public int init(String[] args) { if (RunLocalMAS.class.getResource("/"+defaultProjectFileName) != null) { projectFileName = defaultProjectFileName; appFromClassPath = true; - Config.get(false); // to void to call fix/store the configuration in this case everything is read from a jar file + //Config.get(false); // to void to call fix/store the configuration in this case everything is read from a jar file } else { if (!(boolean)(initArgs.getOrDefault("empty-mas", false))) { System.out.println("Jason " + Config.get().getJasonVersion()); diff --git a/jason-interpreter/src/main/java/jason/runtime/SourcePath.java b/jason-interpreter/src/main/java/jason/runtime/SourcePath.java index 3fb9c5f9..39cbeed2 100644 --- a/jason-interpreter/src/main/java/jason/runtime/SourcePath.java +++ b/jason-interpreter/src/main/java/jason/runtime/SourcePath.java @@ -115,7 +115,7 @@ public String fixPath(String f) { if (f.startsWith("$")) { // the case of "$jason/src/a.asl" String jar = f.substring(1,f.indexOf("/")); if (Config.get().getPackage(jar) == null) { - System.err.println("The included file '"+jar+"' is not configured"); + System.err.println("The included '$"+jar+"' is not configured"); } else { var nf = "jar:file:" + Config.get().getPackage(jar).getAbsolutePath() + "!" + f.substring(f.indexOf("/")); if (testURLSrc(nf)) diff --git a/jason-interpreter/src/main/java/jason/stdlib/include.java b/jason-interpreter/src/main/java/jason/stdlib/include.java index ed085bb9..a6bcad86 100644 --- a/jason-interpreter/src/main/java/jason/stdlib/include.java +++ b/jason-interpreter/src/main/java/jason/stdlib/include.java @@ -31,26 +31,6 @@ */ -@Manual( - literal=".include(file[,namespace])", - hint="loads an .asl file, i.e., includes beliefs, goals, and plans from a file optionally in a namespace", - argsHint= { - "the file name or any valid URL", - "sets the name space where the included components (bels, plans, ...) will be placed [optional]" - }, - argsType= { - "string", - "atom or var" - }, - examples= { - ".include(\"x.asl\")", - ".include(\"https://raw.githubusercontent.com/jason-lang/jason/master/examples/auction/ag3.asl\")", - ".include(\"jar:file:/Users/jomi/lib/test.jar!/l.asl\") includes from a local jar file." - }, - seeAlso= { - "" - } - ) @SuppressWarnings("serial") public class include extends DefaultInternalAction { diff --git a/jason-interpreter/src/main/java/jason/util/Config.java b/jason-interpreter/src/main/java/jason/util/Config.java index 6c5349ec..f5190b89 100644 --- a/jason-interpreter/src/main/java/jason/util/Config.java +++ b/jason-interpreter/src/main/java/jason/util/Config.java @@ -321,6 +321,8 @@ public boolean tryToFixJarFileConf(String jarEntry, String jarFileNamePrefix) { return true; } } catch (Exception e) {} + if (showFixMsgs) + System.out.println("Configuration of '"+jarEntry+"' NOT found, based on class loader"); // try to get from classpath (the most common case) jarFile = getJarFromClassPath(jarFileNamePrefix, fileInJar); @@ -331,7 +333,7 @@ public boolean tryToFixJarFileConf(String jarEntry, String jarFileNamePrefix) { return true; } if (showFixMsgs) - System.out.println("Configuration of '"+jarEntry+"' NOT found, based on class loader"); + System.out.println("Configuration of '"+jarEntry+"' NOT found, based on class path: "+System.getProperty("java.class.path")); // try with $JASON_HOME String jh = System.getenv().get("JASON_HOME"); diff --git a/jason-interpreter/src/main/resources/templates/build.gradle b/jason-interpreter/src/main/resources/templates/build.gradle index d6d35d26..f315b34e 100644 --- a/jason-interpreter/src/main/resources/templates/build.gradle +++ b/jason-interpreter/src/main/resources/templates/build.gradle @@ -5,9 +5,12 @@ */ -defaultTasks 'run' +plugins { + id 'com.gradleup.shadow' version '8.3.3' + id 'java' +} -apply plugin: 'java' +defaultTasks 'run' // set version of group for your project //version '1.0' @@ -60,3 +63,42 @@ task runJade (type: JavaExec, dependsOn: 'classes') { // and all usual JADE options for jade.Boot classpath sourceSets.main.runtimeClasspath } + +shadowJar { + doFirst { + copy { + from '' + rename '','default.mas2j' + into project.projectDir.absolutePath + '/' + } + } + archiveFileName = "jason-${project.name}-all.jar" // the name must start with jacamo so that jacamo...jar is found in the classpath + from (project.projectDir.absolutePath + '/src') { + include '**/*.asl' + include '**/*.xml' + include '**/*.sai' + include '**/*.ptl' + include '**/*.jcm' + include '*.properties' + exclude 'test' + } + from (project.buildDir.absolutePath + '/classes') { + include '**/*' + } + from (project.buildDir.absolutePath + '/jcm') { + include '**/*' + } + from (project.projectDir.absolutePath + '/') { + include '*.properties' + include 'default.mas2j' + } + + manifest { + attributes 'Main-Class': 'jason.infra.local.RunLocalMAS' + } + + doLast { + println("You can run your application with: java -jar build/libs/jason-${project.name}-all.jar") + } +} +