How can I add IntelliJ IDEA project JDK setting to Git? - java

A common pain point with IntelliJ IDEA is correctly configuring the JDK for each project you work on every time you clone the repository or lose the .idea folder.
I want to include the JDK settings in Git to make it easier, especially for new developers, to get up and running. We all agreed to use Coretto 1.8.
First, I added .idea/compiler.xml, which specifies the project language level:
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CompilerConfiguration">
<bytecodeTargetLevel target="1.8" />
</component>
</project>
Next, I added .idea/misc.xml, which specifies the project JDK:
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ExternalStorageConfigurationManager" enabled="true" />
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="corretto-1.8" project-jdk-type="JavaSDK" />
</project>
Then I deleted the ~/.jdks directory, cleaned the project directory with git clean -fdx and reopened the project in IntelliJ. It correctly restored the language level to 1.8 but downloaded Corretto 11 and changed the contents of .idea/misc.xml to:
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ExternalStorageConfigurationManager" enabled="true" />
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" project-jdk-name="corretto-11" project-jdk-type="JavaSDK" />
</project>
Do I need to include some other file or is there some other trick?

Related

Where to put -ds.xml?

I am having trouble adding a datasource to my wildfly server using a -ds.xml file as recommended by the jboss doc. I have a maven project with a persistence.xml:
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0"
xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
<persistence-unit name="primary">
<jta-data-source>java:jboss/datasources/DvdRental4</jta-data-source>
<properties>
<property name="hibernate.hbm2ddl.auto" value="create-drop" />
<property name="hibernate.show_sql" value="true" />
</properties>
</persistence-unit>
</persistence>
and a postgres-ds.xml in the root of the project:
<?xml version="1.0" encoding="UTF-8"?>
<datasources>
<local-tx-datasource>
<jndi-name>DvdRental4</jndi-name>
<connection-url>jdbc:postgresql://localhost:5432/dvdrental4</connection-url>
<driver>postgresql-9.4.1208</driver>
<user-name>postgres</user-name>
<password>1234</password>
<metadata>
<type-mapping>PostgreSQL</type-mapping>
</metadata>
</local-tx-datasource>
</datasources>
When running mvn package and deploying the .war, I get an error that DvdRental4 is missing. So I suppose I need to place the postgres-ds.xml somewhere specific, but where? Or maybe the xml files are wrong? If needed, I can also provide the pom.xml. I already created the database dvdrental4, so this shouldn't be an issue.
I also read somewhere that you have to place the -ds.xml file in the deploy folder, I only have a wildfly/standalone/deployments folder, and putting it in there didn't work.
EDIT:
Wildfly gives the following error:
ERROR [org.jboss.as.controller.management-operation] (DeploymentScanner-threads - 2) WFLYCTL0013: Operation ("full-replace-deployment") failed - address: ([]) - failure description: {
"WFLYCTL0412: Required services that are not installed:" => ["jboss.naming.context.java.jboss.datasources.DvdRental4"],
"WFLYCTL0180: Services with missing/unavailable dependencies" => [
"jboss.persistenceunit.\"dvdrental-gruppe-4.war#primary\".__FIRST_PHASE__ is missing [jboss.naming.context.java.jboss.datasources.DvdRental4]",
"jboss.persistenceunit.\"dvdrental-gruppe-4.war#primary\" is missing [jboss.naming.context.java.jboss.datasources.DvdRental4]"
]
}
I think I solved it by just putting the *-ds.xml file in the project/src/main/webapp/WEB-INF of my maven project, at least there is no error saying the datasource couldn't be found. I also changed the postgres-ds.xml a bit:
<?xml version="1.0" encoding="UTF-8"?>
<datasources>
<datasource jndi-name="java:jboss/datasources/DvdRental4" pool-name="DvdRental4"
enabled="true" use-java-context="true">
<connection-url>jdbc:postgresql://localhost:5432/dvdrental4</connection-url>
<driver>postgresql-9.4.1208.jar</driver>
<security>
<user-name>postgres</user-name>
<password>1234</password>
</security>
</datasource>
</datasources>
Note: I deployed the driver as a .jar, so that is why I can specify the driver directly as a .jar, I think.
The JNDI name you specified for your datasource is "DvdRental4". But the persistence context specifies "java:jboss/datasources/DvdRental4". I am not sure whether that is correct. Either try "java:jboss/datasources/DvdRental4" in both places or (even better) use the Boss JNDI view to see where the datasource is actually deployed.
The ability to deploy datasources was not a feature that made it between JBoss 5 and the AS7 rewrite, only the deployable jms destinations. You will need to configure the server to define the datasource, before you deploy your application

Java application is packaged but can not run it

I am trying to use Jarbundler to package my Java application to be used on Mac.
As the application is a maven based application I used mvn ant:ant command to convert it to ant; However, when I run it returns an error as following:
Error: Could not find or load main class com.myproject.swing.Main
build.xml
<?xml version="1.0" encoding="UTF-8"?>
<project name="MyApp" default="package" basedir=".">
<import file="maven-build.xml"/>
<taskdef name="bundleapp"
classname="com.oracle.appbundler.AppBundlerTask"
classpath="lib/appbundler-1.0.jar" />
<target name="MyApp">
<bundleapp outputdirectory="dist"
name="MyApp"
displayname="MyApp"
identifier="com.myproject.swing.Main"
mainclassname="com.myproject.swing.Main">
<classpath file="dist/MyApp.jar" />
</bundleapp>
</target>
<!-- ====================================================================== -->
<!-- Help target -->
<!-- ====================================================================== -->
<!-- <target name="help">
<echo message="Please run: $ant -projecthelp"/>
</target> -->
</project>
*The main class is located in following address
src > main > java > com > myproject > swing > Main
Compiler compliance level is 1.8

Publishing a jar file that already exists

I have some problems understanding how the publication works. I have to publish a jar file to my web repository, but I have found some probably maybe by the fact that I missing something about the artifact and the publication.
These are my three files for the publication:
Build.xml
<project xmlns:ivy="antlib:org.apache.ivy.ant" name="pubblication"
default="pubblication" basedir=".">
<echo>inizio</echo>
<target name="pubblication" description="--> pubblicare un artifact">
<ivy:settings file="archivaIvySetting.xml" />
<ivy:publish resolver="publish-artifact" conf="publicConf" organisation="bbi"
module="resutil" revision="1.0">
<artifacts pattern="./[artifact]-[revision].[type]"/>
</ivy:publish>
</target>
</project>
Ivy.xml
<ivy-module version="2.0">
<info organisation="org.apache" module="central"/>
<configurations>
<conf name="publicConf" visibility="public" />
</configurations>
<publications>
<artifact name="[organisation]-resutil" ext="jar" conf="publicConf"/>
</publications>
</ivy-module>
archivaIvySetting.xml
<?xml version="1.0" encoding="UTF-8"?>
<ivysettings>
<property name="archiva-internal" value="http://host.com:8080/repository
/internal/"/>
<settings defaultResolver="central">
<credentials host="host.com" realm="Repository Archiva Managed internal
Repository" username="username" passwd="passwd" />
</settings>
<resolvers >
<ibiblio name="central" m2compatible="true" usepoms="true" root="${archiva-
internal}" />
</resolvers>
</ivysettings>
My problem is that when I do the build that ant says there is no module with that name in the cache. Now the question:
1) In the pattern do I set the jar that I want to publish?
2) If not how do I must to do practically that: take the jar give it the info params and publish it in the repo?
I repeat the file already exist, and this is a test file.
The pattern in the publish task should match a that is created locally in your build. Additionally the publish section of the ivy file must match the files your attempting to upload.
Hopefully some examples will help:
good ivy tutorial for local repository?
Issues using ivy:publish task
Convert ivy.xml to pom.xml
how to publish 3rdparty artifacts with ivy and nexus

Ivy conflict resolution: two libs need another lib in different version

I'm using json-schema-validator and guava in the same project. When I try to update either one I get a conflict for findbugs, so one lib is left out.
The working versions are:
json-schema-validator 2.0.0
guava 13.0.1
Both rely on findbugs 1.3.9
The version I'd like to use:
json-schema-validator 2.2.1
guava 16.0.1
Here json-schema-validator needs findbugs (jsr305) 2.0.1 and guava needs findbugs 1.3.9. Is there any way around this problem? With that I mean that I can use json-schema-validator version 2.2.1 and guava 16.0.1 in my project.
Sample files:
build.xml
<project name="example" default="download"
xmlns:ivy="antlib:org.apache.ivy.ant">
<target name="download" description="resolve dependencies with ivy">
<ivy:resolve />
<ivy:retrieve sync="true" type="jar"/>
</target>
</project>
ivy.xml, working
<?xml version="1.0" encoding="ISO-8859-1"?>
<ivy-module version="2.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://ant.apache.org/ivy/schemas/ivy.xsd">
<info organisation="example" module="example" status="integration">
</info>
<dependencies>
<dependency org="com.github.fge" name="json-schema-validator" rev="2.0.0" />
<dependency org="com.google.guava" name="guava" rev="13.0.1" />
</dependencies>
</ivy-module>
ivy.xml, not working
<?xml version="1.0" encoding="ISO-8859-1"?>
<ivy-module version="2.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://ant.apache.org/ivy/schemas/ivy.xsd">
<info organisation="example" module="example" status="integration">
</info>
<dependencies>
<dependency org="com.github.fge" name="json-schema-validator" rev="2.2.1" />
<dependency org="com.google.guava" name="guava" rev="16.0.1" />
</dependencies>
</ivy-module>
eviction notice:
[ivy:resolve] :: evicted modules:
[ivy:resolve] com.google.code.findbugs#jsr305;1.3.9 by [com.google.code.findbugs#jsr305;2.0.1] in [default]
#Julien thanks for the hint, according to the example there I changed the retrieve line to
<ivy:retrieve pattern="lib/[artifact]-[revision].[ext]" sync="true"/>
and it works now.

How to use Ivy to get artifacts other than JARs?

There is a Java library I want to use as part of my build, but it contains an external resources/ directory that has to be visible to the runtime classpath in order to work. I'd like to be able to store it as an artifact inside my Ivy repository, but not sure if Ivy can handle this, and if so, how to rig-up the ivy.xml, ivy-settings.xml files, as well as the repo itself.
My repo is actually an Artifactory server and I store artifacts and their ivy files right next to each other:
http://myrepo.com:8080/artifactory/simple/myrepo/
google/
guice/
3.0/
guice-3.0.jar
ivy.xml
Etc. I guess I'm looking for a similar setup here:
http://myrepo.com:8080/artifactory/simple/myrepo/
fizz/
buzz/
1.7/
buzz-1.7.jar
resources/
ivy.xml
...and somehow pull down both the jar and its resources/ directory as part of the Ivy resolve/retrieve pattern, and then place resources/ where I need it to be from there.
Is this possible? Any ideas? Thanks in advance!
Edit - If the fact that resources/ is a directory causes a problem, I don't mind zipping it up as resources.zip, and then resolving/retrieving it into my project at buildtime, and then unzipping it. That's just more work to do, if Ivy can't handle directory-artifacts out of the box.
You should zip/tar the directory and create the following setup:
http://myrepo.com:8080/artifactory/simple/myrepo/
fizz/
buzz/
1.7/
buzz-1.7.jar
resources-1.7.zip
ivy-1.7.xml
In your ivy.xml you would then declare each file as a publication of this module like this:
<?xml version="1.0" encoding="UTF-8"?>
<ivy-module version="2.0">
<info organisation="fizz"
module="buzz"
revision="1.7"
status="release"
publication="20110531150115"
default="true"
/>
<configurations>
<conf name="default" visibility="public"/>
</configurations>
<publications>
<artifact name="buzz" type="jar" />
<artifact name="resources" type="zip" />
</publications>
</ivy-module>
And if needed you could define separate configurations like:
<configurations>
<conf name="default" extends="jar, resources" visibility="public"/>
<conf name="jar" visibility="public"/>
<conf name="resources" visibility="public"/>
</configurations>
<publications>
<artifact name="buzz" type="jar" conf="jar"/>
<artifact name="resources" type="zip" conf="resources"/>
</publications>

Categories

Resources