Unable to export any of my projects into a .jar file - java

Everytime I try to export any of the projects from my workspace into a Java jar file, I end up with an error:
JAR creation failed. See details for additional information.
Class files on classpath not found or not accessible for: 'Server Manager/src/me/Zahach/ServerManager/main.java'
And this error is repeated for every class in my project.
I tried reinstalling Eclipse, that didn't work.
I then tried to recreate a project and drag and drop my packages into it, that didn't work either.
What is going on?

The error is caused because of a missing .class file(s) for corresponding .java file(s)
In Eclipse
Goto Project->Clean and Rebuild the Project and then try exporting,
If it doesn't work then make sure .class file exists in the bin folder for main.java file in
your case
Another solution is to ensure that the Classpath is Valid

Also make sure that the permissions in your workspace folders are ok. I ran into this problem after updating Eclipse and then downloading some Maven dependencies.
In the end, what fixed it was doing a sudo chmod 777 -R workspace/MyProject

I have faced similar problem while exporting my java files into a compressed jar file, so I checked the Java Build Path of my project and found that the External jars I was referring to from the project are not present in the designated folder locations. Once I have resolved that, I was able to export my java files into a jar.

You may have any java file that is totally empty. You have that file in project with somethingName.java but inside it is nothing. So no bytecode gets generated for it and it throws an error. You can find that file in error details and delete it and try building jar again. It works :) Thumbs up

I had empty Java file classes causing the error.

Related

FileNotFoundException with getResourceAsStream() in JAR file

I don't know what to do anymore. When trying to execute my program from a runnable .jar file, I get a FileNotFoundException when trying to read my .properties file with getResourceAsStream().
I use Maven 3.5.0 and Java 8 Update 144, Eclipse Oxygen.
I also use the maven-assembly-plugin and the assembly descriptor jar-with-dependencies for producing my single .jar file.
The properties file is located in /src/main/resources (in Eclipse) as it is the convention with Maven. It is then - when building the .jar file - automatically put into the root of the .jar file.
Works perfectly when running the program in Eclipse. I just provide the name of the properties file, not other slashes (/) or anything, for the getResourceAsStream() method. I looked into the .jar file and see that the file is located directly in the root of the .jar file.
Why is the .properties file not found? I just don't get it.
Update 2017-10-12
I posted an answer and thought it would work, but it just seemed to work because I changed the version string and appended a "-SNAPSHOT", but since then, my submodule does not get updated.
I understood that I just have to append the literal "-SNAPSHOT" in order for Maven to recompile the current code that I have changed in Eclipse and put it into my .jar file. But it doesn't.
Maven begins to really annoy me. It is supposed to be working like this. What the heck is now wrong?
And by the way, "mvn clean -U package" that is supposed to force an update does not update the snapshot either. I use the maven assembly plugin.
You need to put a slash at the beginning of your path.
this.getResourceAsStream('/myFile.properties')
Found the solution. I didn't use SNAPSHOT builds in Maven. Turns out I need to use a "[version-number]-SNAPSHOT" for the tag so that Maven always uses the current most-up-to-date code for the build.
Now it works. :)
Update 2017-10-12
OK, I think I know what went wrong. I need to run "mvn install" from my parent directory in order to invoke the compilation and installation of submodule A which submodule B is referencing as a dependency. Then I can run "mvn package" on submodule B in order to get the up-to-date code of submodule A built into the single .jar file. :)
Finally ...

Exception: com.mysql.jdbc.Driver | Eclipse isnt exporting jar

again me.
I dont know what the hell isnt working right, but everytime im exporting my Teamspeak Bot wrote in Java, it seems like he dont export the mysql-connector.jar.
Everytime im trying to start my jar, he always tells me that he cant find the MySQL-Driver.
Heres my Code:
As you can see, the jar file is in the buildpath. When i try running it through Eclipse, everything works fine. Only when im exporting he throws me the Exception.
Hope someone of you can help me.
ndslr
The way you're exporting your jar, your library jar isn't automatically added to the output jar. You would have to specify the classpath when you run it:
java -cp "C:\Users\Andy\Desktop\mysql-connector.jar;YourOutputJar.jar" TS3BotMySQL
Instead, you have to add the mysql-connector.jar to your output jar. To do this, instead of going to export > jar, go to export > runnable jar, and then select "Extract required libraries into generated JAR" or "Package required libraries into generated JAR" at the prompt.
See these related questions for more information:
How to create a jar with external libraries included in Eclipse?
Eclipse Java; export jar, include referenced libraries, without fatjar
Generating a Jar in Eclipse including external library
How export Java jar from Eclipse with dependencies on other jars?

Eclipse is showing me the jar, but I'm unable to use the classes in it

I'm building an existing project with Maven in Eclipse and all the dependencies are downloaded. But some of my classes using some classes from a specific jar are not found : the import statement shows an error.
The strange thing is that when I browse the Maven dependencies in Eclipse, I see the jar. I'm also able to unfold the jar, and browse in the packages, and see the classes in it. So as far as I can say, the jar is here in my classpath, available to my project. But somehow, it's not seen by my code. I've tried rebuilding, from Eclipse and from mvn command line, but I still have the same issue.
Any idea where that issue could come from ?
Thanks
One root cause would be that your jar is corrupted. Not corrupted enough to make it unavailable in Eclipse, but corrupted enough to prevent Eclipse from using the classes inside.
To make sure of this :
go to your local Maven repo, where the jar is supposed to be.
try to open the jar with your zip tool (Winzip or equivalent)
if you get an error saying your jar is corrupted, then all you have to do is delete the directory containing the corrupted jar, and build again your project with Maven : jar file would be downloaded again from your remote Maven repository.
If this time you're able to open it, then probably Eclipse will also, and you'll be able to use the classes inside and your problem will be solved.
If you're still unable to open it, check if the jar is not corrupted on central repository itself.
Had you add the jar file to your Build Path, if not, then you can not find the classes in the jar file.
Try to do this:
In Eclipse:
Right click on the jar file --> Build Path --> Add to Build Path.
Then try again if you can find the classes in the jar file or not.

java compilation error in eclipse helios

I have executable jar file which is running perfectly when i am double clicking on it. but when i extracted the source code from jar file using jdk gui and trying to execute it in eclipse helios it is displaying the following errors
The project was not built since its build path is incomplete. Cannot find the class file for ControlPoint. Fix the build path then try building this project
The type ControlPoint cannot be resolved. It is indirectly referenced from required .class files
I tried refreshing the source folder, changing the output folder of eclipse, but nothing worked for me.
Can anyone please help.
I think you need to specify the right JRE in your buildpath. Also, you need to check if all the required libraries are added to the buildpath.
You won't be able to build and run until classpath is fixed. Check whether a library containing ControlPoint class is in class path, if not, then add it there.
You can find the library this way
http://www.findjar.com/index.x;jsessionid=EBF627F4D0BAEC200B8DF6DE50C3C47B?query=ControlPoint
If the ControlPoint class is in the sources that you extracted then make sure that this source folder is in the sources paths, if not add it there in project properties -> java build path -> source

Getting NoClassDefFoundError when using common.lang.StringUtils in android java code?

I am getting this error:-NoClassDefFoundError wherever the code is using StringUtils class or methods .I have correctly added the jar files to the code and is not showing any kind of error in my code(Using Eclipse Indigo).
Is there any kind of point I am missing out. I have used this jar file in other projects but they worked properly.
Please help If any one is getting similar kind of problem?Thanks
Yes, this because of your .jar file didn't import properly. Follow below steps -
Place your .jar file in your project's libs folder .
Import it into your project. And, GoTo project -> properties -> Java build path -> order tab.
Check, whether your .jar file checked and placed in order of 1st. This is the main thing.
Hope these steps helps you. Have a look at below image -
Note that the build classpath is different from the runtime classpath. You must add the required JARs to both.
It's one of the things I don't like in Eclipse...
EDIT: To add JARs to the runtime classpath: in Eclipse, double click the plugin.xml file associated with your project. On the Runtime tab there is a Classpath category. From there, you can add JARs to the runtime classpath.
Here is a screenshot to illustrate this:
Are the jar files in a lib folder or a libs folder?
Newer SDKs require the jar files to be in a libs folder.
I do not know how you execute your code, but it clearly means that the jar is not properly added to your classpath, especially if your code compiles in Eclipse.
Add it to your classpath -or re-check it is well added- when executing and it should work.
Right click on project, Select Build Path -> Configure Build Path and Select Libraries tab. Then with add Jars, add the jar in question.(if you are using eclipse)

Categories