osmdroid-packager Could not find or load main class - java

This is mostly a java question, and likely something I'm overlooking.
I've been trying to use osmdroid-packager (http://code.google.com/p/osmdroid/wiki/HowToUsePackager) to package map tiles for my android app, on Ubuntu Linux. I've been following the instructions on the site above, and have run into some issues.
I have in my current directory, osmdroid-android-3.0.8.jar, osmdroid-packager-3.0.8.jar, and slf4j-android-1.6.1-RCq.jar. I've setting the classpath, and attempting to run using the commands below gives me the error
'Could not find or load main class
org.osmdroid.mtp.OSMMapTilePackager'
I've also tried different variations of setting the classpath (setting classpath, CLASSPATH, to the jars, to the current directory, with -classpath) with the same result. The best I can come up with is that the class is not in the jar.
The commands I tried from the website above were:
set classpath='osmdroid-android-3.0.8.jar;osmdroid-packager-3.0.8.jar;slf4j-android-1.6.1-RC1.jar;sqlitejdbc-v056.jar'
java org.osmdroid.mtp.OSMMapTilePackager -u http://tile.openstreetmap.org/%d/%d/%d.png -t Mapnik -d haarlem.zip -zmax 18 -n 52.4244 -s 52.3388 -e 4.6746 -w 4.594
java -cp . org.osmdroid.mtp.OSMMapTilePackager
also gives the same error.
I haven't downloaded a copy of sqlitejdbc yet, but I'm pretty sure that's not the issue.

Use a 3.0.3 version to osmdroid-packager , osmdroid-packager for example
Use the same versions od libriries to this prompt command
set classpath=osmdroid-android-3.0.3.jar;osmdroid-packager-3.0.3.jar;slf4j-android-1.5.8.jar;sqlitejdbc-v056.jar
java org.andnav2.osm.mtp.OSMMapTilePackager -u http://tile.openstreetmap.org/%d/%d/%d.png -t Mapnik -d haarlem.zip -zmax 18 -n 52.4244 -s 52.3388 -e 4.6746 -w 4.5949

Related

Change the default Java path to other path in FreeBSD

I have script to get the java path from this command: readlink -f $(which java).
But it displays wrong path : /usr/local/bin/javavm
While I need to have this path : /usr/local/openjdk8/bin/java
I tried to give export command: export JAVA_HOME=/usr/local/openjdk8/, but the issue remains same.
I tried this post as well : https://stackoverflow.com/a/39691105/10220825
and this post : https://askubuntu.com/a/554052/905016
I also tried : sudo ln -s /usr/local/bin/javavm /usr/local/openjdk8/bin/java
but it results, ln: /usr/local/openjdk8/bin/java: File exists and issue remain same.
I dont want to hardcode it, neither I want to use other command like which java or echo $JAVA_HOME as the script is getting the expected result in Linux but only problems with FreeBSD machine.
I also dont want to apply any parsing like awk or sed from the output of readlink -f $(which java).
Can someone suggest me how to change the value from readlink -f $(which java).
What you’re seeing is the documented behaviour on FreeBSD.
If you want to select a specific Java version, set the JAVA_VERSION environment variable, e.g.:
JAVA_VERSION=8+ javac MyClass.java
If you want to find out what version is being run, set JAVAVM_DRYRUN=yes:
JAVAVM_DRYRUN=yes java
JAVAVM_DRYRUN=yes JAVA_VERSION=11 java

How to make curl available in Docker image based java:8-jdk-alpine and keep the image clean?

We are having java code that runs curl command to fetch the some result.
We have built a jar file and the jar file executes fine
Now, when we try to dokerize the java program (using jar) and run the application in docker we get this error:
errorjava.io.IOException: Cannot run program "curl": error=2, No such file or directory
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1048)
at com.ps.api.common.CoreAPI_Spec.executeCoreAPI(CoreAPI_Spec.java:295)
at com.ps.api.common.CoreAPI_Spec.getAccessTokens(CoreAPI_Spec.java:319)
Dockerfile used :
FROM ubuntu:16.04
MAINTAINER niro;
# Install prerequisites
RUN apt-get update && apt-get install -y \
curl
FROM java:8-jdk-alpine
# Set the working directory to /app
WORKDIR /Users/******/Desktop/CoreAPI_Jar
# Copy the current directory contents into the container at /app
ADD *******_Automation-0.0.1-SNAPSHOT-jar-with-dependencies.jar ******_Automation-0.0.1-SNAPSHOT-jar-with-dependencies.jar
# Run app.py when the container launches
CMD ["java", "-jar", "******-0.0.1-SNAPSHOT-jar-with-dependencies.jar"]
The Java base image you are using is Alpine Linux one and curl package also needs to be downloaded from there. Here is Dockerfile I have used for Production deployments.
FROM openjdk:8-jre-alpine
RUN apk add --update \
curl \
&& rm -rf /var/cache/apk/*
Update 05/2019
As of Alpine Linux 3.3 there exists a new --no-cache option for apk. It allows users to install packages with an index that is updated and used on-the-fly and not cached locally:
FROM openjdk:8-jre-alpine
RUN apk --no-cache add curl
This avoids the need to use --update and remove /var/cache/apk/* when done installing packages.
Reference -
https://github.com/gliderlabs/docker-alpine/blob/master/docs/usage.md and Thank you #Daniel for the comment.
Your example dockerfile contains multiple FROM statements. This is valid but as the documentation says each FROM clears the state from previous instructions. And so the fresh installed curl is wiped after the second FROM.
Most languages have readily available HTTP clients these days; you should almost never be calling out to curl from a program in a language more sophisticated than a shell script. java.net.URLConnection has been a part of Java since Java 1.0 and (without knowing why you're trying to shell out for this) it's almost definitely the right tool here.
Assuming you control the executeCoreAPI method from your backtrace, you should change it to use the built-in Java HTTP client, and just delete all of the Dockerfile parts that try to install curl.

Permissions error running Java Timezone Updater JAR in Dockerfile

I have a fairly standard Java image with some dependencies added in that I'm writing this Dockerfile on top of. Here's where I'm having a problem in my Dockerfile:
RUN which java
RUN ["/usr/bin/java", "-jar", "tzupdater.jar", "-v", "-l"]
I thought that every Dockerfile command was run as root? But when I try to build from this Dockerfile, I'm running into this permissions issue which also happened in my local environment when I forgot to run this JAR as sudo:
$ docker build -t container-w-tz-update .
Uploading context 1.122 GB
Uploading context
Step 0 : FROM company/java-img-with-dependencies:1.0
---> 0101010101
...
Step 3 : RUN which java
---> Running in 0101010101
/usr/bin/java
---> 0101010101
Step 4 : RUN ["/usr/bin/java", "-jar", "tzupdater.jar", "-v", "-l"]
---> Running in 0101010101
java.vendor: Sun Microsystems Inc.
java.version: 1.6.0_45
tzupdater version 2.1.1-b01
Downloaded file to /tmp/tz.tmp/tzdata.tar.gz
Downloaded file to /tmp/tz.tmp/sha512hash
failed.
Cant rename {0} to {1}.
com.sun.tools.tzupdater.TzRuntimeException: com.sun.tools.tzupdater.TzRuntimeException: Cant rename {0} to {1}.
Caused by: com.sun.tools.tzupdater.TzRuntimeException: Cant rename {0} to {1}.
at com.sun.tools.tzupdater.TimezoneUpdater.update(TimezoneUpdater.java:301)
at com.sun.tools.tzupdater.TimezoneUpdater.run(TimezoneUpdater.java:249)
at com.sun.tools.tzupdater.TimezoneUpdater.main(TimezoneUpdater.java:643)
2017/04/05 22:20:23 The command [/usr/bin/java -jar tzupdater.jar -v -l] returned a non-zero code: 1
I was able to run this utility as sudo on my local with the exact same version of Java with no issues. When I tried to run it locally without sudo, I received the same error. Thoughts?
(This is more like a comment but the message length is beyond the comment limit, so I leave it here as an answer so that other people can maybe give more useful info based on what I've done.)
Seems it's really an unresolved issue, I reproduced your problem by image enoniccloud/java6 running with root user, I also tried docker run -it --privileged ... to run it manually but it does not help. I also tried jdk8 with base image alpine:3.3 but also failed with:
Downloaded file to /tmp/tz.tmp/sha512hash
Renaming /opt/jdk1.8.0_91/jre/lib/tzdb.dat to /opt/jdk1.8.0_91/jre/lib/tzdb.dat.tzdata2016a failed.
Cant rename {0} to {1}.
Validating for : tzdata2017b
Validation complete
JRE updated to version : tzdata2017b
I searched and the only info I found is as follows:
An open issue: https://github.com/docker/hub-feedback/issues/896
Related but not the same: https://forums.docker.com/t/update-docker-container-jre-to-set-timezone-correctly/24426
Before you find the root cause for this issue, I think an alternative way to build your image could be:
Download a JDK tarball for your platform
Untar it, setup JAVA_HOME and PATH, run java -jar tzupdater.jar -v -l on your host
Build your base image based on this updated JDK, ADD to image and setup environment variable like JAVA_HOME and PATH
Hope this could be helpful to you :-)
docker build will complete RUN steps as the last USER set in the Dockerfile.
To reset:
RUN whoami
USER root
RUN ["/usr/bin/java", "-jar", "tzupdater.jar", "-v", "-l"]
USER "whatever whoami reported"
I got a workaround for that. Adding some mv commands (that have no real effect) made it work:
FROM openjdk:7u211-jdk-alpine3.9
ADD tzupdater.jar tzupdater.jar
RUN mv /usr/lib/jvm/java-1.7-openjdk/jre/lib/zi /usr/lib/jvm/java-1.7-openjdk/jre/lib/zi.tzdata2018g && \
mv /usr/lib/jvm/java-1.7-openjdk/jre/lib/zi.tzdata2018g /usr/lib/jvm/java-1.7-openjdk/jre/lib/zi && \
java -jar tzupdater.jar -v -l https://.../tzdata-latest.tar.gz
I have no idea why it works, I got it by trial and error.
Notice the two mv commands do like mv a b && mv b a, so nothing really changes.
The names of the files (dirs, actually) used in the mv are the ones it outputs when it errors (before the workaround), so change it accordingly.

Matlab on Ubuntu stuck at `Picked up JAVA_TOOL_OPTIONS:`

I want to open Matlab without cd /usr/local/MATLAB/R2015b/bin and the sudo ./matlab.
So I sudo gedit ~/.bashrc and write the following commands in the ending:
export MATLAB_ROOT="/usr/local/MATLAB/R2015b/bin"
if [ -d "${MATLAB_ROOT}" ]; then
export PATH="${PATH}:${MATLAB_ROOT}"
fi
After source ~/.bashrc and I use echo $PATH to see that the path of matlab does exist. But when I use matlab to open the it, it will be stuck at Picked up JAVA_TOOL_OPTIONS: whereas cd /usr/local/MATLAB/R2015b/bin and the sudo ./matlab commands work well.
And if I directly use sudo ./matlab, it will show sudo:./matlab: command not found
Other information: which java shows /usr/bin/java
unset JAVA_TOOL_OPTIONS will cause another error.
Oh, I found the problem, I use the command JAVA_TOOL_OPTIONS=/usr/local/MATLAB/R2015b/bin or unset JAVA_TOOL_OPTIONS, and then get the error as follows.
It makes me recall the sudo command, so it might be a problem of permission right. Since I have to open Matlab without leaving that directory, I use ln -s /usr/local/MATLAB/R2015b/bin/matlab /path/to/your/current and then sudo ./matlab. It works.
But how to really solve this problem remains unknown. The other methods I saw like sudo apt-get remove jayatana and sudo rm /usr/share/upstart/sessions/jayatana.conf may cause unpredictable result, so I could not try them.

$ is not recognized as an internal or external command

I am trying to develop my own app using Android Studio and Google Calendar API.
The Google page says this:
In your working directory, run the following commands:
$ gradle init --type basic
$ mkdir -p src/main/java src/main/resources
When I try to put that into the command line, it comes back with:
'$' is not recognized as an internal or external command,
operable program or batch file.
Am I putting this in the wrong place?
I didn't even realize they were assuming that people are using Linux. I have a Windows machine. I have tried all the suggestions and am not getting anywhere so far, so I'm not sure where to go from here.
Not a problem at all! The $ means the following command needs to be run in the terminal (in this case, a Bash terminal). So try opening one on your machine and cd'ing into the project. Then run this:
gradle init --type basic && mkdir -p src/main/java src/main/resources
EDIT: Changed it to make use of the && operator
$ is shorthand in documentation for your command prompt and the lines mean you've got two things to enter at subsequent prompts:
gradle init --type basic and
mkdir -p src/main/java src/main/resources

Categories