I'm trying to get the layers of a file geodatabase (.gdb), but I'm having problems with permissions. My Java code is like this:
import org.gdal.gdal.gdal;
public static void main(String[] args) {
gdal.AllRegister();
gdal.Open("C:\\Users\\myUser\\Downloads\\NLD_Multilayer_demo_sample" +
"\\NLD_Multilayer_demo_sample.gdb");
}
When I execute the code, the output is:
ERROR 4: C:\Users\myUser\Downloads\NLD_Multilayer_demo_sample\NLD_Multilayer_demo_sample.gdb: Permission denied
I'm using Maven and the pom.xml has the following dependency:
<dependency>
<groupId>org.gdal</groupId>
<artifactId>gdal</artifactId>
<version>3.6.0</version>
</dependency>
When I go to the terminal and do
$ ogrinfo -al "C:\Users\myUser\Downloads\NLD_Multilayer_demo_sample\NLD_Multilayer_demo_sample.gdb"
I do get the data. So what is wrong with the Java code?
I'm on Windows and I have the following env vars:
GDAL_DATA C:\gdal\bin\gdal-data
PATH C:\gdal\bin
PATH C:\gdal\bin\gdal\apps
PATH C:\gdal\bin\gdal\java
PATH C:\gdal\bin\gdal\plugins
Related
I've been trying to get a hello world project working for a Picocli/GraalVM project. I'm on an M1 Mac running Montery, Java 11, and GraalVM 22.3. I followed he Picocli documentation, but get "unmatched argument" errors when trying to run the native image.
The program works fine by calling:
java -cp "picocli-4.7.0.jar:FocusStackCLI.jar" FSCLI hello
My Java code:
import picocli.CommandLine;
import picocli.CommandLine.Command;
import picocli.CommandLine.Option;
import picocli.CommandLine.Parameters;
#Command(name = "fscli", version = "fscli 1.0", mixinStandardHelpOptions = true)
public class FSCLI implements Runnable{
#Parameters(paramLabel = "directory", description = "Directory containing images to focus stack")
private String directory;
#Override
public void run(){
System.out.println(directory);
}
public static void main(String[] args) {
int exitCode = new CommandLine(new FSCLI()).execute(args);
System.exit(exitCode);
}
}
My pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.example</groupId>
<artifactId>FocusStackCLI</artifactId>
<version>1.0-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<!-- annotationProcessorPaths requires maven-compiler-plugin version 3.5 or higher -->
<version>3.8.1</version>
<configuration>
<annotationProcessorPaths>
<path>
<groupId>info.picocli</groupId>
<artifactId>picocli-codegen</artifactId>
<version>4.7.0</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>info.picocli</groupId>
<artifactId>picocli</artifactId>
<version>4.7.0</version>
</dependency>
</dependencies>
<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>
</project>
Created the native image by calling: Note - It won't let me staticly compile on Mac.
native-image -cp picocli-4.6.3.jar -jar FocusStackCLI.jar
Now when I try to run either of these, with or without arguments,
./FocuStackerCLI hello
./FocuStackerCLI FSCLI hello
I get this error:
Unmatched argument at index 0: 'hello'
Usage: picocli.AutoComplete [-hV] [#<filename>...]
Generates a bash completion script for the specified command class.
[#<filename>...] One or more argument files containing options.
-h, --help Show this help message and exit.
-V, --version Print version information and exit.
Exit Codes:
0 Successful program execution
1 Usage error: user input for the command was incorrect, e.g., the wrong
number of arguments, a bad flag, a bad syntax in a parameter, etc.
2 The specified command script exists (Specify `--force` to overwrite).
3 The specified completion script exists (Specify `--force` to overwrite).
4 An exception occurred while generating the completion script.
System Properties:
Set the following system properties to control the exit code of this program:
* `"picocli.autocomplete.systemExitOnSuccess"`
call `System.exit(0)` when execution completes normally.
* `"picocli.autocomplete.systemExitOnError"`
call `System.exit(ERROR_CODE)` when an error occurs.
If these system properties are not defined or have value "false", this program
completes without terminating the JVM.
Example
-------
java -cp "myapp.jar;picocli-4.6.3.jar" \
picocli.AutoComplete my.pkg.MyClass
Am I not running this right or configuring GraalVM incorrectly?
I suspect you need to make the native image generator know that your FLCL class is the main application class. Without this information the native image generator will search the manifest files in all available jars and find that the picocli.Autocompletion class is a main class in the picocli jar. If your jar doesn’t declare a main class in the manifest file you can specify it on the command line. I forgot what option that was, check the help for the native image generator tool.
I'm trying to understand the inclusion of third party jar files in a java project using only the command line in Windows 10.
Specifically, I try to include the file json-20200518.jar in my "project" so that I can use the java object JSONObject in the project.
My java file:
package com.mypackage.example;
import org.json.JSONObject;
class Example {
public static void main(String[] args) {
// ... program logic
}
}
location of my java file (Examp.java):
./com/mypackage/example
location of jar file:
./jars
using cmd win10 I compile:
javac -cp "C:\Users\pfort\Desktop\java\jars\json-20200518.jar" "C:\Users\pfort\Desktop\java\com\mypackage\example\Examp.java"
compilation is successful.
Run:
java -cp "C:\Users\pfort\Desktop\java\jars\json-20200518.jar" com.mypackage.example.Examp
I get a report:
Error: Could not find or load main class com.mypackage.example.Pokus
Caused by: java.lang.ClassNotFoundException: com.mypackage.example.Pokus
Second attempt:
java -cp "C:\Users\pfort\Desktop\java\jars\json-20200518.jar" "C:\Users\pfort\Desktop\java\com\mypackage\example\Pokus"
But the same error message comes back to me.
Where am I going wrong? Is it the wrong structure? I don't get it, the compilation is successful but the run does not work.
The compiled Examp.class file isn't part of json-20200518.jar, so you'll need to add the directory containing it to the command line. Assuming it's the current directory (.):
java -cp "C:\Users\pfort\Desktop\java\jars\json-20200518.jar;." com.mypackage.example.Examp
I am sure I can load libchilkat.jnilib file. When I change correct path to wrong path , change error can't load library. So I am sure my library load. (I use try and catch and pass correctly.) Upload this library working. After that lines when I want to use this library partials like: CkGlobal glob = new CkGlobal();
I got this error:
java.lang.UnsatisfiedLinkError: nested exception is java.lang.UnsatisfiedLinkError: com.chilkatsoft.chilkatJNI.swig_module_init()V] with root cause com.chilkatsoft.chilkatJNI.swig_module_init()V
I search but nothing found.This error similar like java.lang.UnsatisfiedLinkError: but different because other java.lang.UnsatisfiedLinkError include 'Native code library failed to load.'
I am sure my library load.
If I run my project 'mvn exec:java' working this code. Everything is okey,
but I want to run my code using nohup on GC.
With
import com.chilkatsoft.CkGlobal;
public class Simple {
String PATH_TO_LIB="/full/path/to/lib";
static {
System.load(PATH_TO_LIB + "/libchilkat.so");
}
public static void main(String argv[]) {
CkGlobal glob = new CkGlobal();
}
}
and compilation like this:
> javac -cp ./chilkat.jar Simple.java
> java -cp .:./chilkat.jar Simple
> nohup java -cp .:chilkat.jar Simple
it works as expected. I suggest to take a look at the exact command executed by Maven - by putting -X before your goal.
I am getting an error while writing my simple test program:
package Xbee;
import com.rapplogic.xbee.api.XBee;
import com.rapplogic.xbee.api.XBeeException;
public class XbeeTest {
public static void main(String[] args) {
// TODO Auto-generated method stub
XBee xbee = new XBee();
try {
xbee.open("COM22", 9600);
} catch (XBeeException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
I am getting the following:
java.lang.UnsatisfiedLinkError: no rxtxSerial in java.library.path thrown while loading gnu.io.RXTXCommDriver
Exception in thread "main" java.lang.NoClassDefFoundError: Could not initialize class gnu.io.RXTXVersion
at gnu.io.CommPortIdentifier.<clinit>(CommPortIdentifier.java:123)
at com.rapplogic.xbee.RxTxSerialComm.openSerialPort(RxTxSerialComm.java:71)
at com.rapplogic.xbee.RxTxSerialComm.openSerialPort(RxTxSerialComm.java:61)
at com.rapplogic.xbee.api.XBee.open(XBee.java:140)
at Xbee.XbeeTest.main(XbeeTest.java:14)
The whole problem is that it cannot initialize the class gnu.io.RXTXversion, which is a prt of rtxtcomm.jar, which I have included in my Maven dependency:
<dependency>
<groupId>org.bidib.jbidib.org.qbang.rxtx</groupId>
<artifactId>rxtxcomm</artifactId>
<version>2.2</version>
</dependency>
Any ideas? Thanks.
As I previously mention in comment, you need also native library to make it work. Put it in ${JRE_HOME}/lib/i386
nice article: http://pharos.ece.utexas.edu/wiki/index.php/How_to_Access_Your_Serial_Port_using_Java
and quote from article:
$ wget http://rxtx.qbang.org/pub/rxtx/rxtx-2.1-7-bins-r2.zip
Unzip the rxtx archive and install it. The following commands assume
your JVM is located in /usr/lib/jvm/java-6-openjdk/ and that you are
using a 32-bit x86 computer. You will need to slightly modify these
commands if you have a different JVM or system architecture (i.e.,
64-bit).
$ sudo apt-get install zip
$ unzip rxtx-2.1-7-bins-r2.zip
$ cd rxtx-2.1-7-bins-r2
$ sudo cp RXTXcomm.jar /usr/lib/jvm/java-6-openjdk/jre/lib/ext/
$ sudo cp Linux/i686-unknown-linux-gnu/librxtx* /usr/lib/jvm/java-6-openjdk/jre/lib/i386/
Java Build Path -> Source -> Native library location -> Add your rxtxso and Comm jar file.
Java Build Path -> Add External JAR -> RXTXcomm.jar
Java Build Path -> Order and Export -> Click RXTXcomm.jar
I have create java application using sikuli-script(latest version 1.0.1).
I added the sikuli-script.jar to the Referenced Libraries (I configured using this answer Answer Link)
java code folder structure -->
Java code -->
package com.example.sikuli;
import org.sikuli.script.*;
import java.util.concurrent.TimeUnit;
public class TestSikuli {
public static void main(String[] args) {
Screen s = new Screen();
App app = new App("C:/Program Files/Mozilla Firefox/firefox.exe");//firefox path
try{
app.focus();
TimeUnit.SECONDS.sleep(2);
s.click("imgs/1391152193781.png", 0);//url bar image
s.type(null, "http://www.google.lk", 0);
s.click("imgs/1391152289812.png", 0);//click search image
}
catch(FindFailed e){
e.printStackTrace();
}
}
}
After that i set the the Run Configutrtion such as PATH and SIKULI_HOME
Next I run the code it's working properly.
Then I create .exe using launch4j and according to this site instructions --> How to Create an Executable File from Eclipse
After that i run the .exe file from command prompt then following errors occurred. Please help me.
Error -->
[error] ResourceLoaderBasic: check: libs dir is empty, has wrong content or is outdated
[action] ResourceLoaderBasic: check: Please wait! Trying to extract libs to: C:\Documents and Settings\Dell\SikuliX\libs
[error] ResourceLoaderBasic: loadLib: Fatal Error 109: not found: C:\Documents and Settings\Dell\SikuliX\libs\VisionProxy.dll
[error] Terminating SikuliX after a fatal error(109)! Sorry, but it makes no sense to continue!
If you do not have any idea about the error cause or solution, run againwith a Debug level of 3. You might paste the output to the Q&A board.
--1. when programming in Java using Sikuli, you should always use sikuli-java.jar (sikuli-ide.jar contains much stuff not needed here).
--2. Set a JVM option -Dsikuli.Debug=3 when running the exe to get more details about what's going on. I guess the problem is, that for some reason the export of the native libs does not work in the context of a launch4J exe (I did not test this yet).
--3. always use the latest version (1.1.1 in this case, still nightly but pre-final ;-) http://sikulix.com