I added a module to my project and marked its source file as a source. It does not show any errors in code by when I compile and run it it can't finds other module's class files
Caused by: java.lang.ClassNotFoundException: com.nabu.bloodworks.models.PlayerPosModel
Problem is it does not add path of .class files to class path. Why this happens? When I google it all I get is "mark src as source folder" and I already did that.
I am trying to use "Bloodworks" module both in my server and client. Server is a simple java server and it works as intended, can see and import bloodworks but client can't see it. Client is a libgdx application and I am trying to run desktop module. As you can see bloodworks/src is marked as blue and I added it to dependincies, am I missing something?
I suppose you should check export (for your module).
Otherwise desktop project won't be able to access that module after building.
Good luck.
I'm sure, it is too late to answer, but I had to follow a different approach for this error to resolve this issue. Simply exporting the jar or library didn't work for me.
I had to create this as global library and add that library to the module, then only the error is resolved. I didn't have to export this.
Related
I creating a program to work with databases and I am getting the following error when compiling in IntelliJ IDEA. Does anyone why this is happening and how I could solve it?
The error that you get occurs not on complilation, but when you try to run your application. It happens because Java was not able to find Table.class file inside db subdirectory of the project output directory (classpath).
It can happen for multiple reasons:
wrong main class selected in the run/debug configuration
Table.java is excluded from compilation (by accident or intentionally because it contained errors and you wanted to skip it while working on other code)
class not compiled because Build step is excluded from from Before launch steps in the Run/Debug configuration
project is misconfigured and there is no Source root defined for the directory containing db subdirectory
Table.java has incorrect package statement or is located/moved to a different package
project path contains a colon : on Mac/Linux or semicolon ; on Windows, it's used to separate the classpath and will render the classpath invalid. See this thread for details. Note that Finder on Mac may display colons in the path as slashes.
the jar may not execute if one of the dependent jars is digitally signed since the new artifact will include the partial signature of the dependency. See this answer for more details.
In project structure make sure you have the right Java version for compile.
there is a known bug that sometimes a Java project created from the Command Line template doesn't work because .idea/modules.xml file references invalid module file named untitled104.iml. Fix the module name manually or create a project from scratch and don't use a template.
on Windows "Beta: Use Unicode UTF-8 for worldwide language support" Region Setting is enabled. See IDEA-247837 for more details and workarounds.
When IntelliJ IDEA is configured to store module dependencies in Eclipse format source root configuration is lost due to a known bug. Configure the module to use IntelliJ IDEA format dependencies as a workaround.
In a properly configured project and with the correct run/debug configuration everything works just fine:
the jar may not execute if one of the dependent jars is digitally signed since the new artifact will include the partial signature of the dependency. See this answer for more details.
I must again emphasis the point CrazyCoder has here.
The (Oracle) JVM used to throw a SecurityException when you tried to run a Jar-File containing broken signatures. This made sense from a "What's wrong"-Point of view.
That is no longer the case. They are indeed throwing ClassNotFoundExceptions now - even if the class is right there in the file (no matter if it is in the default package/toplevel or way down in a nested package structure).
Here's what worked for me:
I deleted .ide folder, .iml file. And all other auto generated files by intelliJ then restarted my ide and I was asked if I want to make my project run with maven that's it.
Obviously I said yes :)
This is a known bug in the IntelliJ idea.
To fix this I just deleted the .iml and the .idea and restart the IDE.
It works for most of the cases
Edit: The files will be in the project directories.
In my case the default console app template works only if the project folder path does not contain underscore (_) in it. Underscore brings the error
Error: Could not find or load main class com.company.Main
Caused by: java.lang.ClassNotFoundException: com.company.Main
IntelliJ IDEA 2021.3.1 (Ultimate Edition)
Build #IU-213.6461.79, built on December 28, 2021
If you've tried everything else that others have suggested (deleting .idea folder, rebuild, etc) there's another place to check, especially if you've built an artifact jar. When you first build an artifact jar, IntelliJ adds a folder: META-INF to src directory. in it is a single file: MANIFEST.MF which has info pointing to the Main-Class for Java to find. If you've refactored your project package, unfortunately IntelliJ does not update this file with the new changes. My MANIFEST.MF has the following correct content:
Manifest-Version: 1.0
Main-Class: org.umoja4life.fatashibackend.MainKt
Where "org.umoja4life.fatashibackend" is the package name, and "MainKt" is IntelliJ's constructed name for a (pseudo) "Main Class" because fun main() has been defined in file "main.kt" in the package directory.
Newbies: btw, This will be confusing for you because there should be no actual "class Main {}" definition despite the error message stating there should be.
Before I discovered this file and after trying everyone else's suggestions, I found it quickest to just have IntelliJ start a project (with correct package name!), initialize it with a trivial main.kt having:
fun main() { println("hello world!") }
run and test that; then, I added back in all my other files, rebuilt, ran, and tested it. Apparently IntelliJ has some secret state information stored somewhere which doesn't get correctly updated if your refactor your package name for an already running project and jar.
I'm new to Java and NetBeans and I'm having a very hard time getting a simple project started.
I'm trying to include .jar files I need to work on a NetBeans plugin. I can successfully add the .jar files to my project using a variety of attempted methods.
I added .jar files by the project properties and added the 'wrapped jar' files to the project
I added the .jar files to the 'Libraries' item in the Projects explorer tree
Both methods appear to work in the IDE. They allow the desired classes to be accessed in the IDE and no syntax or access errors (etc) are detected. However, when I build and run I get ten pages of errors such as NullPointerException and this doozy:
java.lang.ClassNotFoundException: Will not load class org.netbeans.modules.openide.nodes.NodesRegistrationSupport arbitrarily from one of ModuleCL#2afef4c1[org.openide.nodes] and ModuleCL#2debe24[com.myproject.simplelauncherbutton] starting from SystemClassLoader[316 modules]
com.myproject.simplelauncherbutton is my own package. Why would NetBeans even be looking in my package for this class? And even if it is looking there, how can it be finding the class there, to be confused? I just want to make a NetBeans plugin using a .jar file for support. How can I get this working?!
Solved with help from a coworker. The problem was the way in which I was including packages in my project. I was trying to include packages in my project that did not seem to be available. For example, I needed to use org.openide.nodes, so at the top of my class file I wrote:
import org.openide.nodes;
NetBeans would respond saying it couldn't find this package. When I found a wrapped JAR package containing org.openide.nodes and included that in my project, it generated a slew of errors too long to list here.
However, when I add the module by its English name "Nodes API" in the project properties, everything works fine. I wish there were some documentation or instructions I had been able to find to save me hours of stressing about why I couldn't get NetBeans to recognize the various versions of org.openide.* I was trying to use.
I'm working on a GWT project to which I've built a .jar file to handle some processes, it is however reusable in other projects and therefore I want to keep it as a seperate project. But when I want to run the code in GWT (adding the jar to the build-path) I cannot seem to get it right.
I have added, to the root of my external project a "xxx.gwt.xml" file ("xxx" is the name of the file and gwt.xml the extension) and then I've set the source-path (the -tag to "com.xxx" which is the root of all the packages I access in the GWT program. Then I've made it a .jar, added it to the buildpath of the GWT - project and then also added the source-code to the jar, still it finds the "xxx.gwt.xml" file and then it complains about the import of the "com.xxx.yyy.YYY" and that it cannot resolve the type of "YYY".
Also notice that I'm not calling any methods which contains any libs that aren't allowed in GWT and I'm not getting the warning "non-canonical package" which you usually get when GWT doesn't/can't resolve/whatever something is wrong your package in the -tag.
Thanks in advance!
You also have to define a module in your .jar and then inherit it in your external project.
See http://www.vogella.com/articles/GWT/article.html#modules_use
I have seen a similar problem here for example , but i am not trying to acces to Java SE features..
I have a .jar file with the code of a bluetooth functionality.. I try to make a .jar package that works with Blackberry and Windows.. In both cases i use the javax.bluetooth.BluetoothConnectionException class. This class comes in the Blackberry SDK and in the BlueCove package to use Bluetooth in Windows... so the BlueCove package is included in the jar file..
When i try to use the .jar file with the Blackberry, i have the error mentioned in the title: Error!: Duplicate definition for 'javax.bluetooth.BluetoothConnectionException'.. My problem here is that i want to use a feature that comes in the Standard SDK from RIM, but there is another class with the same name and in the same package in the .jar file, and therefore, i get this error... Is there some way to make the BlackBerry application to look for this class in its own SDK instead of the .jar file?
I think that i cannot / should not modify the package of any of the classes. Any ideas here? I would appreciate any.
Thanks
PS: I use the Eclipse plug-in for Blackberrry, in case that is usefull.
I would get the source code of BlueCove project, and open it in a IDE, for example Netbeans, and refactor package names. Change (refactor) package names to avoid name conflict.
After that include refactored BlueCove sources or compiled jar file to your BlackBerry project.
I have added a piece of sharepoint code to the existing java file which was compiling and working fine. The sharepoint code that is written uses some of the external libraries. Now I need to add the external library to the existing project through ANT.
I have done a few modifications in the build.xml file and hence resolved all the compilation errors. However when the code is getting executed, I get an Error message saying "java.lang.NoClassDefFoundError: net/entropysoft/eci/spi/IContentProviderFactory". Please help me resolving this error.
Also please let me know what needs to be added in the build.xml file to resolve the error.
All the jar files is present in the directory "externallibs"
Thanks,
Rajath
You need to have all the jars in the classpath when running the application:
java -cp externallibs/* com.foo.bar.Main
If it's a Java EE web application, the build process should copy all these jars to the WEB-INF/lib folder of the generated web app structure.
java.lang.NoClassDefFoundError: net/entropysoft/eci/spi/IContentProviderFactory does not mean the class net.entropysoft.eci.spi.IContentProviderFactory is not found. It means the class that is used within this class are not found anywhere in the classpath. This error is thrown when the class loader is trying to load the class but it cannot properly initialize the class definition.
To solve this problem, you will need to look at the source code of the class net.entropysoft.eci.spi.IContentProviderFactory, usually at the import section, and determine what is the missing Java class and which library the missing class is in. Once you know you can add that library to your classpath using the answer by JB Nizet. If you run it from IDE, then you will need to add that library to you build.xml.