Fun Stuff > CLIKC
A programming thread!
ankhtahr:
Yeah, this is great already. I'm working on the first exercise sheet of SWT. They've got relatively detailed instructions (which are specific to Eclipse…), but I'm stuck at one point. This subtask is:
--- Quote ---Make sure that calling "mvn package" puts the correct main class in the resulting Java manifest. Also set the two settings of the maven-jar-plugin "addDefaultImplementationEntries" and "addDefaultSpecificationEntries" to "true". (This causes the jar which is produced by maven to be executable)
--- End quote ---
I think I've got the first part covered (even though it was never explained what a manifest is…), but I can't manage to do the second. I'm trying to do it using Eclipse, but can't figure out how. The provided pom.xml doesn't contain anything about maven-jar-plugin, and I don't know how to change the default settings (there is an entry in the tab "effective POM" for this plugin).
snalin:
First of all, the manifest is a setting for the maven packaging plugin, if you hadn't googl'd your way to that yet. So in the POM, there should be something like this:
--- Code: --- <plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.1</version>
...
<configuration>
<archive>
<manifest>
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
<addDefaultSpecificationEntries>true</addDefaultSpecificationEntries>
<addClasspath>true</addClasspath>
<mainClass>mainPackage.MainClass</mainClass>
</manifest>
</archive>
</configuration>
...
</plugin>
--- End code ---
If you don't have that, you can just cut and paste it in your POM, under the <plugins></plugins> section. If that's not there, just add it wherever under the top level (<project>). As I might have mentioned earlier, you'll want to right-click the POM and select "open with -> text editor", because the eclipse pom editor is confusing.
I'll admit that my knowledge of maven is based on trial and error in addition to some copy-pasting and intuition. But, I got it working, using the above settings, where mainclass points to the fully qualified path to your main class. Try it - cd to the root of your directory, and run mvn package. If you get "build successfull" after it's downloaded everything, go to the newly made target folder, and try to execute the jar in there.
The idea with the plugins is that they each follow their own xml schema for what keywords and stuff they use - I think. The quote you have from the subtask is full of bullshit, by the way - addDefaultImplementationEntries and addDefaultSpecificationEntries does NOT make the jar executable. What they do is that they add a bunch of extra information to the MANIFEST.MF file inside the jar, this link explains it. All you need to do to make the thing executable is to add a main class. If you haven't already, I recommend that you go dig around in the jar files maven generates, and look at all of the files in there.
If you can't get it to work, send me a PM and I can mail you an example project with a simple hello world.
ankhtahr:
okay, so now I've been screaming at my notebook for half an hour. Fucking Eclipse.
Running mvn package on the console works great. Running it from Eclipse, with the .launch file we're supposed to use (I have no idea what they do, or what they are for) fails, with this error. This launch file (which seems to be the only way I can somehow launch mvn package) only runs with the embedded maven, and I can't seem to convince it to run with the external maven.
I already remember, why I can't stand Eclipse. It's a complete mess. The user interface is extremely far from consistent.
snalin:
Why are you running it from within Eclipse? Is that a requirement?
When I right click the POM and go "run as -> maven build" and select "package" as my goal, I get the same error as you (probably a m2e problem), but the jar packs just fine (BUILD SUCCESS, as maven puts it). I'm using the 1.4.1.something version of m2e, which is the standard you pick up from their install site, so if you just installed it, you should have the same thing.
Btw, the .launch file is apparently a launch configuration that's been packaged to a file. So it basically does the right click, run as, whatever for you. Why your uni thinks it's a good idea to give that to you instead of just having you package the thing on your own is beyond me. The problem seems to be more that your uni is trying to hold your hand and just help you do stuff, and in the process makes a huge mess of everything. "You need to deploy your project with maven" would have been a good way to give the assignment.
It's also really silly that running maven goals is done from right clicking the pom instead of say right clicking the project and selecting something from the "maven" menu.
Masterpiece:
I'm teaching myself Haskell.
I could be better.
Navigation
[0] Message Index
[#] Next page
[*] Previous page
Go to full version