Import Java library in RIDE - java

I'm trying to use a java library in RIDE. I found a good tutorial( https://blog.codecentric.de/en/2012/06/robot-framework-tutorial-writing-keyword-libraries-in-java/)
I follow it, but when the time comes to import and use the java library ( Database Library)in RIDE. It fails. When I look the page with my different imports, the java library is written in red and not in black as the others.
And when I try to run with Jybot, I have the well-known message :
[ ERROR ] Error in file 'C:\Users\XXXXXX\Documents\Robot_Test\implementation\DB_Test\Example.html': Importing test library 'org.robot.database.keywords.DatabaseLibrary' failed: ImportError: No module named robot
I follow every line of the tutorial, even the with the set CLASSPATH.
Any idea ? ( I know that this library exist in Python, but I want to write my own java libraries ^^)
Thanks

This worked for me using:
Jython 2.7b4
Robotframework 2.8.7
Ride 1.3
Create Lib and compile it (you do not need to jar it)
Directory structure is
run_ride.sh
libs/DemoLib.class
tests/DemoLibTest.txt
Excerpt from tests/DemoLibTest.txt:
* Settings
Library ../libs/DemoLib.class
* Test Cases
DemoLibTest
Print Demo
Start Ride, switch to tab "Run", choose Execution Profile: jybot, press Start, output is:
Starting test: tests.DemoLibTest.DemoLibTest
20150304 19:13:20.321 : INFO : ---------- Demo ---------------
To avoid confusion put this line
echo $CLASSPATH
in your Ride startup script in order to ensure that your library is really imported. By the way, in my Ride the import is also marked red. Sometimes restarting Ride might help. But the colour does not mean anything, if your settings are correct.

Related

VS Code - The import "#####" cannot be resolved

So, i am running a java project which have many library that are available in the current working directory but VS code seems to not recognize these library and giving out error "The import ###### cannot be resolved" ex: The import org.apache.pdfbox.pdmodel.PDDocument cannot be resolved"
here is the image that might help you to know more about it
This is the package that i am working on :
Here the org/apache is the library contain the class file that are need to be imported and FileArrangement.java is the file having the import statements
Error i have been receiving
this is what VS code is been showing
i really need your help because i really don't have any idea how to correct this
I have checked other projects and they are also showing the same result although the import statements for java classes like . java.util.ArrayList doesn't show any kind of error and i have tried to clean java in VS code it also didn't work
i just need to correct this error of VS code to import the classes that i need
No error on java.util package
Putting the libraries in your current working directory does not work for Java, you need to add them to the classpath.
If you're using maven, that manages the classpath for you.
If not, you can manage it in VS Code by executing the Java: Configure Classpath command from the Command Palette (Ctrl+Shift+P).
You can add dependencies via Referenced libraries under the JAVA PROJECTS panel.
Or use java.project.referencedLibraries setting in settings.json.
For example:
"java.project.referencedLibraries": [
"library/**/*.jar",
"/home/username/lib/foo.jar"
]
Details can be found in configure-classpath and manage-dependencies.

How to import packages from the external Library in Java?

I'm a n00b coder. I found an interesting library and trying to start toying with it. Which is not going great. This library is from 99' and uses JUnit (which I'm unfamiliar with) so there is a lot of confusing stuff. But it seems like the source of my failing even more elementary. Namely I have troubles importing packages.
This library has a test called StandardEvalTest.java. I moved to it to main Java directory and now I'm trying and failing to launch it using JUnit.
This package path org.pokersource.game.Deck goes directly from the directory where the test StandardEvalTest.java sits.
I also added the main java directory to the PATH environmental variable. Which as I assumed will allow import to locate the package.
None of those two things help. Also I was suspecting that maybe Deck.java and Deck.class are not enough and I have to do some work to create a package from it. But as far as I can say from Oracle doc the only thing needed is a package name in the header. Which seems to be present.
So I'm out of moves. Please help!
PS: Some additional info inspired by #Dhrubo 's answer:
The test I'm trying to run indeed sits in the main java folder of the library. (I moved it here hoping that when running from here it would be easier to find the package)
If I'm trying to compile the test instead of running it with JUnit he seem to fail to find JUnit classes and other JUnit related stuff.
[Oh OK I'm an idiot! Dont't mind me]
You should include the package while running StandardEvalTest.java as below
javac -cp [classpath] org.pokersource.game.StandardEvalTest.java
and run it from package root directory, I am assuming it is custom java file that you want to compile. You run directory should be parent of your package directory.
** I also see, you are trying to compile StandardEvalTest.java instead of Deck.java ... then check your StandardEvalTest.java file whether it exists in desired location.

The Eclipse IDE is able to generate the javacard cap file but in command line I am encountering this error

The below error compelled me to dig into the build process of a cap file in the command line without using the IDE. So now, I can build a cap file from the command line using java/javac series of commands. But I have this one applet which successfully created a cap file if built via eclipse IDE but I am encountering an error when i try to build in the command line. I am also having same error when I tried in a correctly setup gradle build settings/environment. This is the error:
[ant:convert] [ INFO: ] Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
[ant:convert]
[ant:convert]
[ant:convert] warning: You did not supply export file for the previous minor version of the package
[ant:convert] [ INFO: ] conversion completed with 1 errors and 1 warnings.
[ant:convert] error: Class org/dx/tools/TestApplet, specified in -applet option, is abstract.
Take note, this is a working and tested applet in combination with other applets that uses this one. And this builds in the eclipse IDE.
Also I am able to generate the .class file. The problem is during the convertion of the class file to cap file.
Here is how it look like:
package org.dx.tools;
import org.globalplatform.GPSystem;
import org.globalplatform.SecureChannel;
import javacardx.apdu.ExtendedLength;
import javacard.framework.ISO7816;
import javacard.framework.ISOException;
import javacard.framework.Util;
import javacard.framework.APDU;
import javacard.framework.APDUException;
import javacard.framework.Applet;
import javacard.framework.AppletEvent;
public abstract class TestApplet extends Applet implements AppletEvent,
ExtendedLength {
...
}
This .cap is one among five others. The others are not abstract, but inherits from this one. Since it build in eclipse IDE, I can actually build the other cap files by taking the output of the IDE had produce. First, I jar the classes since as I said I can create the classes and feed to java conversion command to build the other caps, and I also use the TestApplet.exp that the IDE generated.
UPDATES: 2019/11/17
Here is the actual java command options that is able to build from .class to .cap. I took this as exactly from the Eclipse IDE conversion log.
If an answer can confirm this is a current gradle limitation then I will accept this answer. If answer can show what is the correct gradle settings to make it work then I will accept this answer. Thanks.
This is very likely due to linking to a newer or older version of a library, while targeting a different Java Card version during your build process. Note that the converter creates pre-linked code, so it expects to link against the correct versions.
This is different from Java SE, where the classes can be linked at runtime and the location of methods and fields doesn't matter, as they are created during runtime.
I've resolved the issue by removing the applet {} block in build.gradle. As the particular cap being built is an abstract class, it does not have an applet aid.

how to complete user defined class methods using javacomplete

I am working under Mac OS X 10.7. I got javacomplete working with the help of pathogen, but it only completes JDK classes, not the classes I've created. When trying to omni-complete one of my objects I'm getting 'Pattern not found'. Is this really limited to JDK classes? If not, can anybody describe their config.
BTW, I've tried created ctags but it didn't work with javacomplete either. However, ctrl-x ctrl-] works fine with ctags created.
You need to set up the class path for your sources.
From the javacomplete documentation:
3. Set classpath using the following function: >
javacomplete#AddClassPath('jarfile_or_classes_path')
javacomplete#DelClassPath('jarfile_or_classes_path')
javacomplete#SetClassPath('semicolon_separated_string')
Another two variables will be used if they are existing:
|g:java_classpath| global classpath
|b:classpath| associated with current buffer
I have added the following to my .vimrc to auto-complete android projects:
if filereadable('AndroidManifest.xml')
call javacomplete#SetClassPath('/home/tidbeck/android/sdk/android-sdk-linux_x86/platforms/android-17/android.jar:libs/android-support-v4.jar:bin/classes')
call javacomplete#SetSourcePath('src')
endif
Two things that I noticed:
javacomplete#AddClassPath does not support jar files even though the docs say so
I had to remove my tags file to get completion to working
I've used javacomplete plugin along with supertab and i found that the easiet way to enable method completion is by using another plugin called easytags.vim that automatically creates tags as you compile your classes. From memory it did provide user defined Class and method completion.
After installing the vim plugin you have to add these lines into .vimrc:
" Only do this part when compiled with support for autocommands.
if has("autocmd")
autocmd Filetype java setlocal omnifunc=javacomplete#Complete
endif
I am, too, was unable to get it working with an existing tags file (created by ctags). As mentioned, one workaround is to unset the vim option tags inside .vimrc. But this was not an option for me.
I just manipulated javacomplete.vim to "ignore" the tags file.
Patch follows:
--- autoload/javacomplete.vim 2011-01-30 21:33:46.000000000 +0100
+++ /home/kndl/.vim/autoload/javacomplete.vim 2015-02-12 20:46:48.227465321 +0100
## -2510,7 +2510,8 ##
fu! s:GetClassInfoFromSource(class, filename)
let ci = {}
if len(tagfiles()) > 0
- let ci = s:DoGetClassInfoFromTags(a:class)
+ " kndl: Deactivate ctags feature as this does not work. It seems that I am unable to build an accepted tags file.
+ "let ci = s:DoGetClassInfoFromTags(a:class)
endif
if empty(ci)

Conditional compilation: Getting and testing the package name at compile time

There are numerous examples showing how to get the package name in code at runtime.
In my case, I need to test the package name at compile time.
Here is my situation: I have two Android projects (the free and the pro) which leverage a library project.
The free version has a "Get the pro version" menu item, which does not exist in the other version.
My menu handling code goes like this:
if ( item.getItemId()==R.id.getProVersion ) {
//...
}
Proguard complains that R.id.getProversion does not exist when building the pro package.
So I need to test which project is being built, to exclude this part of the code from being compiled.
Is there a way to know the package name at compile time ?
Are there alterative solutions to this problem ? Either Android-centered or java-centered solutions are fine.
You can put the menu item in the library project, and then use the runtime package name checks to actually decide whether to display the message or not
You could do that by writing a simple annotation that automatically skips this peace of code. Myabe it's overkill, but it's also a good way to get into preprocessing...
This seems to be a good (KISS) tutorial on the topic:
http://blog.christoffer.me/2011/08/how-to-enforce-static-methods-on-class.html

Categories

Resources