I'm working on a kotlin project that I want to execute as a jar. This is all done in IntelliJ Idea and I went about making the jar using the artifacts.
The process I followed was (as illustrated by an Idea guide):
Add artifact (as jar) from project structure
Build jar
Run jar
After this, I get a
'no main manifest attribute, in ____.jar'
What I have tried after reading several stack overflow questions:
Checking that the manifest file is in the correct folder and has the correct path in the artifact
Adding code to the build.gradle file for the jar->manifest portion
Trying the method of moving the manifest stuff into a resources folder
Checking that the jar exists
Moving the manifest stuff into a different folder (java,kotlin,out folders)
Making sure that the manifest file is in the correct format
All of the above has not worked.
Something that is confusing to me is that, even when I alter the manifest file to be in "incorrect" format, it still gives the same error. The path stated in the artifact's details is correct yet there is no difference even when I purposely input incorrect items in the manifest file. Not sure if that is the"real" problem but I'm also not sure how to fix that as well
None of the solutions worked for me.
I solved it in this way:
When setting up the artifact, change:
Meta-inf: (...)\src\main\ (you must remove "java")
Also, there was a problem with resources, solved this way:
When setting up the artifact:
Output Layout > Add copy of > Directory content > resources.
That's all!
For anyone that may have encountered this problem in intellij and did not find a solution in any other posts, what helped me was
Navigating to Project Structure
Going to the Artifacts tab
Explicitly adding a new META-INF/ directory in my jar
Adding the created MANIFEST.MF file to the META-INF/ in the jar FROM THE ARTIFACTS TAB
Rearranging the order for the META-INF/ to be at the top
Building and running
The end result looked like this
while creating the exeutable jar file explicitly create a mainfest.txt file
that should be in order of the directory structure and mainfest.txt file should contain only one line (Main-Class:name of the class containg main method)then run the jar tool
Related
I'm putting a custom plist file (GoogleService-Info.plist) into my Resources directory, but it isn't getting copied into my built project. I can go into XCode and manually add it through "Copy Bundle Resources", but I need to get this running without manual steps.
I can't just use <resource-file src="src/GoogleService-Info.plist" /> in my plugin.xml because I'm building for a couple different widgetIds - I have 2 versions of this file that I switch out, depending on my widgetId. I have the copying and renaming automated with a hook to get the right file into Resources/GoogleService-Info.plist.
How can I get the file I put into Resources included?
The cordova-ios project has code to get the resource files included in the XCode project files, and you could replicate that, but I ended up with a workaround:
Copied my file to a consistent name in a before_prepare hook
Used a resource-file tag for the new name in my plugin.xml
I have a resource abc/xyz.json under src/test/resources. I'm using IntelliJ IDE.
While running a Test for my project, I get the following exception.
Exception
com.google.common.io.Resources.getResource("abc/xyz.json")
fails with java.lang.IllegalArgumentException: resource abc/xyz.json not found.
The Test runs fine with gradle clean build and eclipse
Try marking your src/test/resources folder as Test Resource Root. Attach is the image on how to do it.
Let me know if you need any other information.
Make your resource folder a Test Resource folder, if this does not fix the issue then, close your project, delete target folder and open the project. Hope this helps.
Had the same issue not that long ago, since Intellij outputs the class files into out/production/{project_name}, that path will not start in the src directory but will start in the out/production/{project_name} directory.
It will however see files that are in the project root directory, I'd recommend moving your resource directory into the main project directory then accessing the file with "resources\${FILE_NAME}".
Sometimes I have the same problem, though the folder is marked as resource root. So what I do: I just Unmark it and then mark it as resource root again. Sometimes I need to do it several times and it works. But anyway I think it is Intellij IDEA bug.
So, something has started to act weird in my intelliJ project. I even tried removing the iml and .idea data, to no avail.
I go to Project Structure. There, I have a content root. Withing, I have three folders - one for my jar (and jni lib), one for Samples and one for Tools (just tools written to use the jar). The jar, Samples and Tools are marked blue (sources).
In the jar folder, I have my source tree (com\company\projectname\XXX), a lib folder, a folder for my JNI lib and a folder I created call 'junit', which is the focus of this question. It is marked in Project Structure in green (Tests).
Within, I have a folder structure eerily similar to my code: com\company\projectname\junit.
When I open a file in junit\com\company\xxx\junit, I have a big red underline under my package com.company.xxx.junit; line which tells me: "Package name 'com.company.xxx.junit' does not correspond to the file path 'junit.com.company.xxx.junit'.
I was under the impression that marking a folder as 'Tests' would instruct the IDE to use that as a "parent" folder, if you will, eliminating the need to prepend another folder name.
How can I separate the code from unit tests and in fact, create two junit test suites (one is for internal use, the other is a 'skeleton' for distribution), park them under one "umbrella" folder and NOT have to prepend the package names with that folder name?
Update: Project structure:
Based on your screen shot, the issue is that the junit directory is a subdirectory of another source directory, namely MyProvider. A source directory (whether a "production" source or a unit test source directory) cannot be a subdirectory of another source directory.
You need to either:
move the junit directory out of MyProvider so it is a sibling directory, or
unmark MyProvider as a source directory, create a main (or some such directory) in MyProvider, mark it as a source directory, and then move the com directory/package into main.
Option 2 would be the preferred way to deal with this as it follows a very common directory structure standard.
UPDATE (Following comment from OP)
Here's a couple of screenshot showing the configuration you desire:
I removed the .IdeaIC15 folder and started over. Working for now. Something must have gotten confused in the config, either as part of the update, or in the course of operation. I have taken a backup copy as it is now, so if this happens again, I will have something to check.
I have been trying everything to make IntelliJ allow the use of Struts2 taglib. However it keeps on complaining about <%# taglib prefix="s" uri="/struts-tags"%>. The error it shows in the IDE is:
Cannot resolve the uri /struts-tags
I have set up a new project from scratch and included the struts2 facet (which added the struts.xml file to src/META-INF and the struts2-core jar to myApp/lib).
Is there anything wrong with my project setup ?
Any help is appreciated as I have been stuck with this for a day now!
Environment: IntelliJ IDEA 12.1.6
The issue seemed to be due to IntelliJ caching and the problem is gone after invalidating cache and restart.
Re-indexing the project did the trick.
File > Invalidate Cache
Seems you are not configured a project feature Struts2 properly. You should add File Sets. Right click on the module in the project structure, use Module Config (F4), use Facets, use Struts2 Facet, use File Sets. Press + button to add configuration files. Make sure struts.xml and struts-default.xml, and struts-plugin.xml are added. The struts.xml should not be in src/META-INF but in src like shown in your picture. But struts2-core-x.x.x.x.jar should be on build path. Make sure you have properly configured a project build path, and it should be a valid file containing TLD files inside the jar in the META-INF folder.
I have a problem using Intellij Idea.
I am absolutely unable to load text file as InputStream - it doesnt matter where do I put the file (main/java, main/resources...) it just can't find the file - in Eclipse everything works just fine.
I tried setings->compiler->resource patterns and added ?*.txt but that doesn't seem to work either.
Any help is appreciated.
If you load it as a File, make sure that Working Directory is properly set in IDEA Run/Debug Configuration, since it's the default directory where Java will look for a file when you try to access it like new File("file.txt"). Working directory should be set to the directory of your project containing .txt files.
If you load files as a classpath resource, then they should reside somewhere under Source root and will be copied to the classpath according to Settings | Compiler | Resource Patterns.
If you can't get it working, upload your project somewhere including IDEA project files so that we can point to your mistake.
Look at the image, notice that the txt files are in the project root, and not the source folders (in blue).
If you open the Project Structure dialog, and click on Modules and select your module - are the correct folders marked as Source Folders on the sources tab?
Link for how to get to Project Structure dialog
Also, if you print out the absolute path of that file you are trying to read, is that anywhere near where you expect it to be?
An easy way to figure out the same would be to try creating a file in the same fashion and see where it gets created in your project. You can put your input file at the same location and it should work just fine (if it doesn't, you should check your resource pattern which might be causing the file to be not copied over in the build output).
This method actually gives you the working directory of your intellij settings which is pointed out in the accepted answer. Just sharing as I had similar trouble and I figured out this way. :)