I am having an issue setting up the module.info file for my java desktop app, I am using object box desktop as a database, so I am stuck at this error, I am using maven.
java: the unnamed module reads package io.objectbox.converter from both objectbox.java and objectbox.java.api
at times after edits I get a similar error
java: the com.app module reads package io.objectbox.converter from both objectbox.java and objectbox.java.api
so I an stuck in what may seems to be a loop .
Related
I have a simple Java project using the non-modularized dependency "io.prometheus:simpleclient_hotspot:0.16.0". It has been working fine until, for other reasons, I wanted to use the Java module system and add a module-info.java to my project. Once I do that, I start getting the compilation error:
error: package io.prometheus.client is not visible import io.prometheus.client.CollectorRegistry;
^ (package io.prometheus.client is declared in the unnamed module, but module simpleserver does not read it)
The prometheus client library isn't modularized, so it is called an "unnamed module". How do I get access to the packages of such a library? I assume I add a dependency in my module-info.java?
This seems like a basic, common JPMS newbie issue, but after doing lots of searches I can't find the solution to this issue.
I'm a teacher with a lot of simple .java files to grade. The students have not and will not be using packages as this is a rather simple class.
Having one .java file runs fine. When a second one or more are added, VSCode compiles all the files in the folder. Needless to say, some student files may contain syntax errors. So I can't run or debug the one student file I'm grading.
Is there a workaround for this situation? It seems to be an option under Java specification.
7.4.2. Unnamed Packages states:
An implementation of the Java SE Platform must support at least one unnamed package. An implementation may support more than one unnamed package, but is not required to do so. Which ordinary compilation units are in each unnamed package is determined by the host system.
You can have a try on Code Runner. Then you can right-click and select Run Code or click the Run Code button on the top-right.
Update:
In fact, you can ignore the Build failed prompt and click Proceed to continue the Run Java or Debug Java actions.
I am running a webapp using a connection to MongoDB where products reviews are stored. The current version of the webapp works correctly. (i.e. it writes and stores new reviews in the MongoDB collection).
Nonetheless, when I make changes and try to compile a new version of the MongoDB Utilities class I keep getting:
error package com.mongodb.XXX does not exist
import com.mongodb.BasicDBObject;
^
I do have the following .jar files in the \lib directory:
mongodb-driver-3.6.3
mongodb-driver-core-3.6.3
mongodb-java-driver-3.6.3
bson-3.6.3
and I mentioned them in the CLASSPATH variable:
set CLASSPATH=.;C:\apache-tomcat-7.0.34\lib\servlet-api.jar;C:\apache-tomcat-7.0.34\lib\jsp-api.jar;C:\apache-tomcat-7.0.34\lib\el-api.jar;C:\apache-tomcat-7.0.34\lib\commons-beanutils-1.8.3.jar; C:\apache-tomcat-7.0.34\lib\mongo-java-driver-3.6.3.jar; C:\apache-tomcat-7.0.34\lib\bson-3.6.3;C:\apache-tomcat-7.0.34\lib\mongodb-driver-3.6.3; C:\apache-tomcat-7.0.34\lib\mongodb-driver-core-3.6.3; C:\apache-tomcat-7.0.34\lib\mysql-connector-java-5.1.38-bin.jar;
What am I doing wrong? How can I get java to compile my new MongoDB Utilities class?
I couldn't reproduce the same behaviour, but I only reference mongodb-java-driver-3.6.3 in my build scripts.
Since the mongodb-java-driver is an uber JAR that contains mongodb-driver, mongodb-driver-core, and bson, you could try removing these latter three from your classpath and build scripts and see if that resolves the issue.
I was able to solve my issue so I post this answer in case someone is stuck in the same problem.
Thanks to what user "nos" posts in the answer to this question I used the -verbose option when compiling e.g.:
javac -verbose className.java
In the errors log I noticed that the Java compiler was searching for the MongoDB classes in a different \lib folder than the one I used in my CLASSPATH definition. So I added a copy of the mongodb-java-driver there and the compilation worked.
As craigcaulfield correctly mentions above there is no need to add the other drivers ( mongodb-driver, mongodb-driver-core, and bson).
I am currently writing a game engine in Java using the LibGDX framework. For several months now, I have successfully used LuaJ 3.0 with my engine. I have had no problems getting scripts to run on Android (tested on two devices) or Desktop (in and out of Eclipse).
However, when I tried to deploy to Android today, I got the following error:
org.luaj.vm2.LuaError: script:2 vm error: java.lang.ClassNotFoundException: com.javamon.console.ScriptPlayerCreate
The line of the script causing this error is:
Result = luajava.bindClass("com.javamon.console.ScriptPlayerCreate")
This is typographically identical to the class supposedly "not found" on Android.
If I try to bind a regular java class, such as java.lang.ClassNotFoundException, I don't get any error. However, this error does not occur on the Desktop version, whether run from within Eclipse or via a runnable *.jar.
Here is the stack trace, retrieved from LogCat:
org.luaj.vm2.LuaError: script:2 vm error: java.lang.ClassNotFoundException: com.javamon.console.ScriptPlayerCreate
at org.luaj.vm2.lib.jse.LuajavaLib.invoke(Unknown Source)
at org.luaj.vm2.lib.VarArgFunction.call(Unknown Source)
at org.luaj.vm2.LuaClosure.execute(Unknown Source)
at org.luaj.vm2.LuaClosure.call(Unknown Source)
at com.javamon.console.Script.runFunction(Script.java:91)
at com.javamon.console.Script.runFunction(Script.java:96)
at com.javamon.console.ScriptPlayerCreate.run(ScriptPlayerCreate.java:39)
What bothers me is the very last line. ScriptPlayerCreate certainly exists -- it's running the very script that produces the error!
Things I have tried:
Trying different versions of LuaJ
Binding a different class within the com.javamon package (same problem)
Updating my ADT/SDK plugins
Cleaning/rebuilding the project within Eclipse
"Starting Over" (creating a new LibGDX project using the GUI tool, and manually importing my source files)
Checking classes.dex -- ScriptPlayerCreate is certainly there
Testing on separate Android devices (Moto X and Incredible 2)
I would like to reiterate that I have successfully used LuaJ with Android for several months without incident. Additionally, I have not changed my scripting engine since my last (successful) Android deployment.
UPDATE
After trying to revert to backup versions of my app and Eclipse, the problem persists -- even on another computer. I am beginning to suspect that luajava.bindClass() does not know how to interpret the contents of classes.dex, and is instead searching for actual class files.
When I attempted to recompile some backup versions, I noticed that the recompiled version almost always has a smaller classes.dex file than the backup. Perhaps something is wrong or has changed with Eclipse's/Android's compiler?
I tried manually inserting class files into the com/javamon/console/ folder within the APK, but of course that messes up the file integrity, and even after re-signing the app will not load. Any ideas?
I got a similar problem,and I'd fix it
LuaJavaLib.java:202
original
return Class.forName(name, true, ClassLoader.getSystemClassLoader());
change to
return Class.forName(name, true, Thread.currentThread().getContextClassLoader());
Reverting to LuaJ 2.0.1 solved the issue.
It appears that all versions of LuaJ above 2.0.1 have a different implementation of LuajavaLib.class. In the new implementation, only Java system libraries can be accessed through luajava.bindClass(), whereas in the older versions, bindClass() permits access to local application classes as well. All other script functions behave normally; only luajava.bindClass() is affected.
In the newer versions, if a class is not found in the Java system libraries, LuaJ apparently checks the local application directory. Because the Desktop project is a runnable *.jar and contains actual class files, the Desktop version of the game would have worked properly in any version of LuaJ. Contrastingly, Android bundles everything in a classes.dex file, which is not "searchable" in the file-path sense. Hence the ClassNotFoundException.
Lastly: I have been using LuaJ successfully for months, so what changed? Apparently, when I upgraded to 3.0 several months ago, Eclipse never actually recognized the file change. It was only when I refreshed and cleaned the project that Eclipse realized a new version of LuaJ was present. Because the main project in LibGDX is source-files only (assets are in -android), you almost never click "refresh". Thus, the LuaJ problem has been a time-bomb of sorts.
I plan on submitting a support ticket to the author so he can address this issue. Until he does, I advise Android developers to stay with LuaJ 2.0.1!
Also you can fix it with your class Helper.
Create package: org.luaj.vm2.lib.jse
In this package create following class:
package org.luaj.vm2.lib.jse;
public class Helper {
public static JavaClass forClass(Class c) {
return JavaClass.forClass(c);
}
public Class<JavaClass> huskClass() {
return JavaClass.class;
}
}
Then create something like bridge class:
public class LuaBridge {
public Varargs getClass(String clazzName) {
try {
Class clazz = Class.forName(clazzName);
return Helper.forClass(clazz);
} catch (Exception e) {
e.printStackTrace();
Crashlytics.logException(e);
}
return null;
}
}
And now when you run your script you can pass instance to your lua script:
_globals = JsePlatform.standardGlobals();
_bridge = new LuaBridge();
//...
_globals.loadfile(scriptName)
.call(CoerceJavaToLua.coerce(_bridge));
Inside your LUA script:
First line:
local luaBridge = ...
-- some code here...
UserManager = luaBridge:getClass("com.dexode.cree.ScriptPlayerCreate")
-- used like luajava.bindClass("com.dexode.cree.ScriptPlayerCreate")
I have been working on an inherited code base that is a Java web app and just today it stopped compiling. I am getting errors that it can't find some classes that are declared in the code.
My code base is set up like this: I've got the main package and then, for some reason, both inside it and at the same level of it, I've got a .jar that holds a supplemental package, com.oreilly.servlet to be exact. I have some files in my main code base that import com.oreilly.servlet.MultipartRequest and utill today they had no problem finding them.
I have since wiped my local version and checked out the last revision which I know compiled last timed I made any changes to the java files, leading me to believe my issue is jdeveloper.
The errors I am getting are that package com.oreilly.servlet doesn't exist and subsequently that it cannot find class MultipartRequest.
I have also broken out the jar file (which by the way is included int he Libraries and Classpath section of jdev) into a package structure to no avail.
Any help would be much appreciated.
Sounds like an opportunity to update and refactor to me. I stumbled across the com.oreilly package years ago, haven't seen it since. I say remove it from the code and upgrade to the more standard javax.servlet classes (usually found in a servlet-api.jar or something similarly named bundled with your web app server).