Eclipse maven tensorflow project confused about java version

I have java 18 (not 1.8) on windows 10. Trying the example program from the installation guide gets the errors below.

Look like the compiler is confused about the version.

All of the code from the java models has this problem also.

|Method references are allowed only at source level 1.8 or above|Main.java|/1/src/main/java/p|line 14|Java Problem|

|References to interface static methods are allowed only at source level 1.8 or above|Main.java|/1/src/main/java/p|line 15|Java Problem|

|Resource specification not allowed here for source level below 1.7|Main.java|/1/src/main/java/p|line 14|Java Problem|

1 Like

The examples set the source level to 1.8, so I think this is a misconfiguration in your Eclipse project.

1 Like

i tried installing with gradle, but that failed as it did not like the dependency line: implementation ‘org.tensorflow’, name: ‘tensorflow-core-platform’, version: ‘0.3.3’ it complains about the format.

so i am using elipse with maven. i don’t know anythin abot maven. switching to 1.8 helped a lot. but i still get some erroes (please see below).

can i just donwload some jars from somewhere? can they be fished out of maven somehow?

i trtied https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow_jni-cpu-windows-x86_64-2.4.0.zip but it

and followed the instruction here Add .dll to java.library.path in Eclipse/PyDev Jython project - Stack Overflow but the dll only shows up under source and not at all in libraries.

The import org.tensorflow.framework cannot be resolved

i have very poor vision due to some receny eye sugery, so it’s hard to see all of the problems and i may be missing something obvious.

thanks

AdaDelta cannot be resolved to a type

GradientDescent cannot be resolved to a type

Momentum cannot be resolved to a type

Optimizer cannot be resolved to a type

1 Like

For gradle to include the platform dependency you might need to use something like implementation "org.tensorflow:tensorflow-core-platform:0.4.2@pom" as the platform dependency is just a pom file that pulls in other dependencies.

The jars can be downloaded from Maven Central by searching at https://search.maven.org and pulling down the appropriate files (e.g. Central Repository: org/tensorflow/tensorflow-core/0.4.2), but it’s preferable to get Maven or Gradle running properly as it’ll handle the platform specific native dependencies better.

trying the @pom gets a can not import. from command line (please see below(. running in eclipse gets a reallly long stakc trace trhat i can not read.

i will try ti diwbkiad the jars.

thanks

plugins { id ‘java-library’ }
repositories { mavenCentral() }
java {
toolchain {
//languageVersion = JavaLanguageVersion.of(“1.8”)
}
}
dependencies {
testImplementation ‘org.junit.jupiter:junit-jupiter:5.8.1’
api ‘org.apache.commons:commons-math3:3.6.1’
implementation ‘com.google.guava:guava:30.1.1-jre’
implementation “org.tensorflow:tensorflow-core-platform:0.4.2@pom”
}
tasks.named(‘test’) { useJUnitPlatform() }
<-------------> 0% INITIALIZING [57ms]
<-------------> 0% INITIALIZING [356ms]
-------------> 0% CONFIGURING [453ms]

IDLE
<============= 0% CONFIGURING [453ms]
<-------------> 0% EXECUTING [656ms]

<-------------> 0% EXECUTING [656ms]
<-------------> 0% EXECUTING [749ms]
<-------------> 0% EXECUTING [857ms]f :lib:com
<-------------> 0% EXECUTING [857ms]
<-------------> 0% EXECUTING [1s]

<-------------> 0% EXECUTING [1s]

Task :lib:compileJava FAILED
D:\tensorflow\g1\lib\src\main\java\g1\HelloTensorFlow.java:2: error: package org.tensorflow does not exist
import org.tensorflow.*;
^
1 error

FAILURE: Build failed with an exception.

  • What went wrong:
    Execution failed for task ‘:lib:compileJava’.

Compilation failed; see the compiler error output for details.

  • Try:

Run with --stacktrace option to get the stack trace.
Run with --info or --debug option to get more log output.
Run with --scan to get full insights.

BUILD FAILED in 2s
1 actionable task: 1 executed
<-------------> 14% EXECUTING [1s]

You still need to add tensorflow-core-api and tensorflow-framework as dependencies in addition to platform. The platform dependency pulls in the native parts, the other two I mentioned are the Java apis.

found libtensorflow-1.14.0.jar and added it to the went back to the maven project. stil getting the can not import and can not find AdaFrad stuff.

but id did find the jars in m2 (please see below).

i will start a new peoject and stuff the jars into lib and see how far i get.

thanks again for your prompt assistance.

C:\Users\raz.m2\repository\org\bytedeco\javacpp\1.5.6\javacpp-1.5.6.jar
C:\Users\raz.m2\repository\org\bytedeco\javacpp\1.5.6\javacpp-1.5.6-linux-x86_64.jar
C:\Users\raz.m2\repository\org\bytedeco\javacpp\1.5.6\javacpp-1.5.6-macosx-x86_64.jar
C:\Users\raz.m2\repository\org\bytedeco\javacpp\1.5.6\javacpp-1.5.6-windows-x86_64.jar
C:\Users\raz.m2\repository\org\tensorflow\ndarray\0.3.3\ndarray-0.3.3.jar
C:\Users\raz.m2\repository\com\google\protobuf\protobuf-java\3.19.4\protobuf-java-3.19.4.jar
C:\Users\raz.m2\repository\org\tensorflow\tensorflow-core-api\0.4.2\tensorflow-core-api-0.4.2.jar
C:\Users\raz.m2\repository\org\tensorflow\tensorflow-core-api\0.4.2\tensorflow-core-api-0.4.2-linux-x86_64.jar
C:\Users\raz.m2\repository\org\tensorflow\tensorflow-core-api\0.4.2\tensorflow-core-api-0.4.2-macosx-x86_64.jar
C:\Users\raz.m2\repository\org\tensorflow\tensorflow-core-api\0.4.2\tensorflow-core-api-0.4.2-windows-x86_64.jar
C:\Users\raz.m2\repository\org\tensorflow\tensorflow-core-platform\0.4.2\tensorflow-core-platform-0.4.2.jar

libtensorflow-1.14.0.jar

using:

ndarray-0.3.3.jar
ndarray-0.3.3-sources.jar
tensorflow-core-api-0.4.2.jar
tensorflow-core-api-0.4.2-sources.jar
tensorflow-core-api-0.4.2-windows-x86_64.jar
tensorflow-core-platform-0.4.2.jar
tensorflow-core-platform-0.4.2-sources.jar

only 21 errors in new project (6 are duplicates).

where do these guys live?

thanks

Add cannot be resolved to a type
ConcreteFunction cannot be resolved
ConcreteFunction cannot be resolved to a type
Ops cannot be resolved to a type
Placeholder cannot be resolved to a type
Signature cannot be resolved
Signature cannot be resolved to a type
Tensor cannot be resolved to a type
TensorFlow cannot be resolved
The import org.tensorflow.op.core.Placeholder cannot be resolved
The import org.tensorflow.op.math.Add cannot be resolved
The import org.tensorflow.op.Ops cannot be resolved
The import org.tensorflow.types.TInt32 cannot be resolved
The import org.tensorflow cannot be resolved
TInt32 cannot be resolved
TInt32 cannot be resolved to a type
TInt32 cannot be resolved to a type
TInt32 cannot be resolved to a type
TInt32 cannot be resolved to a type
TInt32 cannot be resolved to a type
TInt32 cannot be resolved to a type

Those live in tensorflow-core-api. You should not mix the old libtensorflow v1.x jars with the newer tensorflow-core v0.x jars, that’ll cause weird errors.

TInt32 is indeed in tensorflow-core-api-0.4.2.jar. so i am wondering why eclipse is complaining.

How am i mixing the old lib stuff? is that in the 0.3.3 jars? or is that the TInt32 stuff?

the simple program below fails wiith a no class fould.

thanks

D:\tensorflow\2>java -cp src p.Foo
Exception in thread “main” java.lang.NoClassDefFoundError: org/te
nsorflow/TensorFlow
at p.Foo.main(Foo.java:5)
Caused by: java.lang.ClassNotFoundException: org.tensorflow.Tenso
rFlow
at java.base/jdk.internal.loader.BuiltinClassLoader.loadC
lass(BuiltinClassLoader.java:641)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoa
der.loadClass(ClassLoaders.java:188)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.
java:521)
… 1 more

package p;
import org.tensorflow.TensorFlow;
public class Foo {
    public static void main(String[] args) {
        System.out.println("Hello TensorFlow "+TensorFlow.version());
    }
}

Your previous post mentioned downloading libtensorflow-1.14.0, I was saying that you shouldn’t use that. If you only have tensorflow-core-api 0.4.2, tensorflow-core-platform 0.4.2 and ndarray 0.3.3 you should be ok.

I don’t know why java isn’t loading those jars when executing the single source file, nor why Eclipse is misconfigured.

i am not usingg any dll. i am getting a clean compile with eclipse when using jre 1.8. tring to print the version gets a can not find com.google.protobuf.InvalidProtocolBufferException, while try(ConcreteFunction dbl=ConcreteFunction.create(HelloTensorFlow::dbl); gets a can not find org/bytedeco/javacpp/Pointer.

looks like some kind of class loader problem.

thanks

Those are two dependencies of tensorflow-core-api, you need protobuf-java v3.19.4 and javacpp v1.5.6.

it works! i got: 10 doubled is 20

how did you figure out that i needed those versions? i had those jars in my .m2 repos but i could not find them in the pom.xml sample.

thanks

They are listed as dependencies in tensorflow-core-api’s pom, but the version numbers are given in the parent poms of that project.

i clone the repo again and imported it into eclipse as a maven project. this all works fine.

thanks again for your assistance.