I am using intellij community version . I am creating a jar file via build artifact but I am getting file size 67357KB . Which is very big .How to create proper jar file .
Thanks in advance
A "proper" JAR file can be very big. So you are probably creating it the right way.
So what you really need to do is to examine the JAR file to see what the build has put into it. If there is stuff in the JAR that shouldn't be there, you then need to look at what your Maven POM file, Gradle file, or whatever to figure out why the build puts the unwanted stuff in there.
If you are not using Maven, Gradle or some other build system, check the artifact configuration that you have created to specify what goes in the JAR, and what is in the directories you have told it to include.
Related
I am working with Scala in Intellij-Idea, and have run into a problem. I have included the Java tag in case someone with Java experience can also answer my question.
In my .ivy2/cache folder for a certain dependency I am working with, there are two jar files. One contains .class files and one contains .scala source files. I want to be able to modify one of the jars, drop it in my lib folder, then run my program with the jar that includes my changes.
I have an issue though. I can modify the file in the source folder with jar uvf, but when I drop it in lib, and run it, the changes don't show up. I have tried commenting out the dependency in my build.sbt file, but it appears to still be using my old dependency even after I run sbt update.
My question can be divided into several parts:
1) Can I just drop a jar file containing only .scala files in the lib folder and expect it to run?
2) To remove the dependency, is commenting out the line in my build.sbt file and then running sbt update enough?
3) Let us say that the only way to run the jar file as a dependency is to use a jar file containing .class files. How do I rebuild the jar with .class files using the .scala files if I don't have any of the other project files, like the build.sbt file? I have the source files, but I am not sure how to use it to recreate the jar without all the other information that usually comes packaged in a Scala project.
I use Intellij only to edit my files, and use sbt to run the code.
1) Can I just drop a jar file containing only .scala files in the lib folder and expect it to run?
That's not possible because the jar file is expected to contain class files, scala files will be handled as resources instead of source files.
2) To remove the dependency, is commenting out the line in my build.sbt file and then running sbt update enough?
I would run sbt clean instead, I haven't tried but sbt "show unmanagedBase" is supposed to list you the library if it was actually picked.
3) Let us say that the only way to run the jar file as a dependency is to use a jar file containing .class files. How do I rebuild the jar with .class files using the .scala files if I don't have any of the other project files, like the build.sbt file? I have the source files, but I am not sure how to use it to recreate the jar without all the other information that usually comes packaged in a Scala project.
The ideal way would be to find the complete repository for that source, update the source and run sbt publishLocal, if that's not possible, another way would be to reconstruct the build.sbt and keep adding libraries until the library compiles properly, hopefully, it will have no dependencies, or a few only.
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 ...
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.
I am building an IntelliJ idea plugin. I have a component TemplateComponent.java which extends the ApplicationComponent. Here is the link to the code.
I want to read some template files in the TemplateLoader. All the files are placed under root_of_project/templates. When I build the jar and install it in my IDE, I am not able to get access to the files because the plugin is packed as a jar file. However, things work as intended when I am debugging the plugin from within the IDE. Can anyone help me?
Please see com.intellij.util.PathUtil#getJarPathForClass and its usages in IDEA codebase. Unfortunately you might have to add a check if it's a directory (debug) or a jar (production), like in com.intellij.compiler.server.BuildManager#getJpsPluginSystemClassesPath
I made a simple standard-lone java Application using Spring,Apache Camel,Activemq for processing messages.
Note: My Application don't have any GUI.
My project structure is in the following way.
SACLib folder have nearly 70 external jars(all Spring,Camel and Activemq corresponding jars).
It's working fine in Eclipse. SO Now We want to deploy into Jar file.I tried in Eclipse,But I didn't seen Rod1,Rod2,Copy1 and SACLib folders in my Jarfile.
after Deploying Jar, If I run FirstConsumer.java it runs Rod1-->ThMapInfratab1-2.exe file. For this I mention Real paths of .exe file.
How can I make Jar file with including all my folders.
Thanks
Well, this is a kind of work that is typically done with build automation tools like Apache Ant, Maven or Gradle, so you can investigate there if you want to make this happen automatically next time.
But, if you want to do it manually...
First, you project needs a META-INF folder where you will place a file called a MANIFEST.
That manifest contains a Main-Class entry pointing to you main class. You can read about this in the Java Tutorial: Setting Application's Entry Point.
But it can also contain a Class-Path entry, pointing to all other jars required by your application and that should be loaded by the executable jar.
You can read about it the Java Tutorial: Adding Classes to your Jar Class Path.
If you are building your executable jar with Eclipse, it will let you choose the MANIFEST file that you want to use during the creation process.
Now, if you want to use build automation tools, there are other answers here that explain how to do it:
Creating a bundle jar with ant
How to create executable jar with dependencies with Maven
How to export an executable jar in Gradle
simply using ant download it , and then make a build.xml file and put it
Here's an simple example of an ant target that will create a jar (named test.jar) that includes all jar files under the lib directory. Maybe this will solve your problem?
for using apache ant, see this
http://ant.apache.org/manual/using.html