I created an example microprofile app. And the readme says i can start it with java -jar myjar.jar
But when I try it i get an error that no manifest.mf exists.
I really don't have one in my example generated project. But when I extract the jar, there is one generated, but without a main class.
How is a Microprofile app even supposed to run? I know there is a class extending Application. But how should I handle this manifest file?
Ok sorry just realized IntelliJ placed the projet into another folder. So now I have two folders. And handled the wrong project.
Related
Uploaded a jar file from my computer to a server and tried to run it. When I run it I get java.lang.NoClassDefFoundError and it seems to be related to the twitter4j jar that my main method depends on.
However, I have this jar file in my libraries so shouldn't this be included when I build my code in to a jar? Here's a pic in case it helps.
is the error that I'm getting. (can't upload a pic just yet.
Not sure what this has to do with twitter, but anyway, the issue is that you do not have the correct class files. In other words, when you are running your fat JAR in the command prompt, you do not have any libraries exported with it (Or if you do, you don't have that specific one).
Sometimes such an error can be because there is an incorrect version of java, however that is not the case here since java has got no "twitter" packages or classes in it.
Using something like JarSplice would fix this.
Assuming you did not package the twitter4j classes inside your application jar, you need to tell Java where it can look for classes that are not inside your application jar. You typically use the classpath flag for that. In your case, it should look something like
java -cp /tmp/twitter4j.jar -jar /tmp/myapp.jar
An alternative would be to package all twitter4j's classes inside your application jar. This is called a 'fat' jar. How to make one depends on how you build your application jar.
The JAR file that you are trying to use needs to be in the classpath. This can be done by using the -cp attribute from the command line. However, when using java -jar, you cannot use the -cp attribute.
To get around this, you can do the following:
java -cp /tmp/myapp.jar;\path\to\external.jar com.example.package.MyClass
where MyClass has the main() method defined.
Alternately, you can specify jar files on the classpath using the manifest.mf file. See http://docs.oracle.com/javase/tutorial/deployment/jar/manifestindex.html for details.
I'm coding a little servlet using weblogic.wsee.jaxrpc.ServiceImpl. My IDE(JDeveloper) doesn't say something wrong. But after launching app, I'm catching java.lang.ClassNotFoundException:weblogic.wsee.jaxrpc.ServiceImpl. Should I add new jar files to lib directory? This is what lib contains:
If you use weblogic 12.x then the jar that contains weblogic.wsee.jaxrpc.ServiceImpl is located in
{WL_INSTALL_FOLDER}/wlserver/modules/clients/com.oracle.webservices.wls.jaxws-wlswss-client.jar
or
wls.jaxrpc-client
depending on which one you use.
If you add that to your lib, it should work.
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.
I've got a project in which I'm using Java+Scala+Slick2D.
The project itself runs well when launched from within eclipse. But when I try to make a jar file, it just refuses to work. Here's the error I keep getting when trying to export it as a Runnable jar:
And if I try to export into just a Jar file, it's unable to find the Main Class:
There is, of course, a main class in game.TicTacGame. But it refuses to acknowledge it. I tried creating an executable with a simple Hello World project and it worked fine. It even detects the main class. Why is Eclipse not detecting the main class in this case?
PS: I've also tried extracting the .jar file created, editing the manifest.mf file to add the Main-Class: game.TicTacGame, enter two new lines and recreate the jar. Then it gives me a corrupted jar file error.
I'm at my wits end and would appreciate any help in this regard. I'm using Windows 7 x64 with Eclipse Juno, Java 1.7 and Scala 2.10
Edit: The Main class is in Java
Okay, I got it to work. Apparently, all I needed to do was restart eclipse. And then magically, it started detecting the Main class:
But the jar started giving me noClassDefFound errors for the Slick2d, LWJGL and other libraries. That's where JarSplice came to my rescue. I exported the project as before, with all the libraries and resources.
Then, I fired up JarSplice and added everything as follows:
Go to "Add Jars" and add the project.jar just created through eclipse, add lwjgl.jar, slick.jar and scala-library.jar. lwjgl and slick should be in your project lib folder where you would have imported them. scala-library should be available wherever it says it is. Make sure you add that as well
Next, when I tried to "Add Natives" it kept giving me "Duplicate library" error. So I removed them all and kept it empty.
Next in "Main Class", I entered the path to the main class i.e. game.TicTacGame
Finally, "Create Fat Jar". And it works perfectly :)
I just encountered the same problem, and here is how I solved it:
Open "Run As" --> "Run Configuration" on the project you want to export
Click "Search" for Eclipse to refresh the list of main class
Then export Runnable JAR file again, and everything goes smoothly.
The most easiest method is run the java file once and automatically the file appears in the list.Even i was facing the error but it was solved by using this simple method.
I recently figured a better way to do this using 'Runnable jar export' which might help you. In order for your main method to be listed in that list, you need to add the main method to the Run Configuration list.
This way it's simpler to create a runnable jar especially if you want to do it repeatedly.
Well, got the same Problem and solved it by selecting my GUI to export and not the whole Project.
I had this problem with Eclipse version 2019-03 (4.11.0) and compiler JaveSE-11. Choosing the right launch configuration and exporting runnable jar failed over and over again with an error
Could not find main method from given launch configuration
I've tried to restart Eclipse and do a clean build, but it didn't help.
In the end, I found a workaround to go into the generated jar file (I've used 7zip) and change META-INF/MANIFEST.MF file. The file should have something like this inside:
Manifest-Version: 1.0
Class-Path: .
Main-Class: <package name>.<class name>
Hope it helps someone.
I faced the same issue and in my case I found that "launch configuration" was incorrect in Runnable Jar file specification dialog. Somehow, eclipse was automatically taking it. The "Launch configuration" should be java file which has main method. Basically, it is filename-package.
The moment I changed my "launch configuration", I was able to create Jar file without any error.
I had the same issue. To overcome this issue, you need to close all opened files and open a single java class file that has the main() method. Then export it from eclipse and works fine.
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.