Internal Action was not loaded Error: java.lang.ClassNotFoundException - java

I am trying to run an implementation a jason code that is using some Internal Actions. The interpreter is showing that it was not possible to find the "java" code of the internal action, as showed:
Server running on http://191.36.8.42:3272
[aslparser] [peleus.asl:29] warning: The internal action class for 'org.soton.peleus.act.plan(Goals)' was not loaded! Error:
java.lang.ClassNotFoundException: org.soton.peleus.act.plan
[aslparser] [peleus.asl:42] warning: The internal action class for 'org.soton.peleus.act.isTrue(H)' was not loaded! Error:
java.lang.ClassNotFoundException: org.soton.peleus.act.isTrue
[peleus] Could not finish intention: intention 1: +des([on(b3,table),on(b2,b3),on(b1,b2)])[source(self)] <- ... org.soton.peleus.act.plan(Goals); !checkGoals(Goals); .print("Goals ",Goals," were satisfied") /
{Goals=[on(b3,table),on(b2,b3),on(b1,b2)]}Trigger: +des([on(b3,table),on(b2,b3),on(b1,b2)])[noenv,code(org.soton.peleus.act.plan([on(b3,table),on(b2,b3),on(b1,b2)])),code_line(29),code_src("peleus.asl"),error(action_failed),error_msg("no environment configured!"),source(self)]
[peleus] Adding belief clear(table)
This mas2j file is as following:
MAS peleus {
infrastructure: Centralised
agents:
peleus;
}
Part of agent code (written by Felipe Meneguzzi) is showed bellow:
//The next line is line 28
+des(Goals) : true
<- org.soton.peleus.act.plan(Goals);
!checkGoals(Goals);
.print("Goals ",Goals," were satisfied").
+!checkGoals([]) : true <- true.
//The next line is line 40
+!checkGoals([H|T]) : true
<- .print("Checking ", H);
org.soton.peleus.act.isTrue(H);
!checkGoals(T).
I guess it is about the folder structure, how to set up Jason to search for java files in specific locations?
The folders structure is like this:
Peleus\src\org\soton\peleus for java files
Peleus\examples for mas2j and asl tested project

It all depends on how you are executing the application.
If you are using java, the CLASSPATH should be defined to include the missing classes.
if you are using jason script (that uses Ant), the .mas2j file should include the class path as well.
More on that in the FAQ. Notice that CLASSPATH is where .class files are found, not .java source code files. The error regards a missing class, not a missing source code.

Related

Executing the single code java file using java Vs javac using jdk11

I am using JDK11. Below is my sample class -
public class SayHi {
public static void main(String[] args) {
System.out.println("Hi There");
}
}
I executed the above class with command "java filename.java" for below scenarios
ColumnA -> Class declared as public?
ColumnB -> File name same as class name?
ColumnA ColumnB Result
Yes Yes Yes
No Yes Yes
*Yes No Yes
No No Yes
For all the scenarios, the command executed successfully and I got the result. I get compile-time error for the "Yes-No" case, if I run the "javac" command on the file name.
Why I am not getting the compile-time error when I am executing "java" command on the file name?
I have multiple public classes in a single code file. I am able to execute the file using "java filename.java" command. What I am missing with the compile-time issues when running the file with "java" command. Please help me on this.
The answers to all your questions can be found in JEP 330. I believe the following excerpts provide answers to your questions.
the first class found in the source file is executed
The source file should contain one or more top-level classes, the first of which is taken as the class to be executed
The compiler does not enforce the optional restriction defined at the end of JLS ยง7.6, that a type in a named package should exist in a file whose name is composed from the type name followed by the .java extension
In other words, when you compile a java source code file with javac, the source code file must contain a single, "public" class whose name matches the name of the file. But when you run a java source code file using the java command, the above restriction does not apply.
The class to be executed is the first top-level class found in the source file. It must contain a declaration of the standard public static void main(String[]) method.

How to customize the gradle error message from javacompile error

We want to custom or change the error log of JavaCompileTask.
We used a special java source location "build\intermediates\merged\main\java" which contains some processed java code that generated before JavaCompileTask executing.Now, when the task compile error and it prints the source code path start with "build\intermediates\merged\main\java". We want to replace the "build/**" preifix with original source code , then we can click the console link and jump to the correct file.
Gadle 3.5, AndroidPlugin 2.3.3 Jdk8
The console is showing the code path which was not what we wanted.
D:\m4399_GameCenter\app\build\intermediates\merged\main\java\com\m4399\gamecenter\plugin\main\models\shop\ShopExchangeRecommendAppModel.java:29: error: ShopExchangeRecommendAppModel was not abstract, and not override method getTorrentId() of IAppDownloadModel
We want to format it to :
D:\m4399_GameCenter\app\src\main\java\com\m4399\gamecenter\plugin\main\models\shop\ShopExchangeRecommendAppModel.java:29: error: ShopExchangeRecommendAppModel was not abstract, and not override method getTorrentId() of IAppDownloadModel .

Why Scala on Mac fails when run in unicode directory

I am attempting to simply compile a helloworld scala file from within a directory named using unicode characters but the scala compiler fails to run. It succeeds when I change directory's out the unicode named folder.
Detail
Given a classic Helloworld.scala class such as the one below
that is located in the directory:
/Users/me/Dev/Company/๐”˜๐”ซ๐”ฆ๐” ๐”ฌ๐”ก๐”ข/code_folder
I am unable to run scalac on the code if my current directory is in code_folder which is the root directory for the Helloworld.scala. When I change directories out of the folder with the unicode name /๐”˜๐”ซ๐”ฆ๐” ๐”ฌ๐”ก๐”ข, the compiler works just fine on the same code. So it would seem that scalac doesnt work when attempting to compile code while in a folder with unicode characters.
Why is that? Is this a system error? An unparsed unicode error between the OS starting the scalac process?
object Main{
def main(args: Array[String]): Unit = {
println("Hello world")
}
}
I expected a compiled file. The error I get is this
Exception in thread "main" java.lang.ExceptionInInitializerError
at scala.tools.util.PathResolver$Environment$.scalaExtDirs(PathResolver.scala:77)
at scala.tools.util.PathResolver$Defaults$.scalaExtDirs(PathResolver.scala:127)
at scala.tools.nsc.settings.StandardScalaSettings.$init$(StandardScalaSettings.scala:31)
at scala.tools.nsc.settings.MutableSettings.<init>(MutableSettings.scala:28)
at scala.tools.nsc.Settings.<init>(Settings.scala:19)
at scala.tools.nsc.Driver.process(Driver.scala:53)
at scala.tools.nsc.Driver.main(Driver.scala:80)
at scala.tools.nsc.Main.main(Main.scala)
Caused by: java.lang.IllegalArgumentException: Error decoding percent encoded characters
at java.base/sun.net.www.ParseUtil.decode(ParseUtil.java:209)
at java.base/jdk.internal.loader.FileURLMapper.getPath(FileURLMapper.java:64)
at java.base/jdk.internal.loader.FileURLMapper.exists(FileURLMapper.java:73)
at java.base/jdk.internal.loader.URLClassPath$JarLoader.getJarFile(URLClassPath.java:802)
at java.base/jdk.internal.loader.URLClassPath$JarLoader.access$900(URLClassPath.java:692)
at java.base/jdk.internal.loader.URLClassPath$JarLoader$1.run(URLClassPath.java:751)
at java.base/jdk.internal.loader.URLClassPath$JarLoader$1.run(URLClassPath.java:744)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at java.base/jdk.internal.loader.URLClassPath$JarLoader.ensureOpen(URLClassPath.java:743)
at java.base/jdk.internal.loader.URLClassPath$JarLoader.<init>(URLClassPath.java:718)
at java.base/jdk.internal.loader.URLClassPath$3.run(URLClassPath.java:486)
at java.base/jdk.internal.loader.URLClassPath$3.run(URLClassPath.java:469)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at java.base/jdk.internal.loader.URLClassPath.getLoader(URLClassPath.java:468)
at java.base/jdk.internal.loader.URLClassPath.getLoader(URLClassPath.java:437)
at java.base/jdk.internal.loader.URLClassPath.findResource(URLClassPath.java:280)
at java.base/jdk.internal.loader.BuiltinClassLoader.findResourceOnClassPath(BuiltinClassLoader.java:479)
at java.base/jdk.internal.loader.BuiltinClassLoader.findResource(BuiltinClassLoader.java:303)
at java.base/java.lang.ClassLoader.getResource(ClassLoader.java:1393)
at java.base/java.lang.ClassLoader.getSystemResource(ClassLoader.java:1658)
at java.base/java.lang.ClassLoader.getSystemResourceAsStream(ClassLoader.java:1762)
at java.base/java.lang.Class.getResourceAsStream(Class.java:2607)
at scala.util.PropertiesTrait.scalaProps(Properties.scala:39)
at scala.util.PropertiesTrait.scalaProps$(Properties.scala:37)
at scala.tools.reflect.WrappedProperties$AccessControl$.scalaProps$lzycompute(WrappedProperties.scala:49)
at scala.tools.reflect.WrappedProperties$AccessControl$.scalaProps(WrappedProperties.scala:49)
at scala.util.PropertiesTrait.scalaPropOrNone(Properties.scala:71)
at scala.util.PropertiesTrait.scalaPropOrNone$(Properties.scala:71)
at scala.tools.reflect.WrappedProperties$AccessControl$.scalaPropOrNone(WrappedProperties.scala:49)
at scala.util.PropertiesTrait.$init$(Properties.scala:83)
at scala.tools.reflect.WrappedProperties$AccessControl$.<init>(WrappedProperties.scala:49)
at scala.tools.reflect.WrappedProperties$AccessControl$.<clinit>(WrappedProperties.scala)
... 8 more
Version:
scalac -version
Scala compiler version 2.12.8 -- Copyright 2002-2018, LAMP/EPFL and Lightbend, Inc.
MacOS version 10.13.6
Not really a solution, but some piece of information:
I set up my folder this way:
/home/nicolas/Private/๐”˜๐”ซ๐”ฆ๐” ๐”ฌ๐”ก๐”ข/
When the ClassLoader tries to load the classes of your project it makes a list of paths where to lookup classes as a list of URLClassPath
Now when the code goes on and it tries to parse these paths, it calls sun.net.www.ParseUtil.decode()
When I put a breakpoint in here, I can see that the path for our class is:
/home/nicolas/Private/%ed%a0%b5%ed%b4%98%ed%a0%b5%ed%b4%ab%ed%a0%b5%ed%b4%a6%ed%a0%b5%ed%b4%a0%ed%a0%b5%ed%b4%ac%ed%a0%b5%ed%b4%a1%ed%a0%b5%ed%b4%a2/target/scala-2.12/classes/
so it somehow translated ๐”˜๐”ซ๐”ฆ๐” ๐”ฌ๐”ก๐”ข into a percent encoded string : %ed%a0%b5%ed%b4%98%ed%a0%b5%ed%b4%ab%ed%a0%b5%ed%b4%a6%ed%a0%b5%ed%b4%a0%ed%a0%b5%ed%b4%ac%ed%a0%b5%ed%b4%a1%ed%a0%b5%ed%b4%a2
This in turn creates a CharsetDecoder for UTF-8:
CharsetDecoder dec = ThreadLocalCoders.decoderFor("UTF-8")
.onMalformedInput(CodingErrorAction.REPORT)
.onUnmappableCharacter(CodingErrorAction.REPORT);
and tries to decode the above url but it fails and that is why the classes can't be loaded.
Now if I go here https://www.branah.com/unicode-converter and tries to convert ๐”˜๐”ซ๐”ฆ๐” ๐”ฌ๐”ก๐”ข to a % encoded string, it gives me
%f0%9d%94%98%f0%9d%94%ab%f0%9d%94%a6%f0%9d%94%a0%f0%9d%94%ac%f0%9d%94%a1%f0%9d%94%a2
And if when I debug, I change the url using this encoded string value, ie
/home/nicolas/Private/%f0%9d%94%98%f0%9d%94%ab%f0%9d%94%a6%f0%9d%94%a0%f0%9d%94%ac%f0%9d%94%a1%f0%9d%94%a2/target/scala-2.12/classes/
Then it parses it properly and keeps going.
So I don't know where it gets that %ed%a0%b5%ed%b4%98%ed%a0%b5%ed%b4%ab%ed%a0%b5%ed%b4%a6%ed%a0%b5%ed%b4%a0%ed%a0%b5%ed%b4%ac%ed%a0%b5%ed%b4%a1%ed%a0%b5%ed%b4%a2
The interesting thing is that if I use the same website and try to convert back %ed%a0%b5%ed%b4%98%ed%a0%b5%ed%b4%ab%ed%a0%b5%ed%b4%a6%ed%a0%b5%ed%b4%a0%ed%a0%b5%ed%b4%ac%ed%a0%b5%ed%b4%a1%ed%a0%b5%ed%b4%a2 then I also get ๐”˜๐”ซ๐”ฆ๐” ๐”ฌ๐”ก๐”ข
So I am a bit confused

RobotFramework ImportError: No module named foo

I have a class in Java which looks like this:
package com.charandeepmatta.keywords;
import org.robotframework.javalib.annotation.RobotKeyword;
import org.robotframework.javalib.annotation.RobotKeywords;
#RobotKeywords
public class SampleKeywords {
#RobotKeyword
public void printToErrorStream() {
System.err.println("!!! Hello from keyword developed in java ...");
}
}
And my test case looks like this
*** Settings ***
Library org.robotframework.javalib.library.AnnotationLibrary /**.class
*** Test Cases ***
Keyword defined in java class can print to error stream
Print To Error Stream
When I try to run it on RIDE it gives me the following error
[ ERROR ] Error in file 'C:\Users\BFerreira\git\robotframework-maven-project\src\main\robot\suite\OwnDevelopedKeywordTestCase.txt':
Importing test library 'org.robotframework.javalib.library.AnnotationLibrary' failed:
ImportError: No module named org.robotframework.javalib.library
Traceback (most recent call last):
None
PYTHONPATH:
C:\Python27\lib\site-packages\robot\libraries
C:\Python27\lib\site-packages
C:\Windows\system32\python27.zip
C:\Python27\DLLs
C:\Python27\lib
C:\Python27\lib\plat-win
C:\Python27\lib\lib-tk
C:\Python27
C:\Python27\lib\site-packages\wx-2.8-msw-unicode
.
C:\Users\user1\git\robotframework-maven-project\src\main\robot\suite
Everything is in the same classpath, can anyone help?
From the looks of your output, you are not executing with jybot/Jython. Jython is required to load Java classes in a Python interpreter. Here is what the output would look like if you were:
PYTHONPATH:
C:\apps\Python27\Lib\site-packages
C:\apps\jython2.5.3\Lib\site-packages\setuptools-0.6c11-py2.5.egg
C:\apps\jython2.5.3\Lib\site-packages\pip-1.2.1-py2.5.egg
C:\apps\jython2.5.3\Lib
__classpath__
__pyclasspath__/
C:\apps\jython2.5.3\Lib\site-packages
.
c:\ws\local
CLASSPATH:
C:\apps\jython2.5.3\jython.jar
A word of caution: if you run the Robot Framework jar (e.g. java -jar robotframework-2.5.3.jar ...) as some examples suggest, all classpath settings are ignored. You would have to put all your dependencies in one jar for that way to work...

Error in Udf of pig

I am new to pig. I wrote a UDF in pig and used it in my pig script. But it gives following error
ERROR org.apache.pig.tools.grunt.Grunt - ERROR 1070: Could not resolve UserDefined.PartsOfSpeech using imports: [, java.lang., org.apache.pig.builtin., org.apache.pig.impl.builtin.]
Here is my UDF code
public String exec(Tuple input) throws IOException {
//my code here
}
Here is my pig script
REGISTER /home/bigdata/NetBeansProjects/UserDefined/dist/UserDefined.jar
a = load '/user/bigdata/json' using TextLoader() as (input:chararray);
b = foreach a GENERATE UserDefined.PartsOfSpeech(input);
In the above code UserDefined is my package name and PartsOfSpeech is my class name
The error message says that Pig cannot find UserDefined.PartsOfSpeech.
What package declaration does PartsOfSpeech.java have at the top of the file?
If the package declaration is package com.my.company; try this instead:
REGISTER /home/bigdata/NetBeansProjects/UserDefined/dist/UserDefined.jar
a = load '/user/bigdata/json' using TextLoader() as (input:chararray);
b = foreach a GENERATE com.my.company.PartsOfSpeech(input);
That is, replace UserDefined.PartsOfSpeech(input) with com.my.company.PartsOfSpeech(input) since the UDF is located in the package com.my.company.
Also, consider using the DEFINE keyword in your Pig script so you don't need to repeat com.my.company every time you use PartsOfSpeech.
DEFINE PartsOfSpeech UserDefined.dist.PartsOfSpeech();
REGISTER /home/bigdata/NetBeansProjects/UserDefined/dist/UserDefined.jar
a = load '/user/bigdata/json' using TextLoader() as (input:chararray);
b = foreach a GENERATE PartsOfSpeech(input);
There is more information about DEFINE in Chapter 5 of Alan Gates' Programming Pig: http://chimera.labs.oreilly.com/books/1234000001811/ch05.html#udf_define.
Here is an example of DEFINE from Gates' book:
--define.pig
register 'your_path_to_piggybank/piggybank.jar';
define reverse org.apache.pig.piggybank.evaluation.string.Reverse();
divs = load 'NYSE_dividends' as (exchange:chararray, symbol:chararray,
date:chararray, dividends:float);
backwards = foreach divs generate reverse(symbol);
Before compiling your UDF(java class) make sure you have mentioned package name properly. for example if you have mentioned package name-
package com.pig.udf;
It means you need to take care of directory in your linux box as well.
you can follow below mentioned steps to create jar -
Create directory using
mkdir -p com/pig/udf
Create your java class with package com.pig.udf
Compile your java source code using command
javac -cp /usr/lib/pig-0.12.0.2.0.6.0-76.jar YourClass.java
Then go to the directory where you want to create jar for now -
cd ../../..
Now create jar using below command
jar -cvf yourJarName.jar com/
Register the jar in your script using keyword "register" followed by path of the jar
Now use your jar with keyword com.pig.udf.YourJavaClassName
for your scenerio -
REGISTER /home/bigdata/NetBeansProjects/UserDefined/dist/UserDefined.jar
a = load '/user/bigdata/json' using TextLoader() as (input:chararray);
b = foreach a GENERATE com.pig.udf.PartsOfSpeech(input);

Categories